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

  • SEARCH
  • Home
  • 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 428201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:39:08+00:00 2026-05-12T19:39:08+00:00

Working in Visual Studio 2008. I’m trying to draw on a PNG image and

  • 0

Working in Visual Studio 2008. I’m trying to draw on a PNG image and save that image again.

I do the following:

private Image img = Image.FromFile("file.png");
private Graphics newGraphics;

And in the constructor:

newGraphics = Graphics.FromImage(img);

Building the solution gives no errors. When I try to run it, I get this:

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

I don’t have much experience with using images in C#. What does this mean and how can I remedy this?

EDIT: through debugging, Visual Studio tells me that the image has a format8bppindexed Pixel Format.

So if I can’t use the Graphics class, what do I use?

EDIT2: After reading this, I think it’s safe to assume that I better stick to JPG files when working with GDI+, no?

EDIT3: my using-statements:

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
  • 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. Editorial Team
    Editorial Team
    2026-05-12T19:39:08+00:00Added an answer on May 12, 2026 at 7:39 pm

    Without a better PNG library that supports indexed PNGs you’re out of luck trying to draw to that image since evidently the GDI+ graphics object doesn’t support indexed images.

    If you don’t need to use indexed PNGs you could trap that error and convert your input to regular RGB PNGs using a 3rd party utility.

    edit:

    I did find this link http://fci-h.blogspot.com/2008/02/c-indexed-pixel-problem.html that gives a method to draw on your image, however it won’t affect the original, just a copy you can Save() if you require.

    In case the link goes down:

    Bitmap bm = (Bitmap) System.Drawing.Image.FromFile("Fci-h.jpg",true);
    Bitmap tmp=new Bitmap (bm.Width ,bm.Height );
    Graphics grPhoto = Graphics.FromImage(tmp);
    grPhoto.DrawImage(bm, new Rectangle(0, 0, tmp.Width , tmp.Height ), 0, 0, tmp.Width , tmp.Height , GraphicsUnit.Pixel);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a Visual Studio 2008 project that is already added to
I am working in Visual Studio 2008 on an ASP.NET application, which has been
For example if I'm working on Visual Studio 2008, I want the values devenv
I'm coming from Eclipse, working in Visual Studio 2008 Express and just want to
I am working with a Visual Studio 2008 (C#) project on Windows XP Pro.
We're working on a project here in Visual Studio 2008. We're using the built-in
I am working on a large C++ project in Visual Studio 2008, and there
I am working with an n-tiered architecture in Visual Studio 2008 (Developer Edition), and
I´m working on a project, in Visual Studio 2008, which DLL currently surpasses 20
When working with Visual Studio and adding a reference to a project you are

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.