[Eqalign-devel] =?iso-8859-1?q?Me_est=E1_dando_guerra_la_QHY?=
Brought to you by:
antoniofga,
isoplut
From: <is...@ya...> - 2007-10-04 17:07:31
|
Pues eso, hartito me tiene... os planteo otra duda, a ver, tengo este código: // El buffer será de 2621440 bytes (16 bits por pixel, // la cámara tiene 1310720 pixels) PixelFormat format = PixelFormat.Format16bppGrayScale; 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.ReadWrite, format); GETBUFFER(bmpData.Scan0,1310720); bmp.UnlockBits(bmpData); Entiendo que en bmpData.Scan0 tengo el comienzo de la imagen RAW ¿y ahora qué he de realizar para obtener la imagen? Si intento guardar o fijarla a un control PictureBox me dice que el argumento es inválido en una excepción en tiempo de ejecución, por ejemplo: bmp.Save(@"c:\test.bmp", ImageFormat.Bmp); Ya mareado, y siendo honesto, he localizado en una web este código, pero genera imágenes de 32bits RGB, logro guardar la imagen pero claro, la cámara es monocromo y a 16: [DllImport("kernel32.dll")] private static extern uint CopyMemory (IntPtr dest, IntPtr Source, int Length); private Bitmap Bitmap32FromUnmanagedArray1(IntPtr image, int width, int height) { Bitmap bmp = new Bitmap(width, height, PixelFormat.Format32bppRgb); BitmapData bmData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); IntPtr dest = bmData.Scan0; IntPtr source = image; int len = width*4; if ( bmData.Stride == len ) { CopyMemory(dest, source, width*height*4); } 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; } Cambiando Format32bppArgb por Format16bppGrayScale me da error de acceso a memoria, soy torpe, ¿qué hago mal? Un saludo! --------------------------------- Sé un Mejor Amante del Cine ¿Quieres saber cómo? ¡Deja que otras personas te ayuden!. |