473,491 Members | 1,965 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Drawing.Bitmap.FromFile ever work for WMF files

I find Bitmap.Save works for WMF files but Bitmap.FromFile does not.

If I use FromFile on a WMF file that came with VS I get an exception.
If I use it on a WMF file created with Bitmap.Save I don't get an exception
but it appears the Bitmap is blank.

Can anyone share some knowledge on this?
Thanks,
Cal
Nov 20 '05 #1
2 6671
* " active" <ac****@REMOVEa-znet.com> scripsit:
I find Bitmap.Save works for WMF files but Bitmap.FromFile does not.

If I use FromFile on a WMF file that came with VS I get an exception.
If I use it on a WMF file created with Bitmap.Save I don't get an exception
but it appears the Bitmap is blank.


Exception text?

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #2
Answer to your question below but first: I lied below. The reason I don't
get an exception from Files Bitmap wrote is because Bitmap writes PNG file
when asked to write PNG, WMF, EMF or ICON.

Here is the code. I put breakpoints at each of the Saves so I know if I ask
it to write a WMF for example it executes the correct statement.

It appears to write BMP, JPEG and GIF files correctly.
Private Sub SaveBitmapAs(ByVal apicP As System.Drawing.Bitmap)

With SaveFileDialog1

..Title = "select Filename And Format"

..Filter = "Bitmap(*.BMP)|*.BMP|Enhanced
Metafile(*.EMF)|*.EMF|Exchangeable(*.EXIF)|*.EXIF| Graphics
Interchange(*.GIF)|*.GIF|Icon(*.ICO)|*.ICO|Icon(*. ICON)|*.ICON|Joint
Photographic(*.JPEG)|*.JPEG|Joint Photographic(*.JPG)|*.JPG|Portable
Network(*.PNG)|*.PNG|Tag Image(*.TIFF)|*.TIFF|Metafile(*.WMF)|*.WMF"

..OverwritePrompt = True

If .ShowDialog = DialogResult.OK Then

Select Case System.IO.Path.GetExtension(.FileName).ToUpper

Case ".BMP"

apicP.Save(.FileName, Imaging.ImageFormat.Bmp)

Case ".EMF"

apicP.Save(.FileName, Imaging.ImageFormat.Emf)

Case ".EXIF"

apicP.Save(.FileName, Imaging.ImageFormat.Exif)

Case ".GIF"

apicP.Save(.FileName, Imaging.ImageFormat.Gif)

Case ".ICO", ".ICON"

apicP.Save(.FileName, Imaging.ImageFormat.Icon)

Case ".JPEG", ".JPG"

apicP.Save(.FileName, Imaging.ImageFormat.Jpeg)

Case ".PNG"

apicP.Save(.FileName, Imaging.ImageFormat.Png)

Case ".WMF"

apicP.Save(.FileName, Imaging.ImageFormat.Wmf)

Case Else

MsgBox("Can not save file with that extension", MsgBoxStyle.OKOnly Or
MsgBoxStyle.Information, "File Type Can Not Be Saved")

End Select

End If

End With

End Sub
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
* " active" <ac****@REMOVEa-znet.com> scripsit:
I find Bitmap.Save works for WMF files but Bitmap.FromFile does not.

If I use FromFile on a WMF file that came with VS I get an exception.
If I use it on a WMF file created with Bitmap.Save I don't get an exception but it appears the Bitmap is blank.


Exception text?

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>

As to your question: I get an Invalid Cast exception. Here is the code:

Public Function CopyFileToBitmap() As Drawing.Bitmap

'Caller needs to dispose bitmap returned

'The file remains locked until the Image object is disposed so I clone it

With OpenFileDialog1

..Title = "select Filename To Copy"

..Filter = "All (*.*)|*.*|Bitmap(*.BMP)|*.BMP|Enhanced
Metafile(*.EMF)|*.EMF|Exchangeable(*.EXIF)|*.EXIF| Graphics
Interchange(*.GIF)|*.GIF|Icon(*.ICO)|*.ICO|Icon(*. ICON)|*.ICON|Joint
Photographic(*.JPEG)|*.JPEG|Joint Photographic(*.JPG)|*.JPG|Portable
Network(*.PNG)|*.PNG|Tag Image(*.TIFF)|*.TIFF|Metafile(*.WMF)|*.WMF"

If .ShowDialog = DialogResult.OK Then

'Try

Dim bmpTmp As Drawing.Bitmap = Drawing.Bitmap.FromFile(.FileName)

Dim bmp As Drawing.Bitmap = bmpTmp.Clone

bmpTmp.Dispose()

Return bmp

'Catch

' MsgBox("Can not copy that type of file", MsgBoxStyle.OKOnly Or
MsgBoxStyle.Information, "File Type Can Not Be Converted To Bitmap")

'End Try

End If

End With

End Function

Did a quick watch on Drawing.Bitmap.FromFile(.FileName) and got
Value = Drawing.Imaging.MetaFile
Type = Drawing.Image
Got rid of the Catch so I could see the exception
Nov 20 '05 #3

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

Similar topics

4
3074
by: Christina Androne | last post by:
Hi I want to allow the user to drow some locators on an image and connect the locators with lines. So I tried to put the following code in the onmousedown enevt of the picture: Graphics...
4
19060
by: funcSter | last post by:
Hey, got a prob which is driving me nuts! I'm trying to resize the resolution of an image as well as it's pyhsical byte size. I've got: byte bytImage = null; System.Drawing.Image imgImage =...
3
19971
by: anastasia | last post by:
I get an out of memory exception when attempting to excecute the following code: original = System.Drawing.Image.FromFile(file.FileName,true); I ONLY get this exception when the file is in the...
0
1826
by: John via .NET 247 | last post by:
Hi, I'm using the System.Drawing.Bitmap namespace to load an image,and the RotateNoneFlipY method to flip that image before saving.However I have noticed that the saved image appears cropped...
13
3284
by: Metallicraft | last post by:
I have a vb6 application. On the main form is a picture box with one or two images and several pieces of text displayed in it. These are created on the fly using gdi32 routines that are all in a...
4
2739
by: Brian Henry | last post by:
I have an icon I want to draw onto the screen, but I want to streatch it out to be about 256x256 and make it about 75% transparent how would I go about this? do i need to convert it to a bitmap...
1
2680
by: Martijn Mulder | last post by:
At startup my application loads an image from a file from disk. If the file is not there, I still need a valid System.Drawing.Image object but I don't know how to get one. //class MyImage...
2
3087
by: Carl | last post by:
I'm new to C#, and I have only limited programming experience. I've been doing the video tutorials at MS's website, and they're very helpful, but I decided to experiment with GDI+ and have gotten...
2
8712
by: Nathan Sokalski | last post by:
I am attempting to create icons for controls I have created using VB.NET by using the System.Drawing.ToolboxBitmap attribute. I have managed to do this in C# by specifying the path to the *.ico...
0
7118
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,...
1
6862
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5452
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,...
0
4579
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3087
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1397
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
637
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
282
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.