Re: [Eqalign-devel] =?iso-8859-1?q?Me_est=E1_dando_guerra_la_QHY?=
Brought to you by:
antoniofga,
isoplut
From: Antonio F. <ant...@ya...> - 2007-10-05 10:31:14
|
Bitmap bp = new Bitmap(width, height, PixelFormat.Format8bppIndexed); Graphics g = Graphics.FromImage(bp); g.DrawImage(bmp, new Point(0, 0)); g.Dispose(); bmp.Dispose(); no funciona: "A Graphics object cannot be created from an image that has an indexed pixel format." De todas maneras este formato nos va a dar problemas en las funciones de astrometría y cálculso de centroides. Antonio Fraga <ant...@ya...> escribió: Si vas a tener razón. De todas formas, si son 2 bytes por pixel y un sólo canal de color: IntPtr hBitmap = Marshal.AllocHGlobal(16 * width * height); GETBUFFER(hBitmap, width * height); ¿no tendría que ser?: IntPtr hBitmap = Marshal.AllocHGlobal(2 * width * height); GETBUFFER(hBitmap, 2 * width * height); De cualquier manera, ¿funciona o no funciona pasarla el puntero de la imagen bloqueada?: Bitmap bmp = new System.Drawing.Bitmap(width, height, PixelFormat.Format16bppGrayScale); BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, bmp.PixelFormat); GETBUFFER(bmpData.Scan0, 2 * width * height); bmp.UnlockBits(bmpData); Si eso funciona, y el bmp queda ya creado, no veo por qué deba fallar pasar a cualquier otro formato con Graphics.DrawImage: Bitmap bp = new Bitmap(width, height, PixelFormat.Format24bppRgb); Graphics g = Graphics.FromImage(bp); g.DrawImage(bmp, new Point(0, 0)); g.Dispose(); bmp.Dispose(); o Bitmap bp = new Bitmap(width, height, PixelFormat.Format8bppIndexed); Graphics g = Graphics.FromImage(bp); g.DrawImage(bmp, new Point(0, 0)); g.Dispose(); bmp.Dispose(); , habría que probarlo. Saludos Andres del Pozo Prieto <and...@gm...> escribió: Con la solución que has puesto le va a dar un error de memoria. Si crea un bitmap de 8bpp, solo reserva memoria para 1 byte por pixel. Sin embargo la función GETBUFFER intenta escribir 2bytes por pixel. Personalmente creo que la mejor solución que tiene Francisco es hacer lo siguiente: * Crear un buffer de 16bpp para almacenar la memoria original tal como hacía al principio * Crear un Bitmap de 8bpp y obtener su BitmapData * Volcar a mano los datos de la imagen sobre el bitmap de 8bpp utilizando un trozo de código unsafe. La ventaja de este mecanismo es que en la traducción de 16bpp a 8bpp se puede aplicar cualquier fórmula de escalado para cambiar brillo, contraste o utilizar una curva de luminosidad no lineal: IntPtr hBitmap = Marshal.AllocHGlobal(16 * width * height); GETBUFFER(hBitmap, width* height); PixelFormat format = PixelFormat.Format8bppGrayScale; System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(width, height, format); System.Drawing.Imaging.BitmapData bmpData = bmp.LockBits(new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, format); unsafe { for (int y = 0; y < bmpData.Height; ++y) { short* buff_in = (short*)hBitmap + bmpData.Width * y; byte* buff_out = (byte*)bmpData.Scan0 + y * bmpData.Stride; for(int x=0; x<bmpData.Width; x++) { buff_out[x]=Transform(buff_in[x]); } } } El problema es que esto es relativamente lento. Si la DLL en C++ está hecha por Francisco se podría implementar un GETBUFFER16 y un GETBUFFER8 que devuelvan los datos en el formato que se necesita. Saludos, Andrés. Antonio Fraga wrote: Prueba esto a ver si es más lento: .... PixelFormat format = PixelFormat.Format8bppIndexed; System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(1280, 1024, format); System.Drawing.Imaging.BitmapData bmpData = bmp.LockBits(new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, format); GETBUFFER(bmpData.Scan0, 1310720); bmp.UnlockBits(bmpData); Bitmap bp = new Bitmap(bmp.Width, bmp.Height, PixelFormat.Format24bppRgb); Graphics g = Graphics.FromImage(bp); g.DrawImage(bmp, new Point(0, 0)); g.Dispose(); bmp.Dispose(); ..... Francisco José <is...@ya...> escribió: Parece ser que el formato de 16 bits en escala de grises está roto en el GDI+, cojonudo. La buena noticia es que a 8 bits indexados parece que el tema funciona... pero a color!! siendo la cámara monocromo, en fin, he realizado una burda transformación con la paleta de colores, ya que las funciones setpixel/getpixel no se llevan bien con los 8 bits indexados; a más bits, realmente sólo leía una parte del buffer... muy raro; os paso el extracto del código que funciona, mañana lo intento subir al SVN y mejorar: Inicialización: // Buffer de 8bits RAW SETBUFFERMODE(1); Función de captura: void CapturarClick(object sender, EventArgs e) { ThreadedExposure((uint)int.Parse(tExposicion.Text), null); while(isExposing()!=0) { this.mensaje.Text = "Exponiendo..."; Console.Write("Exponiendo\n"); } // Ahora leemos los datos del buffer this.mensaje.Text = "Leyendo datos..."; // El buffer será de 2621440 bytes (16 bits por pixel, // la cámara tiene 1310720 pixels) PixelFormat format = PixelFormat.Format8bppIndexed; System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(1280, 1024, format); System.Drawing.Imaging.BitmapData bmpData = bmp.LockBits(new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, format); GETBUFFER(bmpData.Scan0,1310720); bmp.UnlockBits(bmpData); // Obtención del bitmap Bitmap bp = Bitmap8FromUnmanagedArray1(bmpData.Scan0,1280,1024); // Transformación a escala de grises. ColorPalette greyPal = bp.Palette; for(int i = 0;i<256;i++) { greyPal.Entries[i] = Color.FromArgb(255,i,i,i); } bp.Palette = greyPal; imagenFrame.Image = bp; bp.Save(@"c:\test.jpg", ImageFormat.Jpeg); } Creación del bitmap: private Bitmap Bitmap8FromUnmanagedArray1(IntPtr image, int width, int height) { Bitmap bmp = new Bitmap(width, height, PixelFormat.Format8bppIndexed); BitmapData bmData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed); IntPtr dest = bmData.Scan0; IntPtr source = image; int len = width; if ( bmData.Stride == len ) { CopyMemory(dest, source, width*height); } else { for( int y = 0; y < bmp.Height; y++ ) { CopyMemory(dest, source, len); source = new IntPtr(source.ToInt32() + len); dest = new IntPtr(dest.ToInt32() + bmData.Stride); } } bmp.UnlockBits(bmData); return bmp; } --------------------------------- Sé un Mejor Amante del Cine ¿Quieres saber cómo? ¡Deja que otras personas te ayuden! . ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/_______________________________________________ Eqalign-devel mailing list Eqa...@li... https://lists.sourceforge.net/lists/listinfo/eqalign-devel --------------------------------- LLama Gratis a cualquier PC del Mundo. Llamadas a fijos y móviles desde 1 céntimo por minuto. http://es.voice.yahoo.com --------------------------------- ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ --------------------------------- _______________________________________________ Eqalign-devel mailing list Eqa...@li... https://lists.sourceforge.net/lists/listinfo/eqalign-devel ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/_______________________________________________ Eqalign-devel mailing list Eqa...@li... https://lists.sourceforge.net/lists/listinfo/eqalign-devel --------------------------------- LLama Gratis a cualquier PC del Mundo. Llamadas a fijos y móviles desde 1 céntimo por minuto. http://es.voice.yahoo.com------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/_______________________________________________ Eqalign-devel mailing list Eqa...@li... https://lists.sourceforge.net/lists/listinfo/eqalign-devel --------------------------------- Sé un Mejor Amante del Cine ¿Quieres saber cómo? ¡Deja que otras personas te ayuden!. |