Click here to Skip to main content
15,878,316 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
how i can converts image stream to int[] argb ?
and what the differents between argb and bgr ?
Posted
Comments
BillWoodruff 24-Sep-12 8:12am    
Please tag your question: WinForms, WPF, ASP.NET, C#, etc. Why do you want an array of Ints from an image stream ? What is it you are trying to do ?
Sergey Alexandrovich Kryukov 24-Sep-12 13:10pm    
That's right. However, I tried to answer in general, which should be enough, because OP can always read the help on particular article.
Please see my solution.
--SA

This is a bad idea to represent ARGB as int[]. The color components are represented by 8 or 16-bit values, depending on "pixel format" you can read from the bitmap file or define for a new bitmap, but int is a 32-bit signed value. You should better use an array of structures.

BGR is (most probably; you did not provide all the details in the question, please see below) it the same as (Red-Green-Blue, RGB), but in different order of components used for some pixel formats.
ARGB is the same as RGB, but with additional component called "alpha", which represent "transparency" of a pixel. The number of bits per component depends on pixel format.

That's all, considering the level of detail of the original question, but that should be enough for you. You did not explain us what imagine library do you use. It could be System.Drawing, WPF or something else. Anyway, if you understand the basic ideas, you can easily find further detail in the library documentation provided by MSDN help.

Good luck,
—SA
 
Share this answer
 
Comments
pasztorpisti 24-Sep-12 22:15pm    
+5, Good advices especially the one with the array of structures instead of int[]. The integer width used for each component might matter in case of an image processing algorithm where accuracy is important especially if you chain some algorithms and one gets the result of another accumulating inaccuracies.
I've also added my own minimalistic answer guessing the needs of the OP, please see.
Sergey Alexandrovich Kryukov 24-Sep-12 23:44pm    
Thank you.
And yes, your answer is useful, even of OP uses different library because the basic ideas are still similar.
--SA
This is a good example on how to lock and read/write the bits of a bitmap in C#: Work with bitmaps faster in C#[^]. Note that 24/32 bit bitmaps contain the pixel data in BGR format. I would questions the "faster" part of the title of the article depending on your goals. This can come handy for example if you are implementing some image processing algorithms.

Differences between BGR and ARGB:
The old winapi and GDI stuff stores dibsection data in BGR format in memory, this is basically the same as the format used in bitmap files. palettized (8 or less bit) bmp files have a palette consisting of an array of RGBQUAD[^] structures and the pixels are just 1, 4, or 8 bit indices to this array. When you have a 32 bit bitmap then you don't have a palette but every pixel has the same format as the RGBQUAD structure. The difference between BGRA and ARGB is that they store the red, green, blue and alpha components in different bitranges of the integer.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 24-Sep-12 23:43pm    
Sure, a 5. The only problem that we cannot be certain about the library OP uses, but this is basically OP's fault.
--SA
pasztorpisti 24-Sep-12 23:45pm    
Thank you!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900