Bitmap

Hello
How to change a bitmap bits.
if I have an picture 24bit and I wont to make it 8bit and save to the hard dick.
ILPowerSoftAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

karooCommented:
listening:)
0
men xinCEOCommented:
var a:Tbitmap;
begin
  a:=TBitmap.Create;
  a.LoadFromFile('c:\a.bmp');
  a.PixelFormat:=pf8bit;//convert to 8bit
  a.SaveToFile('c:\b.bmp');
  a.free;
end;

then b.bmp is a 256 colors bitmap.

menxin
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
simonetCommented:
Menxin,

While this is the "easy" way, you rarely get the "right" palette out of this approach.  Neither Windows nor Delphi does anything to make sure you have the "right" palette.  Since a pf24bit image can have thousands (even 100,000s) of colors, finding the "best" 236 colors for the palette is the hard part of this problem.

then you ask: But what about the other 20 (20 + 236 = 256) colors? Well, 20 colors are reserved for Windows' defalt palette and cannot be changed to a custom pallete.

Alex




0
kretzschmarCommented:
hi all

best result by colorreduction is with use of the jpeg-unit (jpegimage), because there is also a dithering included.

you can do it like in this code part


  MyBmp := TBitmap.Create;
  MyJPG := TJpegImage.Create;
  M := TMemoryStream.Create;
  try
    MyBmp.LoadFromFile(OpenPictureDialog1.Filename);
    MyJPG.Assign(MyBmp);
    MyJpg.SaveToStream(M);
    M.Position := 0;
    MyJpg.PixelFormat := jf8Bit;  //reduce colordepth to 8 Bit
    MyJpg.LoadFromStream(M);      //Best result if done over JPG-Object
    Image1.Picture.Bitmap.Assign(MyJPG);  //here is now the reduced bitmap
  finally
    MyBmp.Free;
    MyJpg.Free;
    M.Free;
  end;

meikl
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Fonts Typography

From novice to tech pro — start learning today.