473,748 Members | 2,793 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

convert enum to imaging.imagefo rmat

I currently have a class that has an enumeration of graphics extensions that
it supports ie:

Public Enum GraphicFormats
JPG
JPEG
BMP
TIFF
End Enum
When a user selects a file it checks against this enum to verify it has an
okay extension and if I ever want add more files I can just modify this
enum. At some point though I need to translate a variable of the type
GraphicsFormat to type Imaging.ImageFo rmat in order to pass to a function.
I.E. BMP to Imaging.ImageFo rmat.BMP and JPG or JPEG to
Imaging.ImageFo rmat.JPEG.

I thought Maybe I could do the following when the user loads the vaiable:

Public Property FileFormat() As GraphicFormats
Get
If _FileFormat Is Imaging.ImageFo rmat.Jpeg Then
Return GraphicFormats. JPEG
ElseIf _FileFormat Is Imaging.ImageFo rmat.Bmp Then
Return GraphicFormats. BMP
ElseIf _FileFormat Is Imaging.ImageFo rmat.Tiff Then
Return GraphicFormats. TIFF
End If
End Get
Set(ByVal Value As GraphicFormats)
If Value = GraphicFormats. JPEG Or Value = GraphicFormats. JPG
Then
_FileFormat = Imaging.ImageFo rmat.Jpeg
ElseIf Value = GraphicFormats. BMP Then
_FileFormat = Imaging.ImageFo rmat.Bmp
ElseIf Value = GraphicFormats. TIFF Then
_FileFormat = Imaging.ImageFo rmat.Tiff
End If
End Set
End Property

This way the object would really store in _FileFormat of type
Imaging.ImageFo rmat, but when the user access the variable the get a type of
my enumeration. But this doesn't work because if I access _FileFormat in my
class it doesn't have the value, but just an object of type
Imaging.ImageFo rmat, and if I access Me.FileFormat in my class I get a type
of my enum instead.

Also this method kills my ease of adding new extensions to my class. Maybe
I am going about this completely the wrong way. Any suggestions?

Nov 21 '05 #1
3 4091
David,

I have this as almost yours in a program like beneath. You can change that
filterindex of course for the extention and set than in the case more
extentions and test on that. However, this is for me a typical sample of
using a select case (you can set more condition seperated by a comma in a
select case)

http://msdn.microsoft.com/library/de...selectcase.asp

\\\\
Private Sub whatever
)
)
fdlSave.Filter = "Bitmap (*.bmp)|*.bmp|G IF (*.gif)|*.gif|" & _
"JPEG (*.jpg)|*.jpg;* .jpeg|TIF (*.tif)|*.tif|P NG (*.png)|*.png"
fdlSave.FilterI ndex = 3
If fdlSave.ShowDia log() = DialogResult.OK Then
Dim ici As ImageCodecInfo = GetEncoderInfo( fdlSave.FilterI ndex)
newImage.Save(f dlSave.FileName , ici, eps)
End If
End Sub
Private Function Getimageformat( ByVal Filterindex As Integer) As
Imaging.ImageFo rmat
Select Case Filterindex
Case 1
Return Imaging.ImageFo rmat.Bmp
Case 2
Return Imaging.ImageFo rmat.Gif
Case 3
Return Imaging.ImageFo rmat.Jpeg
Case 4
Return Imaging.ImageFo rmat.Tiff
Case 5
Return Imaging.ImageFo rmat.Png
End Select
End Function
///

I hope this helps?

Cor
Nov 21 '05 #2
Thanks, but not exactly what I'm looking for. I'm using a TreeView control
and not a file dialog box. I'm actually hoping to figure out a way to list
my extensions in the enumeration so that it is the only place I will update
to add new extensions. Is there are way to "map" each enumeration to a type
if Imaging.ImageFo rmat?
"Cor Ligthert [MVP]" <no************ @planet.nl> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
David,

I have this as almost yours in a program like beneath. You can change that
filterindex of course for the extention and set than in the case more
extentions and test on that. However, this is for me a typical sample of
using a select case (you can set more condition seperated by a comma in a
select case)

http://msdn.microsoft.com/library/de...selectcase.asp

