• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 261
  • Last Modified:

Covert string to image resouce vb.net

The following code is used to load an image.....

picMA.Image = My.Resources.gauge_25
picMA.SizeMode = PictureBoxSizeMode.Zoom

But i need to set the "gauge_25" as a variable

Is this possible, why i try i get an error in the conversion?

Thanks in advance
1 Solution
use object variable if you wan to load a picture in a variable. explaining image formats as basics and how to save them as bytes here is a bit matter of copyrights who has them and what type of image.
SweetingAAuthor Commented:
I'm afraid i am a real novice, how do i do that?
picMA.Image = My.Resources.gauge_25 as object


picMA.Picture = My.Resources.gauge_25 as object

try there is very little code on both sides
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

SweetingAAuthor Commented:
I have tried this where MA =0.84
MA is declared as Double

i have tried delcaring img as a string and as an object        

img = "Gauge-" & Int(MA) & ".png"
picMA.Image = My.Resources.ResourceManager.GetObject(img)
picMA.SizeMode = PictureBoxSizeMode.Zoom

When i run it, no picture is displayed
SweetingAAuthor Commented:
Hi Matti,

Sorry i just don't get it, i want assign any 1 of 150 pictures depending on certain criteria (i.e. the value of MA) so i need the .Gauge_25 part to be a variable

Jacques Bourgeois (James Burger)PresidentCommented:
picMA.Image = DirectCast(My.Resources.ResourceManager.GetObject("gauge_25"), Image)

If DirectCast does not work, try replacing it by CType.
David Johnson, CD, MVPOwnerCommented:
are you trying to display a number as an image?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now