This is a migrated thread and some comments may be shown as answers.

how to load a PictureBox from a pack Uri

5 Answers 194 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Wadigzon
Top achievements
Rank 1
Wadigzon asked on 07 Aug 2013, 04:32 PM
my png image is stored on a Uri object and it has the following format
"pack://application:,,,/AppName.Modules.App.Shared;component/Images/AppName_logo.png"

how do I put this image into the .value property of a PictureBox element in my report.

regars.

5 Answers, 1 is accepted

Sort by
0
Wadigzon
Top achievements
Rank 1
answered on 08 Aug 2013, 03:24 PM
Is anybody taking a look at this? thanks!
0
Squall
Top achievements
Rank 1
answered on 08 Aug 2013, 04:10 PM
Have you tried with user function to resolve the Image and return it to the PictureBox? The PictureBox.Value supports expressions (right click on the picturebox)

SN
0
Wadigzon
Top achievements
Rank 1
answered on 08 Aug 2013, 04:54 PM
I guess it all revolves around how to convert an embedded Uri object resource image reference into System.Drawing.Image object so that I can push it into the .Value property of the PictureBox. I have not had any luck finding such a snippet of code anywhere so far.
0
David
Top achievements
Rank 1
Iron
Veteran
Iron
answered on 08 Aug 2013, 07:02 PM
If the object in embedded, the odds are the format stored is a BMP.  You should be able to load the object into a System.Drawing.Image object.  You could then use the methods of the Image class to save it in another form should you need it.  Obviously you could also resize or perform some other effect if needed at the same time.
0
Wadigzon
Top achievements
Rank 1
answered on 08 Aug 2013, 07:37 PM
I figured it out, this is how you do it:

var streamResourceInfo = System.Windows.Application.GetResourceStream(_uriImageRef);
if (streamResourceInfo != null)
{
    var stri = streamResourceInfo.Stream;
    var bm = new System.Drawing.Bitmap(stri);
    pictureBoxObj.Value = bm;
}

The only "drawback" is that you have to add a reference to PresentationFramework into your app.
Tags
General Discussions
Asked by
Wadigzon
Top achievements
Rank 1
Answers by
Wadigzon
Top achievements
Rank 1
Squall
Top achievements
Rank 1
David
Top achievements
Rank 1
Iron
Veteran
Iron
Share this question
or