473,761 Members | 8,463 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 6698
* " 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
3095
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
19102
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
20109
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
1856
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
3347
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
2769
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
2713
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
3105
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
8760
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
9522
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
10111
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9948
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
9902
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
9765
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6603
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
5364
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3866
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
3446
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.