Example #1
0
        private Image GenerateThumb(ImageModel img)
        {
            if (!File.Exists(img.fileUri))
                return null;
            string ext = Path.GetExtension(img.fileUri);
            Image image = Image.FromFile(img.fileUri, true);
            int height = (int)(image.Height / (image.Width/282f)), width = 282;
            var destRect = new Rectangle(0, 0, width, height);
            var destImage = new Bitmap(width, height);

            destImage.SetResolution(image.HorizontalResolution, image.VerticalResolution);

            using (var graphics = Graphics.FromImage(destImage))
            {
                graphics.CompositingMode = CompositingMode.SourceCopy;
                graphics.CompositingQuality = CompositingQuality.HighSpeed;
                graphics.InterpolationMode = InterpolationMode.Default;
                graphics.SmoothingMode = SmoothingMode.HighSpeed;
                graphics.PixelOffsetMode = PixelOffsetMode.HighSpeed;

                using (var wrapMode = new ImageAttributes())
                {
                    wrapMode.SetWrapMode(WrapMode.TileFlipXY);
                    graphics.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, wrapMode);
                }
            }
            destImage.Save($"{RinDB.THUMB_DIR}/{img.id}{ext}", (ext == ".gif") ? ImageFormat.Gif : ImageFormat.Png);
            return destImage;
        }
Example #2
0
 private Response GetOrGenerateThumb(ImageModel image)
 {
     string ext = Path.GetExtension(image.fileUri);
     if(!File.Exists($"{RinDB.BASE_DIR}/RinDB/thumbs/{image.id}{ext}"))
     {
         if (!Directory.Exists(RinDB.THUMB_DIR))
             Directory.CreateDirectory(RinDB.THUMB_DIR);
         return Response.FromImage(GenerateThumb(image), (ext == ".gif") ? "image/gif" : "image/png");
     }
     return Response.FromImage(Image.FromFile($"{RinDB.THUMB_DIR}/{image.id}{ext}", true), (ext == ".gif") ? "image/gif" : "image/png");
 }