Results 1 to 7 of 7

Thread: how can I edit a gif file? CONFUSED AGAIN!

  1. #1

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    how can I edit a gif file? CONFUSED AGAIN!

    Well I can edit JPG files perfectly fine, but I tried a GIF file and I get this error:
    A Graphics object cannot be created from an image that has an indexed pixel format.
    I'm obviously trying to create a graphics object from the GIF image.

    I've tried loading the GIF by using both of these methods:
    dim img as image = image.fromfile(gifFile)
    dim bmp as new bitmap(gifFile)

    both will result the same. I'm wondering how I can "convert" the indexed format to a normal image so it can be edited with the Graphics class. There should certainly be a way, but I'm clueless
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  2. #2
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    try this link from the Microsoft Knowledge Base...
    HOW TO: Save a .gif File with a New Color Table By Using Visual Basic .NET
    hope it helps
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  3. #3

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    Originally posted by dynamic_sysop
    try this link from the Microsoft Knowledge Base...
    HOW TO: Save a .gif File with a New Color Table By Using Visual Basic .NET
    hope it helps
    hmm I havent read that yet, but.... does this happen only with GIF files? can I just load and edit any other file types that .NET supports?
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  4. #4
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    as far as i'm aware it's only Gif's that cause a problem , they have an indexing system and also it's something about the amount of colours, this is why you must specify " PixelFormat.Format8BPPIndexed " when making the new bitmap of the gif. eg:
    VB Code:
    1. Dim bitmap As Bitmap = New Bitmap(Width, Height, PixelFormat.Format8BppIndexed)
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  5. #5

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    aah I cant get this to work. That article seems to be about SAVING a GIF file correctly. What I want it to be able to load the GIF and edit it with Graphics....
    I tried doing this, but it wont work:

    I locked the GIF as PixelFormat.Format8bppIndexed and created a bitmap and locked it with PixelFormat.Format24bppRgb. I tried copying every pixel of the GIF to the BMP file, but the result is a somewhat black and white image messed up... I dont know what I should do
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  6. #6

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    bump
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  7. #7

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    hehe this seems to work
    VB Code:
    1. public static Bitmap ConvertFromIndexedFormat(Image img)
    2.         {
    3.             Bitmap bmp = new Bitmap(img.Width, img.Height);
    4.             Graphics gr = Graphics.FromImage(bmp);
    5.             gr.DrawImage (img, 0,0);
    6.             return bmp;
    7.         }
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width