Ejemplo n.º 1
0
        public static void MakeMyThumbs(string originalImagePath, string thumbnailPath, int toW, int toH, int X, int Y, int W, int H)
        {
            Image    image    = Image.FromFile(originalImagePath);
            Image    image2   = new Bitmap(toW, toH);
            Graphics graphics = Graphics.FromImage(image2);

            graphics.InterpolationMode  = InterpolationMode.High;
            graphics.SmoothingMode      = SmoothingMode.HighQuality;
            graphics.CompositingQuality = CompositingQuality.HighQuality;
            graphics.InterpolationMode  = InterpolationMode.High;
            graphics.Clear(Color.Transparent);
            graphics.DrawImage(image, new Rectangle(0, 0, toW, toH), new Rectangle(X, Y, W, H), GraphicsUnit.Pixel);
            try
            {
                image2.Save(thumbnailPath, ImageHelp.ImgFormat(thumbnailPath));
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                image.Dispose();
                image2.Dispose();
                graphics.Dispose();
            }
        }
Ejemplo n.º 2
0
        public static void MakeMyThumbs(string originalImagePath, string thumbnailPath, int toW, int toH, int X, int Y, int W, int H)
        {
            Image    image1   = Image.FromFile(originalImagePath);
            int      width1   = toW;
            int      height1  = toH;
            int      x        = X;
            int      y        = Y;
            int      width2   = W;
            int      height2  = H;
            Image    image2   = (Image) new Bitmap(width1, height1);
            Graphics graphics = Graphics.FromImage(image2);

            graphics.InterpolationMode  = InterpolationMode.High;
            graphics.SmoothingMode      = SmoothingMode.HighQuality;
            graphics.CompositingQuality = CompositingQuality.HighQuality;
            graphics.InterpolationMode  = InterpolationMode.High;
            graphics.Clear(Color.Transparent);
            graphics.DrawImage(image1, new Rectangle(0, 0, width1, height1), new Rectangle(x, y, width2, height2), GraphicsUnit.Pixel);
            try
            {
                image2.Save(thumbnailPath, ImageHelp.ImgFormat(thumbnailPath));
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                image1.Dispose();
                image2.Dispose();
                graphics.Dispose();
            }
        }
Ejemplo n.º 3
0
        public static void Image2Thumbs(Image originalImage, string thumbnailPath, int photoWidth, int photoHeight, string mode)
        {
            int    num  = photoWidth;
            int    num2 = photoHeight;
            int    num3 = photoWidth;
            int    num4 = photoHeight;
            int    x    = 0;
            int    y    = 0;
            int    num5 = originalImage.Width;
            int    num6 = originalImage.Height;
            int    x2   = 0;
            int    y2   = 0;
            string a;

            if ((a = mode.ToUpper()) != null)
            {
                if (!(a == "FILL"))
                {
                    if (!(a == "HW"))
                    {
                        if (!(a == "W"))
                        {
                            if (!(a == "H"))
                            {
                                if (a == "CUT")
                                {
                                    if ((double)originalImage.Width / (double)originalImage.Height > (double)num / (double)num2)
                                    {
                                        num6 = originalImage.Height;
                                        num5 = originalImage.Height * num / num2;
                                        y    = 0;
                                        x    = (originalImage.Width - num5) / 2;
                                    }
                                    else
                                    {
                                        num5 = originalImage.Width;
                                        num6 = originalImage.Width * photoHeight / num;
                                        x    = 0;
                                        y    = (originalImage.Height - num6) / 2;
                                    }
                                }
                            }
                            else
                            {
                                num = (num3 = originalImage.Width * photoHeight / originalImage.Height);
                            }
                        }
                        else
                        {
                            num2 = (num4 = originalImage.Height * photoWidth / originalImage.Width);
                        }
                    }
                }
                else
                {
                    num4 = photoHeight;
                    num3 = num4 * num5 / num6;
                    if (num3 > photoWidth)
                    {
                        num4 = num4 * photoWidth / num3;
                        num3 = photoWidth;
                    }
                    x2 = (photoWidth - num3) / 2;
                    y2 = (photoHeight - num4) / 2;
                }
            }
            Image    image    = new Bitmap(num, num2);
            Graphics graphics = Graphics.FromImage(image);

            graphics.InterpolationMode  = InterpolationMode.High;
            graphics.SmoothingMode      = SmoothingMode.HighQuality;
            graphics.CompositingQuality = CompositingQuality.HighQuality;
            graphics.InterpolationMode  = InterpolationMode.High;
            graphics.Clear(Color.White);
            graphics.DrawImage(originalImage, new Rectangle(x2, y2, num3, num4), new Rectangle(x, y, num5, num6), GraphicsUnit.Pixel);
            try
            {
                image.Save(thumbnailPath, ImageHelp.ImgFormat(thumbnailPath));
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                image.Dispose();
                graphics.Dispose();
            }
        }
Ejemplo n.º 4
0
        public static void Image2Thumbs(Image originalImage, string thumbnailPath, int photoWidth, int photoHeight, string mode)
        {
            int width1  = photoWidth;
            int height1 = photoHeight;
            int width2  = photoWidth;
            int height2 = photoHeight;
            int x1      = 0;
            int y1      = 0;
            int width3  = originalImage.Width;
            int height3 = originalImage.Height;
            int x2      = 0;
            int y2      = 0;

            switch (mode.ToUpper())
            {
            case "FILL":
                height2 = photoHeight;
                width2  = height2 * width3 / height3;
                if (width2 > photoWidth)
                {
                    height2 = height2 * photoWidth / width2;
                    width2  = photoWidth;
                }
                x2 = (photoWidth - width2) / 2;
                y2 = (photoHeight - height2) / 2;
                break;

            case "W":
                height2 = height1 = originalImage.Height * photoWidth / originalImage.Width;
                break;

            case "H":
                width2 = width1 = originalImage.Width * photoHeight / originalImage.Height;
                break;

            case "CUT":
                if ((double)originalImage.Width / (double)originalImage.Height > (double)width1 / (double)height1)
                {
                    height3 = originalImage.Height;
                    width3  = originalImage.Height * width1 / height1;
                    y1      = 0;
                    x1      = (originalImage.Width - width3) / 2;
                    break;
                }
                width3  = originalImage.Width;
                height3 = originalImage.Width * photoHeight / width1;
                x1      = 0;
                y1      = (originalImage.Height - height3) / 2;
                break;
            }
            Image    image    = (Image) new Bitmap(width1, height1);
            Graphics graphics = Graphics.FromImage(image);

            graphics.InterpolationMode  = InterpolationMode.High;
            graphics.SmoothingMode      = SmoothingMode.HighQuality;
            graphics.CompositingQuality = CompositingQuality.HighQuality;
            graphics.InterpolationMode  = InterpolationMode.High;
            graphics.Clear(Color.White);
            graphics.DrawImage(originalImage, new Rectangle(x2, y2, width2, height2), new Rectangle(x1, y1, width3, height3), GraphicsUnit.Pixel);
            try
            {
                image.Save(thumbnailPath, ImageHelp.ImgFormat(thumbnailPath));
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                image.Dispose();
                graphics.Dispose();
            }
        }