473,396 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Metafile to Bitmap and WindowsXP-SP2

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.


Nov 21 '05 #1
3 2079
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" <ki**********@zywave.com> wrote in message
news:Om******************@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.



Nov 21 '05 #2
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
Nov 21 '05 #3
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.

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: fowlertrainer | last post by:
Hi ! My problem is that: I have a program that copy pictures from Notes NSF file. The format is METAFILE or METAFILEPICT. I can save these pictures with this code: import win32api import...
0
by: gana | last post by:
I'm converting an EMF to BMP. Image is coming properly except that background color of the bMP is set to black. I'm saving EMF to a stream and craeting BMP from stream. One more thing I tried is...
1
by: sendhil | last post by:
hi, Iam doing some graphics programming with C#. I have to create a Windows MetaFile from a base64 encoded string. How do i create the file. I want to Overlay this Windows MetaFile on a image...
3
by: Richard Skopal | last post by:
In .NET Windows forms I can create a metafile using this code: Graphics grph = aControl.CreateGraphics(); IntPtr ipHDC = grph.GetHdc(); Metafile mf = new Metafile(aImgFilePath, ipHDC,...
1
by: B. Cline | last post by:
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...
2
by: George Yefchak | last post by:
Hi I need to retrieve a metafile image from the clipboard and render it as a bitmap in my application. In particular, an image will be placed on the clipboard by pasting from PowerPoint (I...
0
by: weiruic | last post by:
I am trying to create a metafile (.emf) on the harddisk, write graphics from a graphics object to it, and then save it. I can do this successfully except I cannot set the horizontal and vertical...
5
by: Peter | last post by:
Does anyone have a c# or vb.net example of how to convert bitmap to Metafile - preferably without writing anything to a file ? Thank You Peter
2
by: Laurent Navarro | last post by:
Hello, I am using a library which returns a byte containing RAW data, ie all pixels' color values coded in a byte array without header. I would like to save those data into a JPEG file so I...
0
by: =?Utf-8?B?U3lsdmFpbiBBcmVuZQ==?= | last post by:
Hi, I would like to serialize a class which includes an image property field. I have no problem saving with bitmap image. However, when using a metafile (*.emf format) the result is also...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.