473,689 Members | 2,822 Online
Bytes | Software Development & Data Engineering Community
+ 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 6693
* " active" <ac****@REMOV Ea-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(By Val apicP As System.Drawing. Bitmap)

With SaveFileDialog1

..Title = "select Filename And Format"

..Filter = "Bitmap(*.BMP)| *.BMP|Enhanced
Metafile(*.EMF) |*.EMF|Exchange able(*.EXIF)|*. EXIF|Graphics
Interchange(*.G IF)|*.GIF|Icon( *.ICO)|*.ICO|Ic on(*.ICON)|*.IC ON|Joint
Photographic(*. JPEG)|*.JPEG|Jo int Photographic(*. JPG)|*.JPG|Port able
Network(*.PNG)| *.PNG|Tag Image(*.TIFF)|* .TIFF|Metafile( *.WMF)|*.WMF"

..OverwriteProm pt = True

If .ShowDialog = DialogResult.OK Then

Select Case System.IO.Path. GetExtension(.F ileName).ToUppe r

Case ".BMP"

apicP.Save(.Fil eName, Imaging.ImageFo rmat.Bmp)

Case ".EMF"

apicP.Save(.Fil eName, Imaging.ImageFo rmat.Emf)

Case ".EXIF"

apicP.Save(.Fil eName, Imaging.ImageFo rmat.Exif)

Case ".GIF"

apicP.Save(.Fil eName, Imaging.ImageFo rmat.Gif)

Case ".ICO", ".ICON"

apicP.Save(.Fil eName, Imaging.ImageFo rmat.Icon)

Case ".JPEG", ".JPG"

apicP.Save(.Fil eName, Imaging.ImageFo rmat.Jpeg)

Case ".PNG"

apicP.Save(.Fil eName, Imaging.ImageFo rmat.Png)

Case ".WMF"

apicP.Save(.Fil eName, Imaging.ImageFo rmat.Wmf)

Case Else

MsgBox("Can not save file with that extension", MsgBoxStyle.OKO nly Or
MsgBoxStyle.Inf ormation, "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******** ********@tk2msf tngp13.phx.gbl. ..
* " active" <ac****@REMOV Ea-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 CopyFileToBitma p() 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 (*.*)|*.*|Bitma p(*.BMP)|*.BMP| Enhanced
Metafile(*.EMF) |*.EMF|Exchange able(*.EXIF)|*. EXIF|Graphics
Interchange(*.G IF)|*.GIF|Icon( *.ICO)|*.ICO|Ic on(*.ICON)|*.IC ON|Joint
Photographic(*. JPEG)|*.JPEG|Jo int Photographic(*. JPG)|*.JPG|Port able
Network(*.PNG)| *.PNG|Tag Image(*.TIFF)|* .TIFF|Metafile( *.WMF)|*.WMF"

If .ShowDialog = DialogResult.OK Then

'Try

Dim bmpTmp As Drawing.Bitmap = Drawing.Bitmap. FromFile(.FileN ame)

Dim bmp As Drawing.Bitmap = bmpTmp.Clone

bmpTmp.Dispose( )

Return bmp

'Catch

' MsgBox("Can not copy that type of file", MsgBoxStyle.OKO nly Or
MsgBoxStyle.Inf ormation, "File Type Can Not Be Converted To Bitmap")

'End Try

End If

End With

End Function

Did a quick watch on Drawing.Bitmap. FromFile(.FileN ame) 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
3092
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 LGraphics = Graphics.FromImage(imgMap.Image); LGraphics.DrawString("X", new Font("Arial", 12), SystemBrushes.WindowText, AX, AY);
4
19100
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 = null; System.Drawing.Image imgNewImage = null;
3
20088
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 "My Documents" folder or subfolders. If the file lives anywhere else on the hard drive, I have no problems. What could be going on here?
0
1850
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 andhas a large blue area on a particular side, which gets largerevery time the image is flipped again. I'm assuming that this may be due to a lack of time assigned tothe procedure before saving the image, but I'm not sure how Ican recitify this. I...
13
3328
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 referenced, custom dll. I call a PrintImage routine in the dll and pass it only the the Picturebox.hdc from the main form. The dll's print routine draws to the hdc and it shows up in the picturebox perfectly. I would like to do a similar thing...
4
2760
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 first then paint it larger? and how would i make the entire image transparent at 75% transparency (25% opaque) thanks!
1
2710
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 class MyImage { //data member image
2
3103
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 stuck. I'm trying to draw a bitmap on my main form and then to draw a second bitmap, as if it were a sprite (e.g., a "unit" in a wargame), on top of the first. The main form renders fine; I handle the Paint event by creating a temporary Graphics...
2
8752
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 file, but I have been unable to get any of the overloads to work in VB.NET. I would like to store the *.ico files in a *.resx file so that users do not need anything other than the *.dll, but at the moment I am just trying to get any of the overloads...
0
8594
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
8528
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8947
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8783
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5810
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4321
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4547
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2965
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 we have to send another system
3
1952
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.