How to create a bitmap image programmatically when its source is an image with Build Action = Resource?
When I try the following I get an invalid URI exception :(
BitmapIm开发者_StackOverflow社区age image = new BitmapImage(new Uri("/MyAssembly;component/Images/MyImage.png"));
I'm using silverlight 4 and this code is inside one of the many projects of my solution (it's a silverlight class library and not the silverlight application).
BitmapImage image = new BitmapImage(new Uri("/MyAssembly;component/Images/MyImage.png"));
should be:
BitmapImage image = new BitmapImage(new Uri("/MyAssembly;component/Images/MyImage.png", UriKind.Relative));
Images/MyImage.png
also assumes your image is located inside a folder called Images
.
var image = new ImageInline(new Uri("/BF.SilverlightClient;component/Views/Reports/ChartLegendBar.png", UriKind.Relative))
{ Width = 200, Height = 25};
精彩评论