Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi...


I used image converter in my application.It working good.But retrieving images from database,some images were not displayed.

I used image converter class like this:

public object Convert(object value, Type targetType, object parameter,                                System.Globalization.CultureInfo culture)
{
    MemoryStream ms = new MemoryStream((byte[])value);
    BitmapImage image = new BitmapImage();
    image.SetSource(ms);
    return image;
}

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
    throw new NotImplementedException();

}



but it converts only .jpg/.png format to bitmap images.
My query is,how to retrieve all type image formats to bitmap.
Give me any suggestions....

Thanks,
swathi
Posted
Updated 3-Feb-12 0:06am
v2
Comments
Rajesh Anuhya 3-Feb-12 6:06am    
Edited: Code Tags added.
--RA

1 solution

C#
var path = string.Format("/namespace;component/Folderpath/filename", gridType);
                var uri = new Uri(path, UriKind.Relative);
                var resourceStream = Application.GetResourceStream(uri);
                if (resourceStream == null)
                    return null;

                var bitmap = new BitmapImage();
                bitmap.BeginInit();
                bitmap.StreamSource = resourceStream.Stream;
                bitmap.EndInit();
                return bitmap;


I think this will help you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900