Infosys Microsoft Alliance and Solutions blog

« ASP.NET AJAX Perils | Main | Why is .NET Micro Framework so crucial for Autonomous digital enterprise »

WPF - Binding to Image Control

Overtime, I have used different approaches to binding pictures to Image control in a WPF application. I have seen various questions on the WPF forum as well on this topic. The information is all available out there, but scattered. Hence, I decided to create a sample application to demostrate the various scenarios that can exist when you need to use the Image control to display pictures.

You can download the demo code (Download file) and play around with it. If you unzip it in C:\, it should work without having to change any file paths etc. There are 7 scenarios that i have currently handled in code. If you can think of more, do pass them along and I will update the code to add them as well

  1. Regular resource image binding to Source property in XAML
  2. Binding resource image, but from code behind
  3. Binding resource image in code behind by using Application.GetResourceStream
  4. Loading image from file path via memory stream (same is applicable when loading blog image data from database)
  5. Loading image from file path, but by using binding to a file path Property
  6. Binding image data to a user control which internally has image control via dependency property
  7. Same as point 5, but also ensuring that the file doesn't get's locked on hard-disk

Comments welcome !

Comments

Hello Atul
I am working on an ImageEditor Functionality in WPF where i need to provide various Image Editing techniques like Cropping,Zooming,Adjusting Brightness,Contrast,Saturation,Auto Image Correction etc.
Could you provide me some useful url links and resource where i can find the solution which performs the functionality on a Fly i.e, by using WPF tags and Commands.

Yusuf, i guess google is the best bet :-)

A few links that you may find useful
http://blog.donburnett.com/2007/04/snipshot-to-rescue.html

http://www.codeproject.com/KB/WPF/ImageCropper.aspx

Not WPF related. Some fuctions directly in C# - http://blog.paranoidferret.com/?p=11

Hi Atul,
Is there a way to store the bmp file created in Step 3 to some temp location like C:\Temp\sample.bmp image?

Kevin, am a bit pressed on time so may not be able to try this out. Since you can get a stream from the Bitmap, how about trying to use that stream to write to a file?

I did find something similar that might give you ideas - http://blogs.msdn.com/swick/archive/2007/12/02/rendering-ink-and-image-to-a-bitmap-using-wpf.aspx

Hi Atul,

I'm unable to get option 6, with the drop image function to work. Each time I drag/drop an image onto the existing image (to override) it disappears.

I'm having the same problem in my own project and wondered if you knew the solutions.

Hi Atul,
I have imagelist of bitmap images,I want to show them in UIEditor.
Any help is appreciated.

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

Please key in the two words you see in the box to validate your identity as an authentic user and reduce spam.

Subscribe to this blog's feed

Follow us on

Blogger Profiles

Infosys on Twitter