jump to navigation

Set Image.Source properties using project Properties.Resource images October 16, 2010

Posted by geek-ish.com in Uncategorized.
trackback

 

I got tired of validating URI’s and wanted to use app Resource images.  Play with it at your own risk though.  Interop stuff is known to leak.  HTH!

private void SetImageControlSourceFromBitmap(System.Windows.Controls.Image img, Bitmap bmp)
        {
            try
            {
                img.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
                    bmp.GetHbitmap(),
                    IntPtr.Zero,
                    System.Windows.Int32Rect.Empty,
                    BitmapSizeOptions.FromWidthAndHeight(bmp.Width, bmp.Height)
                    );
            }
            catch { }           
        }

Advertisements

Comments»

No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: