VoyForums
[ Show ]
Support VoyForums
[ Shrink ]
VoyForums Announcement: Programming and providing support for this service has been a labor of love since 1997. We are one of the few services online who values our users' privacy, and have never sold your information. We have even fought hard to defend your privacy in legal cases; however, we've done it with almost no financial support -- paying out of pocket to continue providing the service. Due to the issues imposed on us by advertisers, we also stopped hosting most ads on the forums many years ago. We hope you appreciate our efforts.

Show your support by donating any amount. (Note: We are still technically a for-profit company, so your contribution is not tax-deductible.) PayPal Acct: Feedback:

Donate to VoyForums (PayPal):

Login ] [ Contact Forum Admin ] [ Main index ] [ Post a new message ] [ Search | Check update time | Archives: 1234567[8]910 ]


[ Next Thread | Previous Thread | Next Message | Previous Message ]

Date Posted: 07:30:26 01/03/01 Wed
Author: Michel
Subject: Re: Draw in bitmap - 256 color palette
In reply to: Poul Halgaard 's message, "Draw in bitmap - 256 color palette" on 15:34:50 01/02/01 Tue


Dear Poul,

I would use a TBitmapGraphic instead of a TBitmap to do the conversion. For example,

var

Bitmap24, Bitmap8 : TBitmapGraphic

begin
Bitmap24 := TBitmapGraphic.Create;
Bitmap8 := TBitmapGraphic.Create;
ImageFormatTransform := TImageFormatTransform.Create;

Bitmap24.LoadFromFile( 'c:\24bit.bmp' );

ImageFormatTransform.ImageFormat := ifColor256;
ImageFormatTransform.Quantize := true;
ImageFormatTransform.Dither := true;
ImageFormatTransform.ApplyOnDest(Bitmap24, Bitmap8);

Bitmap8.SaveToFile( 'c:\8bit.bmp' );

ImageFormatTransform.Free;
Bitmap8.Free;
Bitmap24.Free;

end;

Best regards,

Michel

>I want to convert a 24 bit image to 8 bit and assign the result to a bitmap. Why does this code not work? The colors are messed up, no matter what I try. How should it be done? <BR>
><BR>
>var<BR>
> ABitmap: TBitmap;<BR>
> ADibGfx: TDibGraphic;<BR>
> AImageFormatTransform: TImageFormatTransform;<BR>
>begin<BR>
> ABitmap := TBitmap.Create;<BR>
> try<BR>
> ABitmap.LoadFromFile('c:\24bit.bmp');<BR>
> ADibGfx := TDibGraphic.Create;<BR>
> try<BR>
> ADibGfx.Assign(ABitmap);<BR>
><BR>
> AImageFormatTransform := TImageFormatTransform.Create;<BR>
> try<BR>
> AImageFormatTransform.ImageFormat := ifColor256;<BR>
> AImageFormatTransform.Quantize := true;<BR>
> AImageFormatTransform.Dither := true;<BR>
> AImageFormatTransform.Apply(ADibGfx);<BR>
> finally<BR>
> AImageFormatTransform.Free;<BR>
> end;<BR>
><BR>
> ABitmap.PixelFormat := pf8bit;<BR>
> ABitmap.Palette := ADibGfx.PaletteHandle;<BR>
><BR>
> ADibGfx.Draw(<BR>
> ABitmap.Canvas,<BR>
> Rect(<BR>
> 0, 0,<BR>
> ADibGfx.Width,<BR>
> ADibGfx.Height));<BR>
><BR>
> ABitmap.SaveToFile('c:\8bit.bmp');<BR>
><BR>
> finally<BR>
> ADibGfx.Free;<BR>
> end;<BR>
> finally<BR>
> ABitmap.Free;<BR>
> end;<BR>
>end;<BR>

[ Next Thread | Previous Thread | Next Message | Previous Message ]


Replies:


[ Contact Forum Admin ]


Forum timezone: GMT-5
VF Version: 3.00b, ConfDB:
Before posting please read our privacy policy.
VoyForums(tm) is a Free Service from Voyager Info-Systems.
Copyright © 1998-2019 Voyager Info-Systems. All Rights Reserved.