\\\\
Private Sub whatever
)
)
fdlSave.Filter = "Bitmap (*.bmp)|*.bmp|G IF (*.gif)|*.gif|" & _
"JPEG (*.jpg)|*.jpg;* .jpeg|TIF (*.tif)|*.tif|P NG (*.png)|*.png"
fdlSave.FilterI ndex = 3
If fdlSave.ShowDia log() = DialogResult.OK Then
Dim ici As ImageCodecInfo = GetEncoderInfo( fdlSave.FilterI ndex)
newImage.Save(f dlSave.FileName , ici, eps)
End If
End Sub
Private Function Getimageformat( ByVal Filterindex As Integer) As
Imaging.ImageFo rmat
Select Case Filterindex
Case 1
Return Imaging.ImageFo rmat.Bmp
Case 2
Return Imaging.ImageFo rmat.Gif
Case 3
Return Imaging.ImageFo rmat.Jpeg
Case 4
Return Imaging.ImageFo rmat.Tiff
Case 5
Return Imaging.ImageFo rmat.Png
End Select
End Function
///

I hope this helps?

Cor


Nov 21 '05 #3
David,

Any reason that it "must" be an Enum.
In my opinion is setting in the Tag of the treeview an indexnumber much
easier.

Just my opinion.

Cor
Nov 21 '05 #4

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

Similar topics

0
18021
by: Nicolas Guilhot | last post by:
Hi all ! I have a multi-page Tiff image file that I want to convert to PDF. To do so I am using iText library. The conversion is working, but the code execution is very different according to wich iTextSharp.text.Image.getInstance(...) signature I am using : - using code 1 below, the conversion is fast enough but the resulting PDF file is too big (1 817ko sample Tiff file is converted in less than 30 seconds to a 2 764ko PDF file) -...
2
17054
by: Lucas Cowald | last post by:
Hi, Using ASP and VBScript. How to convert JPEG image into a binary data? Is it possible with a command from ASP / VBScript without having to put it into a database first? I want to take the JPEG image from a folder, convert it into a binary data, and stream it to the browser. How can I do it? Can you show a short code? Thank you for your help.
3
8063
by: Ignacio Marcos | last post by:
Hi all. I need to convert files on my server from gif to jpg format. I tried with the thumb function, but it does not work (on the line thumb.Save(Response.OutputStream, Imaging.ImageFormat.Jpeg)). Anybody can help me, tanks a lot.
4
2418
by: Harry Hudini | last post by:
Hi, I need to run exactly this code in an asp.net file when someone uploads an image, but i dont know C# and im having real issues converting it. If anyone can, could you convert it to VB.net for me to use ? Loads of karma in it for you :) <%@ Import Namespace="System.Collections" %>
7
3400
by: Scott Schluer | last post by:
Is there a way to use the Image class to convert a color photo (GIF or JPEG) to a B&W photo? Thanks, Scott
4
6871
by: Kalvin | last post by:
I am trying to create an image from a graphics object. I would like to create the image and use in the application without having to save to disk. If this isn't possible, please just tell me so I can quite looking. Thank you Kalvin
3
9232
by: Dennis | last post by:
I am trying to convert a bitmap to a JPEG MemoryStream and return a Byte array containing the resulting JPEG Image as follows: Public Function BmpToJPEG(ByVal BitMapIn As Bitmap, ByVal Quality As Long) As Byte() 'find the encoder with the image/jpeg mime-type dim codecs as ImageCodecInfo = ImageCodecInfo.GetImageEncoders() Dim ici As ImageCodecInfo For Each codec As ImageCodecInfo In codecs If (codec.MimeType = "image/jpeg") Then
4
3581
by: Frank | last post by:
Private Sub SaveBitmap(ByVal fileName As String, ByVal p As System.Drawing.Bitmap) ...snip p.Save(fileName, Imaging.ImageFormat.Icon) Does not produce an icon formatted file. At least if I try to open it with icon reading programs it does not open.
2
2701
by: Bill Fuller | last post by:
I have a Bitmap (bm) that I am able to save using, for example, bm.Save("file.jpg", System.Drawing.Imaging.ImageFormat.Jpeg). However, I would like to convert this to a byte array (byte). What is the best way to do this?
0
8991
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
8830
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
9370
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
9321
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
9247
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
4602
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
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2782
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
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.