inline image mime type

V

vveen

Pasting an image into a Infopath rich text box and submitting the form results in an xml inline image of the format

<img style=".." src="msoInline/f4b19f6546fa4081" xd:inline="...." />

Using System.Convert.FromBase64String the xd:inline innertext can be converted to an image.

However how do I convert the src innertext to something readable. And does it contain the mime type of the image ?
 
B

Brian Teutsch [MSFT]

There actually isn't a MIME type stored with the image anywhere. The src
data isn't good to anyone besides InfoPath, probably.

The image should be of type GIF or JPG, which you can get at by sniffing the
first few bytes of the converted Base64. I don't believe we keep BMP or PNG
formats, but instead convert them to a universal web format.

Thanks,
Brian
 
V

vveen

Thanks for your quick reply Brian

I tried reading the first 16 bytes of the converted Base64 and converted these into a GUID which I used to construct a System.Drawing.Imaging.ImageFormat.

However the System.Drawing.Imaging.ImageFormat does not return any of the available image types.

What am i doing wrong ?
 
V

vveen

Ok found the solution myself, I am new to the System.drawing class so thats why i was lost.

Sniffing the first bytes did not help me, but, reading the complete image into a bitmap object did the job for me.

I did the following:

Dim objMemStream As New MemoryStream(System.Convert.FromBase64String(Base64String))
Dim objBitMap As New System.Drawing.Bitmap(objMemStream)
Dim objImageFormat As New System.Drawing.Imaging.ImageFormat(objBitMap.RawFormat.Guid)
strMimeType = ImageFormatName(objImageFormat)

Where ImageFormatName is a function using the equal() the determine the mime type, see: http://www.codeproject.com/cs/database/albumviewer.asp?msg=620693#xx620693xx

Thanks for all your help
 
A

Andrew Ma [MSFT]

We have a blog entry about decoding base64 using managed code:
http://blogs.msdn.com/infopath/archive/2004/04/21/117600.aspx

It's pretty similar if you are trying to encode. Just copy everything into a
memory stream and then use GetBuffer()

--
Andrew J. Ma
Software Test Engineer
Microsoft Office InfoPath
http://blogs.msdn.com/ajma
---------------------------------------
This posting is provided "As Is" with no warranties, and confers no rights.
Use of any included script sample are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm.
Please do not send email directly to this alias. This alias is for
newsgroup purposes only.
 

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