473,396 Members | 1,933 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.

Convert String to System.Drawing.Image

1
VVVVVVVVVVVVVVVVVVVVVVVV Code

Expand|Select|Wrap|Line Numbers
  1. Private Sub impimg_Click(sender As Object, e As EventArgs) Handles impimg.Click
  2.         Dim fileimg As New OpenFileDialog
  3.         fileimg.Filter = "Bitmap Images (*.bmp)|*.bmp"
  4.         fileimg.Title = "Open Icon File"
  5.         fileimg.InitialDirectory = "C:\"
  6.         DialogResult = fileimg.ShowDialog
  7.         If DialogResult = Windows.Forms.DialogResult.OK Then
  8.             imglabel.Text = fileimg.FileName
  9.             finalinp.imgpic.Image = fileimg.FileName
  10.         End If
  11.     End Sub
  12.  
  13. Here
  14.  
  15.             finalinp.imgpic.Image = fileimg.FileName
is where I get the trouble I tried
Expand|Select|Wrap|Line Numbers
  1. Dim imgz As System.Drawing.Image = fileimg.FileName
but it didn't work.
Jun 8 '15 #1
1 4980
!NoItAll
297 100+
Fileimg.filename returns a string (which you appear to know), but that string is not the image, rather it is a string such as "myicon.ico" and cannot be converted to the image you want.
Instead try the fromfile method of the system.drawing.image class.
Expand|Select|Wrap|Line Numbers
  1. Private Sub impimg_Click(sender As Object, e As EventArgs) Handles impimg.Click
  2.  
  3.         Dim myImage as System.drawing.image
  4.  
  5.         Dim fileimg As New OpenFileDialog
  6.         fileimg.Filter = "Bitmap Images (*.bmp)|*.bmp"
  7.         fileimg.Title = "Open Icon File"
  8.         fileimg.InitialDirectory = "C:\"
  9.         DialogResult = fileimg.ShowDialog
  10.  
  11.         If DialogResult = Windows.Forms.DialogResult.OK Then
  12.             imglabel.Text = fileimg.FileName
  13.             MyImage = Image.fromfile(fileimg.FileName)
  14.         End If
  15.  
  16.  
  17. End Sub
  18.  
Now that you have an image (MyImage) you can do something useful with it such as

Expand|Select|Wrap|Line Numbers
  1. Picturebox1.Image = MyImage
...and see the image. You can also place the imgLabel below the image so you can see the filename.
Jun 15 '15 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Toby Mathews | last post by:
Hi, In an ASP.Net application I want to convert open create a FileStream object from a System.Drawing.Image - is this possible? I create an instance of an Image object using the FromFile method,...
3
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...
2
by: PJ | last post by:
Hi I was developing a Class for skinning an application. IN order to read the image file dynamically I used System.Drawing.Image.FromFile("..."). Strangely VS 2003 returns an error saying that...
1
by: Mchuck | last post by:
I've seen several newsgroup topics everywhere concerning this, as well as a couple of articles from the MSDN website, but this error still baffles me. It has to do with using the...
2
by: Jeremy | last post by:
I am creating an imaging service using WIA (Windows Imaging Acquisition). The problem is that I cannot convert a WIA.ImageFile to a System.Drawing.Image to put a timestamp on the image without...
3
by: JackBlack | last post by:
Using VB.Net (VS.Net 2k3)... I'm at a bit of an impasse I think... Is there any way to convert an array of Byte() into a System.Drawing.Image object without writing the array to a file, then...
5
by: Jerry J | last post by:
I want to use the System.Drawing.Image class. According to the help file, this is an abstract base class. Because it is supposedly abstract, I created another class that inherits from it. However,...
1
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...
3
by: Dave Keen | last post by:
Hi all. Hope you can help me. This should be easy but I can't make this work. In brief I am building a page of thumbnails using images held in a SQLServer 2000 database. I do this by creating...
9
by: Eric | last post by:
Hi Everyone, I'm writing a UserControl that exposes a property of the type System.Drawing.Image, like this: Public Property DefaultImage() As Image Get Return propDefaultImage End Get...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.