New Bitmap Image from Uri - CSharp System.Drawing

CSharp examples for System.Drawing:Bitmap

Description

New Bitmap Image from Uri

Demo Code


using System.Windows.Media.Imaging;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;/*w  w w.  jav  a 2  s .c o  m*/

public class Main{
        public static BitmapImage NewBitmapImage(Uri uri)
        {
            BitmapImage bmp = null;
            try
            {
                bmp = new BitmapImage();
                bmp.BeginInit();
                bmp.CreateOptions |= BitmapCreateOptions.IgnoreColorProfile;
                bmp.UriSource = uri;
                bmp.EndInit();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(string.Format("{0} {1} {2}",
                System.Reflection.Assembly.GetExecutingAssembly().GetName().Name,
                ex,
                "Failed to create bitmap image"));

            }

            return bmp;
        }
}

Related Tutorials