I'm running into a minor snag.
I load a bitmap into the clipboard using the Ctrl+C command.
The program I wrote, then copies the clipboard into a Bitmap object.
Next the program assigns this as the Image of a Picturebox object.
So far so good... This is where the problem pops up. The Image displayed in the picture box is a dithered image. A nice solid brown patch becomes a dithered patch of color.
It shouldn't be system display settings, since the original image displays properly. It isn't the copy operation, since I can set the clipboard object to the bitmap I just loaded, paste it into a graphics program, and the dithering is not there.
It appears to be a function of the picturebox assignment. Sample code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim b As Bitmap Dim x As IDataObjectx = Clipboard.GetDataObject
If x.GetDataPresent(DataFormats.Bitmap) Thenb = x.GetData(DataFormats.Bitmap)
PictureBox1.Image = b
Clipboard.SetDataObject(b,
True) End If
Picturebox format conversion?
Dirk Van der Straeten
hmm - that doesn't seem to be necessary... if I stick in a line like this:
b = x.GetData(DataFormats.Bitmap)
msgbox(b.Height.ToString & "," & b.Width.ToString)
PictureBox1.Image = b
The box displays the correct H & W for any image I copy to the clipboard.
The problem is just a display problem with the picturebox. (I am not sure what the "native" format for a Picturebox Image is, but whatever the format, the default color depth seems to have a dithered palette.)
The remainder of the program (not shown) works just fine, which is basically hunts for specific colors in a bitmap. Like I said earlier, I can even use Clipboard.Setdata(b, True) to put the original (undithered) image back onto the clipboard.
Oh well; I was just hoping to have the displayed image appear the same as the original. Not a requirement for my program... just a nicety. (And don't you just hate when you can't figure something out ) The solution probably involves specifying a color depth or a palette.
If anyone figures it out, please post a reply; otherwise I'll press on with the dithered images.
Nep23
Another clue Okay, this is truly tortured:
b2 = Image.FromFile("mypic.GIF")
Clipboard.SetDataObject(b2)
b2 = Clipboard.GetDataObject.GetData(DataFormats.Bitmap)
PictureBox2.Image = b2
Loading it from a file into a "bitmap" (B2), then exporting it to the clipboard, and re-importing it from the clipboard actually loads the palette. I must be overlooking something here...
It is almost as if the "image.fromfile" command does import the palette, but doesn't use it; until the image is sent to the clipboard. Perhaps I need to find a way to set the palette of B2
EvanescenceX
I should mention that this appears to be a display problem.
I can still manipulate the bitmap "b", with all the original colors; the problem lies with attempting to display it in it's true colors.
SLV
Related problem:
Reading a GIF image from a file creates a similar dithered bitmap (In memory, and when displayed in the picturebox)
The only work-around I have for this is to manually open the image in an external graphics program and copy it to the clipboard, and then import it.
Does anyone know how to convert a GIF to a Bitmap without losing the original palette colors
More exactly: how can I read a GIF file into an internal bitmap structure, preserving or accurately converting the palette.
Jassim Rahma
Try using variations in the SetResolution Function like for your case
b.SetReslolution(800,600)