I need to have an image in my silverlight library and load it into a bitmap. I want to just refer to it like a resource, but not sure how to go about it. I don't have any xaml at all in this library, but what I read seems to indicate I need to do it with xaml.
Here is how I did it in a sample solution using the imageLoaded event. (you know how silverlight just loves async stuff!) The image properties is set to resource/copy always.
public partial class MainPage : UserControl
{
WriteableBitmap myIcon = new WriteableBitmap(100, 100);
public MainPage()
{
InitializeComponent();
LoadImages();
}
public void LoadImages()
{
BitmapImage bmi = new BitmapImage();
bmi.ImageOpened += ImagesLoaded;
bmi.CreateOptions = BitmapCreateOptions.None;
bmi.UriSource = new Uri(App.Current.Host.Source, "/ClientBin/HouseLogo.png");
}
public void ImagesLoaded(object sender, RoutedEventArgs e)
{
BitmapImage bm = (BitmapImage)sender;
myIcon = new WriteableBitmap(bm);
}
private void btnPdf_Click(object sender, RoutedEventArgs e)
{
PDFdoc doc = new PDFdoc(32.0, 32.0, myIcon );
}
}