Problem with setting 32ARGB values

  • Thread starter Thread starter James Dean
  • Start date Start date
J

James Dean

I am trying to directly set the pixels in a 32ARGB image but for some
reason i am not setting them correctly. I have a struct 4 bytes in
size...
public struct PixelData
{
public byte Blue;
public byte Green;
public byte Red;
public byte transparent;
}
I set the data to the correct size....the transparent byte is at the end
which i thought was correct but i cannot display it correctly. I can
display a 24RGB bitmap correctly using the 3 byte structure...what could
be the problem?.I make the bitmap a 32ARGB bitmap at the start also.
 
James Dean said:
I am trying to directly set the pixels in a 32ARGB image but for some
reason i am not setting them correctly. I have a struct 4 bytes in
size...
public struct PixelData
{
public byte Blue;
public byte Green;
public byte Red;
public byte transparent;
}
I set the data to the correct size....the transparent byte is at the end
which i thought was correct but i cannot display it correctly. I can
display a 24RGB bitmap correctly using the 3 byte structure...what could
be the problem?.I make the bitmap a 32ARGB bitmap at the start also.

I'd expect the transparency to be the first byte of the structure, as
the "A" of ARGB stands for "Alpha". (I'd expect it to be RGBA if the
transparency is at the end.)
 
The LockBits example in the GDI+ FAQ illustrates the structure of the data
and the pixel element order.

--
Bob Powell [MVP]
Visual C#, System.Drawing

The Image Transition Library wraps up and LED style instrumentation is
available in the June of Well Formed for C# or VB programmers
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml
 
Well actually i did not fix the problem but i used 32rgb which leaves
one byte blank and with this i can set the transparency so its the same
result. Actually its not sttructured like ARGB. The correct RGB
structure is blue first then green then red last, so its read
backwards....
 
Back
Top