コード例 #1
0
ファイル: ImageLoader.cs プロジェクト: vvarshne/monodevelop
 void LoadFromDisk(string path, bool downloaded)
 {
     Xwt.Application.Invoke(delegate {
         Xwt.Drawing.Image newImage = null;
         try {
             if (File.Exists(path))
             {
                 using (var stream = File.OpenRead(path))
                     newImage = Xwt.Drawing.Image.FromStream(stream);
                 if (Math.Abs(scaleFactor - 1) > 0.2)
                 {
                     newImage = newImage.Scale(1 / scaleFactor);
                 }
             }
             UpdateImage(newImage, downloaded);
         } catch (Exception ex) {
             LoggingService.LogError("Failed to load cached image", ex);
             try {
                 File.Delete(path);
             } catch {
                 LoggingService.LogError("Failed to delete corrupt cached image", ex);
             }
             UpdateImage(null, downloaded);
         }
     });
 }
コード例 #2
0
        private void ScaleImage(Xwt.Drawing.Image image)
        {
            double num1 = image.Width > image.Height ? image.Width : image.Height;

            if (num1 > 46.0)
            {
                double num2 = 46.0 / num1;
                image = image.Scale(num2, num2);
            }
            this.imageWidget.Image = image;
            this.imageWidget.QueueDraw();
        }
コード例 #3
0
 public static Xwt.Drawing.Image GetPreviewIcon(string filePath, out double width, out double height, bool isFouse = false)
 {
     filePath = Path.Combine(filePath);
     Xwt.Drawing.Image image = (Xwt.Drawing.Image)null;
     if (!isFouse && ImageIcon.previewIcons.TryGetValue(filePath, out image))
     {
         width  = image.Width;
         height = image.Height;
         return(image);
     }
     image = ImageIcon.GetImageFromFile(filePath);
     if (image != null)
     {
         width  = image.Width;
         height = image.Height;
         if (ImageIcon.previewIconNames.Count <string>() >= ImageIcon.previewIconCacheMax)
         {
             string key = ImageIcon.previewIconNames.Dequeue();
             ImageIcon.previewIcons.Remove(key);
         }
         double num = 1.0;
         if (image.Width > 46.0 && image.Width >= image.Height)
         {
             num = 46.0 / image.Width;
         }
         if (image.Height > 46.0 && image.Height >= image.Width)
         {
             num = 46.0 / image.Height;
         }
         image = image.Scale(num, num);
         ImageIcon.previewIcons[filePath] = image;
         ImageIcon.previewIconNames.Enqueue(filePath);
     }
     else
     {
         width  = 0.0;
         height = 0.0;
     }
     return(image);
 }
コード例 #4
0
        private void DrawImageSized(PageImage pi, Xwt.Drawing.Image im, Xwt.Drawing.Context g, Xwt.Rectangle r)
        {
            double    height, width;   // some work variables
            StyleInfo si = pi.SI;

            Xwt.Rectangle r2 = new Xwt.Rectangle(r.X + PixelsX(si.PaddingLeft),
                                                 r.Y + PixelsY(si.PaddingTop),
                                                 r.Width - PixelsX(si.PaddingLeft + si.PaddingRight),
                                                 r.Height - PixelsY(si.PaddingTop + si.PaddingBottom));

            Xwt.Rectangle ir;   // int work rectangle
            switch (pi.Sizing)
            {
            case ImageSizingEnum.AutoSize:

                float imwidth  = PixelsX((float)im.Size.Width);
                float imheight = PixelsX((float)im.Size.Height);
                ir = new Xwt.Rectangle(Convert.ToInt32(r2.X), Convert.ToInt32(r2.Y),
                                       imwidth, imheight);

                im.Scale((int)r2.Width, (int)r2.Height);
                g.DrawImage(im, ir);

                break;

            case ImageSizingEnum.Clip:
                g.Save();
                g.Rectangle(r2);
                g.Clip();


                ir = new Xwt.Rectangle(Convert.ToInt32(r2.X), Convert.ToInt32(r2.Y),
                                       im.Size.Width, im.Size.Height);

                g.DrawImage(im, ir);
                g.Restore();
                break;

            case ImageSizingEnum.FitProportional:
                double ratioIm = (float)im.Size.Height / (float)im.Size.Width;
                double ratioR  = r2.Height / r2.Width;
                height = r2.Height;
                width  = r2.Width;
                if (ratioIm > ratioR)
                {
                    // this means the rectangle width must be corrected
                    width = height * (1 / ratioIm);
                }
                else if (ratioIm < ratioR)
                {
                    // this means the ractangle height must be corrected
                    height = width * ratioIm;
                }
                r2 = new Xwt.Rectangle(r2.X, r2.Y, width, height);
                g.DrawImage(im, r2);
                break;

            case ImageSizingEnum.Fit:
            default:
                g.DrawImage(im, r2);
                break;
            }
        }