C # proportional scaling, compression of gif and animation files

Source: Internet
Author: User

// Source image path string imgPath = Environment. getFolderPath (Environment. specialFolder. desktop) + @ "\ 0.gif"; // source Image img = Image. fromFile (imgPath); // if (img. width> 100 & img. height> 100) {// the first frame of the new Image, Image new_img = new Bitmap (100,100); // other frames of the new Image, Image new_imgs = new Bitmap (100,100 ); // The first frame of the new graph, GDI + Drawing Object, Graphics g_new_img = Graphics. fromImage (new_img); // New Graph other frames GDI + Drawing Object Graphics g_new_imgs = Graphics. fromImage (new_imgs); // configure the first frame of the new graph, GDI + Drawing Object g_new_img.CompositingMode = CompositingMode. sourceCopy; g_new_img.InterpolationMode = InterpolationMode. highQualityBicubic; g_new_img.PixelOffsetMode = PixelOffsetMode. highQuality; g_new_img.SmoothingMode = SmoothingMode. highQuality; g_new_img.Clear (Color. fromKnownColor (KnownColor. transparent); // configure other frames. GDI + Drawing Object g_new_imgs.CompositingMode = CompositingMode. sourceCopy; g_new_imgs.InterpolationMode = InterpolationMode. highQualityBicubic; g_new_imgs.PixelOffsetMode = PixelOffsetMode. highQuality; g_new_imgs.SmoothingMode = SmoothingMode. highQuality; g_new_imgs.Clear (Color. fromKnownColor (KnownColor. transparent); // traverse the dimension foreach (Guid gid in img. frameDimensionsList) {// because the GIF file is reduced, set it to Time. // if it is TIFF, set it to PAGE FrameDimension f = FrameDimension. time; // get the total number of frames int count = img. getFrameCount (f); // Save the parameter Encoder encoder = Encoder. saveFlag; // EncoderParameters ep = null; // image encoding and decoder ImageCodecInfo ici = null; // image encoding and decoder set ImageCodecInfo [] icis = ImageCodecInfo. getImageDecoders (); // assign foreach (ImageCodecInfo ic in icis) {if (ic. formatID = ImageFormat. gif. guid) {ici = ic; break ;}// for each frame (int c = 0; c <count; c ++) {// select the frame img specified by the dimension and index. selectActiveFrame (f, c); // the first frame if (c = 0) {// draw the first frame of the source image to the first frame of the new image g_new_img.DrawImage (img, new Rectangle (0, 0,100,100), new Rectangle (0, 0, img. width, img. height), GraphicsUnit. pixel); // copy the vibrator and transparent background palette to the first frame of the new image (int I = 0; I 

// Effect

100*100

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.