Hi Nigel,
This is a sample file that is causing the issue. It is a big file. Basically, I wrote this function to remove the gray and highlight whites and blacks. This function works fine for small images but with large images, it gives out of memory. Is there a way to make this function work for large images?
Thanks Nigel. I appreciate any help you can offer.
Files:
https://mega.nz/#!TII2AJ5I!Tai-CJUCbplBgNmMfDf9gJgTs91r7agXuU3SuliqvfY
Calling:
DoColorizeMap2( 'FCS1.bmp', 'FCS2.bmp', 'outfile.png', True, 1 );
procedure TForm3.DoColorizeMap2( tmpStandard, tmpDefect, tmpOutput: string; colorized: Boolean; clrmode: Integer );
var
VTemp: TImageEnVect;
beginDiffColor: TColor;
endDiffColor: TColor;
beginMissColor: TColor;
endMissColor: TColor;
newColor: TColor;
w: Integer;
h: Integer;
map: array [0..255] of TRGB;
i: Integer;
ImgProc: TImageEnProc;
Bmp: TIEBitmap;
begin
beginDiffColor := $00525252;
endDiffColor := $00989898;
beginMissColor := $00010101;
endMissColor := $00090909;
newColor := clWhite;
try
Bmp := TIEBitmap.Create( tmpDefect );
Bmp.Location := ieFile;
// Make current bitmap use file storage if image is larger than 1MB
Bmp.MinFileSize := 1 * 1024 * 1024;
ImgProc := TImageEnProc.Create( Self );
ImgProc.AttachedIEBitmap := Bmp;
try
ImgProc.CastColorRange(TColor2TRGB(beginDiffColor), TColor2TRGB(endDiffColor), TColor2TRGB(newColor));
ImgProc.SetTransparentColors(TColor2TRGB(clWhite), TColor2TRGB(clWhite), 0);
ImgProc.CastColorRange(TColor2TRGB(beginMissColor), TColor2TRGB(endMissColor), TColor2TRGB(clGray));
ImgProc.Update;
if (colorized = True) then begin
if (clrmode = 0) then begin
//Method 1
ImgProc.Colorize(40, 50, 1.1);
end else if (clrmode = 1) then begin
//Method 2
for i := 0 to 255 do begin
map[i].r := i;
map[i].g := 255-i;
map[i].b := i;
end;
ImgProc.MapGrayToColor(map);
end;
ImgProc.Update;
end;
w := Bmp.Width;
h := Bmp.Height;
finally
Bmp.Write( tmpOutput );
FreeAndNil( ImgProc );
FreeAndNil( Bmp );
end;
except
on E : Exception do
ShowMessage(E.ClassName+' error raised, with message : '+E.Message);
end;
end;