James Russo

James Russo

  • NA
  • 1
  • 0

Bitmap sent to clipboard showing up as 32bpp DIB not 24bpp DIB?

May 3 2006 8:34 AM
Hello,

I have an application which requires an image to be retrived from the
clipboard. So, I am writting a quick C# windows application to take
images from a webcam and store a single frame on the clipboard so it can
be pasted into this other application. My solution is working fine with
all applications (mspaint, word, wordpad) except the one I need it to
work with. I've contacted the vendor of the application, but I haven't
been able to get anywhere with them.

I think I've narrowed down my problem to the format of the DIB being
placed on the clipboard. When I call Clipboard.setDataObject(someBitmap)
the DIB which is placed into the clipboard has a type of 32bpp BITFIELDS
 and not 24bpp RGB. Even though I specifically set the PixelFormat to
Format24bppRgb when the Bitmap object is created. When I attempt to
paste the image in the target application, nothing happens. If I first
paste the image to mspaint, then select all, copy it to the clipboard
again and then paste it into the application it works fine. When mspaint
places the image on the clipboard it is a 24bpp RGB image, and not a
32bpp BITFIELDS image. I've been using the clipboard viewer application
at
(http://www.codeguru.com/cpp/w-p/clipboard/externallinks/article.php/c9155/)
to see the data placed on the clipboard.

Anyone have any idea how I can take a C# Bitmap object and turn it into
a 24bit RGB image which will appear on the clipboard? I've been trying
to figure this out for hours!

The following code demonstrates the issue :

Bitmap b = new
Bitmap(100,100,System.Drawing.Imaging.PixelFormat.Format24bppRgb);
for (int i=0;i<50;i++)
{
	b.SetPixel(i,i,Color.Red);
}
Clipboard.SetDataObject(b);

After this the CF_DIB stored on the clipboard will be 32bpp and
BITFIELDS not RGB. I am not certain what BITFIELDS means, it is what is
displayed by the clipboard viewer I am using..


Thanks!

-James