all groups > dotnet drawing api > october 2006 >
You're in the

dotnet drawing api

group:

Lockbits question


Lockbits question keperry
10/26/2006 2:43:25 PM
dotnet drawing api:
Ok..so I was trying to follow the example on Bob's site:
(http://www.bobpowell.net/lockingbits.htm)

BitmapData bmd=bm.LockBits(new Rectangle(0, 0, 10, 10),
System.Drawing.Imaging.ImageLockMode.ReadOnly, bm.PixelFormat);

int PixelSize=4;

for(int y=0; y<bmd.Height; y++)

{

byte* row=(byte *)bmd.Scan0+(y*bmd.Stride);

for(int x=0; x<bmd.Width; x++)

{

row[x*PixelSize]=255;

}

}

Supposedly, the "row[x*PixelSize] = 255" can be used to access the blue
byte. Can someone give an example of how I can access the red, green,
and alpha bytes? Assuming its a Format32BppArgb?
Re: Lockbits question keperry
10/26/2006 6:12:43 PM

Dang...that's what I thought. I keep getting an error towards the end
saying that I tried to write or read protected memory. So I thought
maybe I was going out of bounds or something.
Re: Lockbits question keperry
10/26/2006 7:05:20 PM

Thanks for the reply btw!

When I setup my bitmap, I was setting the format to 32bit, but when I
specified my BitmapData I set it up as a 24 bit. That's why I was
running out of memory.
Re: Lockbits question keperry
10/26/2006 7:09:53 PM
Thanks for the reply! I like your way, too.



[quoted text, click to view]
Re: Lockbits question Joergen Bech <jbech<NOSPAM> NO[at]SPAM
10/27/2006 12:37:40 AM

Little-Endian order?

index + 0 = blue
index + 1 = green
index + 2 = red
index + 3 = alpha

e.g. row(x*PixelSize + 2)=<red value>

/JB

On 26 Oct 2006 14:43:25 -0700, "keperry" <keith.b.perry@gmail.com>
[quoted text, click to view]
Re: Lockbits question Michael C
10/27/2006 12:00:10 PM
[quoted text, click to view]

I usually do this slightly differently

BitmapData bmd=bm.LockBits(new Rectangle(0, 0, 10, 10),
System.Drawing.Imaging.ImageLockMode.ReadOnly, bm.PixelFormat);

int PixelSize=4;
byte* ptr = (byte*)bmd.Scan0;
int offset = bmd.stride - PixelSize * bmd.Width;

for(int y=0; y<bmd.Height; y++, ptr += offset)

{

for(int x=0; x<bmd.Width; x++, ptr += PixelSize)

{

ptr[RGB.A] = whatever;
ptr[RGB.R] = whatever;
ptr[RGB.G] = whatever;
ptr[RGB.B] = whatever;

}

}

where RGB.A, R, G and B are constants in a class called RGB.
public const int A = 3;

public const int R = 2;

public const int G = 1;

public const int B = 0;



[quoted text, click to view]

AddThis Social Bookmark Button