Solved

Covert string to image resouce vb.net

Posted on 2014-02-06
7
231 Views
Last Modified: 2014-02-10
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
0
Comment
Question by:SweetingA
7 Comments
 
LVL 14

Expert Comment

by:Matti
ID: 39840069
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.
0
 

Author Comment

by:SweetingA
ID: 39840178
I'm afraid i am a real novice, how do i do that?
0
 
LVL 14

Accepted Solution

by:
Matti earned 500 total points
ID: 39840249
picMA.Image = My.Resources.gauge_25 as object

or

picMA.Picture = My.Resources.gauge_25 as object

try there is very little code on both sides
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:SweetingA
ID: 39840261
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
0
 

Author Comment

by:SweetingA
ID: 39840291
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

Thanks
0
 
LVL 40
ID: 39840535
picMA.Image = DirectCast(My.Resources.ResourceManager.GetObject("gauge_25"), Image)

If DirectCast does not work, try replacing it by CType.
0
 
LVL 79

Expert Comment

by:David Johnson, CD, MVP
ID: 39840662
are you trying to display a number as an image?
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question