Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 32059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T13:42:10+00:00 2026-05-10T13:42:10+00:00

Does anyone have the secret formula to resizing transparent images (mainly GIFs) without ANY

  • 0

Does anyone have the secret formula to resizing transparent images (mainly GIFs) without ANY quality loss – what so ever?

I’ve tried a bunch of stuff, the closest I get is not good enough.

Take a look at my main image:

http://www.thewallcompany.dk/test/main.gif

And then the scaled image:

http://www.thewallcompany.dk/test/ScaledImage.gif

//Internal resize for indexed colored images void IndexedRezise(int xSize, int ySize) {   BitmapData sourceData;   BitmapData targetData;    AdjustSizes(ref xSize, ref ySize);    scaledBitmap = new Bitmap(xSize, ySize, bitmap.PixelFormat);   scaledBitmap.Palette = bitmap.Palette;   sourceData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height),     ImageLockMode.ReadOnly, bitmap.PixelFormat);   try   {     targetData = scaledBitmap.LockBits(new Rectangle(0, 0, xSize, ySize),       ImageLockMode.WriteOnly, scaledBitmap.PixelFormat);     try     {       xFactor = (Double)bitmap.Width / (Double)scaledBitmap.Width;       yFactor = (Double)bitmap.Height / (Double)scaledBitmap.Height;       sourceStride = sourceData.Stride;       sourceScan0 = sourceData.Scan0;       int targetStride = targetData.Stride;       System.IntPtr targetScan0 = targetData.Scan0;       unsafe       {         byte* p = (byte*)(void*)targetScan0;         int nOffset = targetStride - scaledBitmap.Width;         int nWidth = scaledBitmap.Width;         for (int y = 0; y < scaledBitmap.Height; ++y)         {           for (int x = 0; x < nWidth; ++x)           {             p[0] = GetSourceByteAt(x, y);             ++p;           }           p += nOffset;         }       }     }     finally     {       scaledBitmap.UnlockBits(targetData);     }   }   finally   {     bitmap.UnlockBits(sourceData);   } } 

I’m using the above code, to do the indexed resizing.

Does anyone have improvement ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T13:42:10+00:00Added an answer on May 10, 2026 at 1:42 pm

    If there’s no requirement on preserving file type after scaling I’d recommend the following approach.

    using (Image src = Image.FromFile('main.gif')) using (Bitmap dst = new Bitmap(100, 129)) using (Graphics g = Graphics.FromImage(dst)) {    g.SmoothingMode = SmoothingMode.AntiAlias;    g.InterpolationMode = InterpolationMode.HighQualityBicubic;    g.DrawImage(src, 0, 0, dst.Width, dst.Height);    dst.Save('scale.png', ImageFormat.Png); } 

    The result will have really nice anti aliased edges

    • removed image shack image that had been replaced by an advert

    If you must export the image in gif you’re in for a ride; GDI+ doesn’t play well with gif. See this blog post about it for more information

    Edit: I forgot to dispose of the bitmaps in the example; it’s been corrected

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 74k
  • Answers 74k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Add this to div.right margin-left: 51px; May 11, 2026 at 2:14 pm
  • added an answer Have you looked in to Templating the ListBoxItem Use this… May 11, 2026 at 2:14 pm
  • added an answer Fastest in terms of simplest? Assuming .NET 3.5 (and thus… May 11, 2026 at 2:14 pm

Related Questions

Does anyone have experience using the URL Rewrite Module (see here )? Can it
Does anyone have metrics on the utility of formal Unit Testing? I see a
Does anyone have any information about getting the current versions of ASP.NET MVC (Preview
Does anyone have any experience hosting the Windows Workflow designer surface? I've seen a
I'm trying to test a method I have in my application, but I don't
Does anyone know if there's a way to automatically expand a list in Python,
Does anyone have an idea why the ampersand was chosen as the way to
Does anyone have any examples or resources where i might find information on scrolling

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.