Exemplo n.º 1
0
 public static Image GetImage(this ImageReference ir, Size size)
 {
     using (var ms = ir.OpenImageStream())
         using (var image = Image.FromStream(ms))
         {
             if (size.IsEmpty)
             {
                 size = image.Size;
             }
             var    ratio  = Math.Min(image.Width * size.Height, size.Width * image.Height);
             Bitmap bitmap = null;
             try { bitmap = new Bitmap(image, ratio / image.Height, ratio / image.Width); }
             catch
             {
                 if (bitmap != null)
                 {
                     bitmap.Dispose();
                 }
                 throw;
             }
             return(bitmap);
         }
 }