Drag and Drop image

Scribbly

Member
Joined
Jul 16, 2007
Messages
9
Programming Experience
3-5
This one has me quite stumped.

VB.NET:
ElseIf thisFormat = DataFormats.Dib.ToString Then
 Dim im As Image
 im = thisData.GetData(DataFormats.Bitmap, True)
 Me.pictureboxData.Image = im

When dragging an image (from webpage) onto win form the above code is executed eventually, but the Image is always Nothing.

When I tried to use the DataFormats.Dib with something like:
VB.NET:
Dim bm As Bitmap = Bitmap.FromStream(thisData.GetData(DataFormats.Dib, True))

I get a "parameter is not valid" error, which seams odd because DataFormats.Dib returns a MemoryStream?

Thanks for any help.
 
I've been investigating this a bit and, while I can't give you an answer, I can give you an explanation and an avenue of investigation. A device-independent bitmap has no specific managed representation. I believe that what you'd have to do would be to use unmanaged code to create a device-independent bitmap from the data in the stream, then create a .NET Bitmap from that. Exactly how I really couldn't say. It might be easier to use a different data format, like the URL and download the image file yourself.
 
Thanks, I wondered if that was going to be the best avenue, though it seems a shame to download the image again if it already has been and displayed, eh?
 
Thanks, I wondered if that was going to be the best avenue, though it seems a shame to download the image again if it already has been and displayed, eh?
I agree. That's why I think unmanaged code might be the "best" way, but I'm afraid I have no idea what such a solution would look like.
 
Back
Top