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 3722490
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T05:55:25+00:00 2026-05-19T05:55:25+00:00

I need to process and save images in their original bpp (1 – for

  • 0

I need to process and save images in their original bpp (1 – for BnW, 8 – for gray, 24 – color).
After processing I always have 24bpp (due to processing with Aforge.Net). I pass original bpp to saving function and I’m using the next code for saving:

private static Bitmap changePixelFormat(Bitmap input, PixelFormat format)
    {
        Bitmap retval = new Bitmap(input.Width, input.Height, format);
        retval.SetResolution(input.HorizontalResolution, input.VerticalResolution);
        Graphics g = Graphics.FromImage(retval);
        g.DrawImage(input, 0, 0);
        g.Dispose();
        return retval;
    }

When I pass:

PixelFormat.Format8bppIndexed

I’m getting an exception: “Graphics object can’t create image in indexed pixel format” in the line:

Graphics g = Graphics.FromImage(retval);

I’ve tried the next code:

Bitmap s = new Bitmap("gray.jpg");
        Bitmap NewPicture = s.Clone(new Rectangle(0, 0, s.Width, s.Height),                   PixelFormat.Format8bppIndexed);

After this “NewImage” has PixelFormat 8bppIndexed, but when I’m saving NewImage:

NewPicture.Save("hello.jpg", ImageFormat.Jpeg);

hello.jpg has 24bpp.

I need to keep bpp and image format of original image.

Why Bitmap.Save ignores PixelFormat of Bitmap?

=======================================================

Thanks guys, I’ve found a solution:
http://freeimage.sourceforge.net/license.html

With help of this free library it is possible to save images (especially JPEG ) to Grayscale 8-bit.

  • 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-19T05:55:26+00:00Added an answer on May 19, 2026 at 5:55 am

    Here is the code that will convert a Bitmap to 1bpp/8bpp bitmap. 1bpp/8bpp in C#.

    In your changePixelFormat method you can check what fixel format it needs to be converted to, then if it’s 1bpp or 8 bpp then use code from link and for all other formats use your code.

    Graphics.FromImage documentation has remarks:

    If the image has an indexed pixel
    format, this method throws an
    exception with the message, “A
    Graphics object cannot be created from
    an image that has an indexed pixel
    format.” The indexed pixel formats are
    shown in the following list.

    Format1bppIndexed

    Format4bppIndexed

    Format8bppIndexed

    NEW PART:

    This is what i found after short googling:

    8bpp greyscale images and 8bpp jpg is not supported with gdiplus version
    1.0. There is a new version of gdiplus in Windows 7 that supports greyscale
    images and more enhanced codec support.

    8bpp indexed jpeg images are supported with
    Microsoft’s WIC API.

    You can try it yourself by downloading the WIC explorer from Microsoft’s
    download site.

    GDI+ 8 bit load/save bug

    Standard JPEG only supports 24-bit image.

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

Sidebar

Related Questions

I have a big problem, I need to save an AJAXed ordered list as
I have a program which executes constantly and I need to save data every
As part of my build process I need to convert a number of XCF
I'm developing an NPAPI plugin for Mac OS X, and need an Open/Save dialog
I have a large 1D dynamic array in my program that represents a FITS
I'm trying to understand the android:process attribute. Ref says : If the name assigned
I am working on a android app and I have an EditText where user
I need to install PEAR on a shared server & was reading this page:
My application has a photobooth feature which will allow the user to take a
As I understand it, the build method can be used to build up a

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.