ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 How to convert function to use TIEBitmap
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

AndyColmes

USA
351 Posts

Posted - Oct 04 2018 :  16:29:33  Show Profile  Reply
I have this function but it uses TBitmap. I tried changing it to TIEBitmap but it gives an error in the Palette:

procedure SetBitmap8bitPalette(const Palette: T8bitPaletteArray; Bitmap: TBitmap);
// Add a 256-color palette to a bitmap
var
i, y: integer;
pal: PLogPalette;
hpal: HPALETTE;
begin
if not assigned(Bitmap) then exit;
// 8 bits per pixel
Bitmap.PixelFormat := pf8bit;

// Create a gradient palette between foreground and background color
GetMem(pal, sizeof(TLogPalette) + sizeof(TPaletteEntry) * 256);
try
pal.palVersion := $300;
pal.palNumEntries := 256;
for i := 0 to 255 do begin
pal.palPalEntry[i].peRed := Palette[i].R;
pal.palPalEntry[i].peGreen := Palette[i].G;
pal.palPalEntry[i].peBlue := Palette[i].B;
end;
hpal := CreatePalette(pal^);
if hpal <> 0 then
Bitmap.Palette := hpal; <--- Error!
finally
FreeMem(pal);
end;

// Fill bitmap with background color
for y := 0 to Bitmap.Height - 1 do
FillChar(Bitmap.Scanline[y]^, Bitmap.Width, 0);
end;

I appreciate any help you can offer. Thank you in advance.

Andy

xequte

39053 Posts

Posted - Oct 04 2018 :  20:11:24  Show Profile  Reply
Hi Andy

Firstly, have you considered just using the built in ImageEn methods for this:

https://www.imageen.com/help/TImageEnProc.ConvertTo.html


Nigel
Xequte Software
www.imageen.com
Go to Top of Page

AndyColmes

USA
351 Posts

Posted - Oct 04 2018 :  23:13:24  Show Profile  Reply
Hi Nigel,

Thanks for the info. What would be the values to use the ConvertTo function to do what the SetBitmap8bitPalette does?

Thanks again.

Andy
Go to Top of Page

AndyColmes

USA
351 Posts

Posted - Oct 04 2018 :  23:40:07  Show Profile  Reply
Right now, I have to create a TBitmap, run SetBitmap8bitPalette on it and then assign it to a TIEBitmap which I think increases overhead and gives "not enough storage" memory error when dealing with large images
Go to Top of Page

xequte

39053 Posts

Posted - Oct 05 2018 :  00:30:35  Show Profile  Reply
Hi Andy

The third overload accepts Palette as an array of TRGB:


function ConvertTo(PixelFormat: TIEPixelFormat; Palette: array of TRGB; DitherType: TIEDitherType = iedtSolid; CheckParametersOnly: boolean = false): boolean; overload;

So you can assign your TBitmap to a TIEBitmap, convert your T8bitPaletteArray to an array of TRGB then call:

ImageEnView1.Proc.ConvertTo(ie8p, MYPALETTE, iedtErrorDiffusion);
ImageEnView1.IO.Params.BitsPerSample := 8;
ImageEnView1.IO.Params.SamplesPerPixel := 1;

If you just want a general 256 color palette, use:

ImageEnView1.Proc.ConvertTo(256);

Nigel
Xequte Software
www.imageen.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: