Click here to Skip to main content
15,887,477 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I'm having 4 values of 16bit each: red, green, blue and alpha respectively. I'm trying to use these values in Color.FromArgb method to create a new color. But I'm getting an exception as Red value should be between 0 to 255. but i need to create a bitmap image with 16bit value for each of red, green, blue and alpha colors.. please help me as soon as possible
Posted

1 solution

The actual information per bit depends on the PixelFormat: http://msdn.microsoft.com/en-us/library/system.drawing.imaging.pixelformat.aspx[^].

[EDIT]

As Philippe Mori correctly pointed out in his comment, Color type cannot be used to solve this problem, it is designed to serve only the pixel formats using 8 bits per color component.

[END EDIT]

You can immediately fill in the pixel memory for any pixel format by using System.Drawing.LockBits:
http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.lockbits.aspx[^].

Also, this is the best for performance. WPF also has similar approach.

—SA
 
Share this answer
 
v3
Comments
Philippe Mori 2-Dec-12 8:30am    
If you carefully read the documentation for Color.FromRgb, it explicitly says that color are limited to 8 bits (per color channel). Thus, Color class cannot be used in OP case.
Sergey Alexandrovich Kryukov 2-Dec-12 13:22pm    
You are right; thank you for correcting me. But second part of my answer is a solution.
I'll remove redundant part.
--SA
Sergey Alexandrovich Kryukov 2-Dec-12 13:26pm    
Done, you correction is credited, after [EDIT].
Thank you again,
--SA

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