Problem with setting 32ARGB values

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.
 
J

Jon Skeet [C# MVP]

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.)
 
B

Bob Powell [MVP]

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
 
J

James Dean

Bob,
Thats very helpful....i must reference that more often...thank you very
much.
 
J

James Dean

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....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top