Pregunta

Bob Powell el LockBits , puse el siguiente código en C # 2010 de Visual Studio Express :

System.Drawing.Imaging.BitmapData bmp = 
    BitmapImage
        .LockBits(new Rectangle(0, 0, 800, 600),
                  System.Drawing.Imaging.ImageLockMode.ReadWrite, 
                  MainGrid.PixelFormat)

        unsafe
        {
            for (int y = 0; y < bmp.Height; y++)
            {
                byte* row = (byte*)bmp.Scan0 + (y * bmp.Stride);
                for (int x = 0; x < bmp.Width; x++)
                {
                    row[x * 4] = 255;
                }
            }
        }

Después de empujar los datos de mapa de bits en un cuadro de imagen (picturebox.Image = BitmapImage;) todo lo que sale es una X roja sobre un fondo blanco, con un borde rojo. ¿Qué estoy haciendo mal?

¿Fue útil?

Solución

Ha olvidado llamar UnlockBits al final como se sugiere al final del enlace http: // www. bobpowell.net/lockingbits.htm

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top