ImageSource to string in WPF and C# ?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: ImageSource to string in WPF and C# ?

  1. #1
    Join Date
    Jun 2008
    Posts
    57

    ImageSource to string in WPF and C# ?

    Hi,

    I have the below XAML code :

    PHP Code:
    <Window x:Class="WpfApplication1.Window1"
        
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        
    DataContext="{Binding RelativeSource={RelativeSource Self}}"
        
    WindowStartupLocation="CenterScreen"
        
    Title="Window1" Height="300" Width="300">
        
        <
    Grid>
            <
    Image x:Name="TestImage" Source="{Binding Path=ImageSource}" />
        </
    Grid>

    </
    Window
    Now, I'm gonna set the `TestImage` with the below method :

    PHP Code:
    Image Base64StringToImage(string base64ImageString)
    {
        try
        {
            
    byte[] b;
            
    Convert.FromBase64String(base64ImageString);
            
    MemoryStream ms = new System.IO.MemoryStream(b);
            
    System.Drawing.Image img System.Drawing.Image.FromStream(ms);

            
    //////////////////////////////////////////////
            //convert System.Drawing.Image to WPF image
            
    System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(img);
            
    IntPtr hBitmap bmp.GetHbitmap();
            
    System.Windows.Media.ImageSource imageSource System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmapIntPtr.ZeroInt32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

            
    Image wpfImage = new Image();
            
    wpfImage.Source imageSource;
            
    wpfImage.Width wpfImage.Height 16;
            
    //////////////////////////////////////////////

            
    return wpfImage;
        }
        catch
        {
            
    Image img1 = new Image();
            
    img1.Source = new BitmapImage(new Uri(@"/passwordManager;component/images/TreeView/empty-bookmark.png"UriKind.Relative));
            
    img1.Width img1.Height 16;
            return 
    img1;
        }

    I've used the following code, but it doesn't work :

    PHP Code:
    public string ImageSource getset; }
    ImageSource Base64StringToImage("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAABjUExURXK45////6fT8PX6/bTZ8onE643F7Pf7/pDH7PP5/dns+b7e9MPh9Xq86NHo947G7Hm76NTp+PL4/bHY8ojD67rc85bK7b3e9MTh9dLo97vd8/D3/Hy96Xe76Nfr+H+/6f///1bvXooAAAAhdFJOU///////////////////////////////////////////AJ/B0CEAAACHSURBVHjaXI/ZFoMgEEMzLCqg1q37Yv//KxvAlh7zMuQeyAS8d8I2z8PT/AMDShWQfCYJHL0FmlcXSQTGi7NNLSMwR2BQaXE1IfAguPFx5UQmeqwEHSfviz7w0BIMyU86khBDZ8DLfWHOGPJahe66MKe/fIupXKst1VXxW/VgT/3utz99BBgA4P0So6hyl+QAAAAASUVORK5CYIII").Source.ToString(); 
    Actually , I have a problem with converting ImageSource to string !
    Would you please guide me, how I can do it ?
    Thanks.

  2. #2
    Join Date
    Nov 2007
    Location
    .NET 3.5 / VS2008 Developer
    Posts
    624

    Re: ImageSource to string in WPF and C# ?

    You don't convert the ImageSource to a string. The ImageSource is the type. In WPF, there is a .Net datatype called ImageSource.

    http://weblogs.asp.net/monikadyrda/a...agesource.aspx
    ===============================
    My Blog

  3. #3
    Join Date
    Jun 2008
    Posts
    57

    Re: ImageSource to string in WPF and C# ?

    Thanks friend ,
    I've been gotten the response in StackOverFlow

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center