[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.drawing

Metafile to Bitmap and WindowsXP-SP2

news.microsoft.com

9/23/2004 4:06:00 PM

hi,

I have the following sample .NET 1.0 code which converts a metafile to a
bitmap:
Dim tmpImage As Bitmap 'System.Drawing.Image
Dim streamX As New System.IO.MemoryStream()
Dim fs As FileStream, br As BinaryReader
Dim FilePath As String
Dim data() As Byte

FilePath = Application.StartupPath & "\computer.wmf"
streamX = New MemoryStream()
fs = New FileStream(FilePath, FileMode.Open, FileAccess.Read,
FileShare.Read)
br = New BinaryReader(fs)
data = br.ReadBytes(500000)
streamX.Write(data, 0, data.GetLength(0))

tmpImage = New Bitmap(streamX)
Dim outImage As Bitmap = New Bitmap(tmpImage)
outImage.SetResolution(200, 200)
PictureBox1.Image = outImage

I am running under WindowsXP and this code worked perfect before I installed
Service Pack 2 for WindowsXP. Now I get an error in the line tmpImage = New
Bitmap(streamX). The error is "Invalid Parameter Used" and that's it.

Has anyone ever experienced this? I am wondering if this is a new bug
introduced by the Service Pack or did they change something so that WMF
files can't be streamed to a bitmap. I can get this same code to work fine
using a JPG or a GIF, so this error is specific to using a WMF, but in my
situation we'd prefer to use a WMF

Kirk Quinbar
Zywave, Inc.






3 Answers

Ken Tucker [MVP]

9/23/2004 11:41:00 PM

0

Hi,

Whats wrong with doing it this way?

Dim bm As New Bitmap("Computer.wmf")

bm.Save("computer.bmp", Imaging.ImageFormat.Bmp)



Ken

------------------------------

"Kirk Quinbar" <kirk.quinbar@zywave.com> wrote in message
news:Om%23O%23cYoEHA.1308@TK2MSFTNGP14.phx.gbl...
hi,

I have the following sample .NET 1.0 code which converts a metafile to a
bitmap:
Dim tmpImage As Bitmap ''System.Drawing.Image
Dim streamX As New System.IO.MemoryStream()
Dim fs As FileStream, br As BinaryReader
Dim FilePath As String
Dim data() As Byte

FilePath = Application.StartupPath & "\computer.wmf"
streamX = New MemoryStream()
fs = New FileStream(FilePath, FileMode.Open, FileAccess.Read,
FileShare.Read)
br = New BinaryReader(fs)
data = br.ReadBytes(500000)
streamX.Write(data, 0, data.GetLength(0))

tmpImage = New Bitmap(streamX)
Dim outImage As Bitmap = New Bitmap(tmpImage)
outImage.SetResolution(200, 200)
PictureBox1.Image = outImage

I am running under WindowsXP and this code worked perfect before I installed
Service Pack 2 for WindowsXP. Now I get an error in the line tmpImage = New
Bitmap(streamX). The error is "Invalid Parameter Used" and that''s it.

Has anyone ever experienced this? I am wondering if this is a new bug
introduced by the Service Pack or did they change something so that WMF
files can''t be streamed to a bitmap. I can get this same code to work fine
using a JPG or a GIF, so this error is specific to using a WMF, but in my
situation we''d prefer to use a WMF

Kirk Quinbar
Zywave, Inc.







news.microsoft.com

9/24/2004 3:03:00 PM

0

I do not want to convert a physical wmf to a physical bmp, i was just giving
some example code to show how I am using the wmf stream to bitmap
functionality. In my real code, the source is is not a physical file. It''s a
wmf stream from a chart control and then I have to take that stream, convert
it to a bitmap and set an image type control to that bitmap.

thanks for the suggestion though..

kirk


news.microsoft.com

9/28/2004 3:44:00 PM

0

alright, i got the answer direct from Microsoft, so I thought I''d share the
solution:

The New constructor for creation of a bitmap from a stream has changed.
Before SP2, creating a new bitmap from a wmf stream would automatically
reset the stream to position 0, but after SP2, it no longer does that.
Supposedly this was changed to allow more functionality in that you could
read from the stream at any position instead of always from the beginning.
This obviously makes it necessary to reset the stream to the beginning if
your wmf is the whole stream.

so in the code example in my first post, you''d need to do this

streamX.Write(data, 0, data.GetLength(0))
streamX.position = 0 ''reset the stream to the beginning


That should do it!

Kirk Quinbar
Zywave, Inc.