while printing with Grayscale-Option the Exception EOutOfResources occures because of a very big Bitmap.
Work a round:
- Code: Select all
procedure StretchDrawGrayscale(Canvas: TCanvas; const Rect: TRect; Graphic: TGraphic);
var
Bitmap: TBitmap;
R: TRect;
// new
f: integer;
ok: boolean;
begin
Bitmap := TBitmap.Create;
{ old:
Bitmap.Width := Rect.Right - Rect.Left;
Bitmap.Height := Rect.Bottom - Rect.Top;
}
try
// new
f := 1;
repeat
ok := true;
try
Bitmap.Width := (Rect.Right - Rect.Left) div f;
Bitmap.Height := (Rect.Bottom - Rect.Top) div f;
except
on EOutOfResources do
begin
f := f * 2;
ok := false;
end
else
Raise;
end;
until ok;
// old
SetRect(R, 0, 0, Bitmap.Width, Bitmap.Height);
Bitmap.Canvas.StretchDraw(R, Graphic);
ConvertBitmapToGrayscale(Bitmap);
DrawBitmapAsDIB(Canvas.Handle, Bitmap, Rect);
finally
Bitmap.Free;
end;
end;
Good Work to you all
Edwin



