views:

464

answers:

3

I am creating a 64bit bitmap and wrapping it using Graphics object to draw over it. Problem is Gdiplus Color class is only 32bit(each component is byte only i.e.max 255) so how can I draw over a 64bit image using gdiplus? e.g.

Bitmap bmp(100, 100, PixelFormat64bppARGB);

Graphics g(&bmp);
//how do I draw a red line now, if i use Color(255,0,0) it comes as almost dark black red
A: 

You can use this Bitmap contructor to set the pixel format:

public:
Bitmap(
    int width, 
    int height, 
    PixelFormat format
)

EDIT: You won't be able to use the Color class (I think) as it only supports 32 bit colors. You can however call LockBits on the Bitmap and loop through it manually.

Ed Swangren
thats what i am doing and question is not that, how you will draw 64bit colors over it using gdiplus graphics object
Anurag Uniyal
I'm not sure what you mean, if you get at the buffer, each component will be 2 bytes.
Ed Swangren
see modified question.
Anurag Uniyal
+2  A: 

It seems Gdiplus doesn't support any 64-bit operations. An somehow easy way to still be able to use Gdiplus methods would be to split the image in two 32-bit images and operate on them seperately.

You could either split the ARGB channels into AARR and GGBB or use two 32-bit images with the lower and higher ARGB bits.

Both variants would need that you either write wrapping functions or split each call into two parts like this:

// This is what you want to do (ARGB, 16 bit per channel)
// g.DrawLine(new Pen(Color(0, 65535, 1024, 31), 1, 0, 0, 100, 100);

// AARR GGBB variant
gAARR.DrawLine(new Pen(Color(0,0,255,255), 1, 0, 0, 100, 100);
gGGBB.DrawLine(new Pen(Color(4,0,0,31), 1, 0, 0, 100, 100);

// ARGBhigh ARGBlow variant
gHigh.DrawLine(new Pen(Color(0,255,4,0), 1, 0, 0, 100, 100);
gLow.DrawLine(new Pen(Color(0,255,0,31), 1, 0, 0, 100, 100);

Note that I used Color(A,R,G,B) order here and I'm not sure about it. According to the MSDN documentation, this must be changed to Color(R,G,B,A) instead. If you won't need the alpha channel, you should prefer the highlow variant as you should still be able to use Color(R,G,B) with it.

To display or save the results, you'll need to merge the 2 buffers.

schnaader
I don't think this will work because you'll screw up the anti-aliasing and transparency effects. Even if you merge "intelligently" (which is still an undefined concept...) it will still make incorrect choices for anti-aliasing.
Jason Cohen
That's right, there could/will be some side-effects, but I think those can be handled (i.e. switching off anti-aliasing). It still seems to be one of the best ways to create 64-bit images without heavy efforts.
schnaader
but in that case I will just draw to a 32bit transparent image and copy it again with each pixel scaled to 64bit, that is much easier.
Anurag Uniyal
+1  A: 

You can't according to MSDN - Image Pixel Format Constants:

Remarks

PixelFormat48bppRGB, PixelFormat64bppARGB, and PixelFormat64bppPARGB use 16 bits per color component (channel). Microsoft Windows GDI+ version 1.0 can read 16-bits-per-channel images, but such images are converted to an 8-bits-per-channel format for processing, displaying, and saving.

dalle