DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3

Thread: Gif Resizing

  1. #1
    Join Date
    Feb 2007
    Posts
    3

    Gif Resizing

    Hi, I am trying to resize a gif image I have on my server, and then stream it to the browser. (.net 2.0 & C#)

    Unfortunately, the gif gets a bit distorted. I 've read a lot of walkthroughs, the dgi+ palette, etc etc but still haven't done it yet.

    I have no problem using a third party component as long as its price is reasonable, and maybe the option to also edit multi-frame gifs.

    Let me give you a small clue of what I've written so far:

    void ServeTheImage(string fileName, string downloadExtension, int iWidth, int iHeight)
    {
    int original_width = 0;
    int original_height = 0;

    string WorkingDirectory = "/mw/";
    string fullfilename = WorkingDirectory + fileName;

    // create New image and bitmap objects. Load the image file and put into a resized bitmap.
    System.Drawing.Image myImage = System.Drawing.Image.FromFile(Server.MapPath(fullfilename));

    original_width = myImage.Width;
    original_height = myImage.Height;

    fixWidthHeight(ref original_width, ref original_height, ref iWidth, ref iHeight);


    Bitmap b = Bitmap(iWidth, iHeight, PixelFormat.Format24bppRgb);

    Graphics g = Graphics.FromImage(b);

    g.DrawImage(myImage, Rectangle(0, 0, 234, 30), Rectangle(0, 0, iWidth, iHeight), GraphicsUnit.Pixel);

    b.Save(Server.MapPath("pics/NewAnimatedGif.gif"));

    System.Drawing.Image.GetThumbnailImageAbort dummyCallBack = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);

    System.Drawing.Image thumbNailImg = myImage.GetThumbnailImage(iWidth, iHeight, dummyCallBack, IntPtr.Zero);

    Response.Clear();
    Response.ContentType = "image/gif";

    thumbNailImg.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);
    }

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Feb 2007
    Posts
    3
    I have dtried to use the drawing classes but it seems they only work for jpeg.

    For gif I get this:

    A Graphics object cannot be created from an image that has an indexed pixel format.

    Maybe a component would do better and easiest job?

Similar Threads

  1. Resizing Program Window
    By jobartley515 in forum VB Classic
    Replies: 2
    Last Post: 10-03-2005, 12:01 AM
  2. Trouble buffering transparent gif
    By axlan in forum Java
    Replies: 2
    Last Post: 06-22-2005, 08:21 AM
  3. Replies: 0
    Last Post: 02-18-2002, 03:34 PM
  4. Stop gif from cacheing
    By Reg Ripperger in forum Web
    Replies: 0
    Last Post: 07-30-2001, 10:33 AM
  5. Acme Gif Encoder Problem
    By Vikram in forum Java
    Replies: 0
    Last Post: 07-22-2000, 04:02 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links