Reading metafile or gif from clipboard to picturebox

B

B. Cline

Hi,

I need to write a conversion routine to split pictures out of about 10000
word documents. (Actually the text is converted to RTF, the pictures should
be converted to jpg).

I thought I could simply save the word doc as rtf and strip the picture.
That works. The problem is getting the picture to save correctly. I can use
word to determine which pictures are in the original document and can get
them to the clipboard. I can't seem to be able to paste this into a
picturebox for further processing (selecting the correct picture etc.).

Code like
If Clipboard.GetDataObject.GetDataPresent(DataFormats.Bitmap, True)
Then
Dim i As Image
i = CType(Clipboard.GetDataObject.GetData(DataFormats.Bitmap,
True), Bitmap)
PictureBox1.Image = i
End If
won't work because the framework can't identify any of the formats as a
bitmap.

The formats I am seeing are
Office Drawing Shape Format
MetaFilePict
EnhancedMetafile
PNG+Office Art
JFIF+Office Art
GIF+Office Art
PNG
JFIF
GIF
(On a different computer I also saw DIB but that was at home :)

Has anyone managed to do something like this? Or could someone give me a
nudge in the correct direction or group?

Thanks
Ben
 
C

Cor

Hi Ben,

I never used in this way,
But for bringing a picture to an image it need to be readed as stream.

Something as (This is from a dataset)
Dim arrPicture() As Byte = CType(dspictabel.Tables(0).Rows(x)("pic"),
Byte())
Dim ms As New MemoryStream(arrPicture)
originalImage = Image.FromStream(ms)

I think you would do something in the same way,

Cor
 
E

Eduardo A. Morcillo [MS MVP VB]

If Bitmap fails you can get the other format like this:

Dim data As IDataObject = Clipboard.GetDataObject()
Dim img As Image

If data.GetDataPresent("GIF") Then
img = Image.FromStream(data.GetData("GIF"))
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top