TPrintPreview StretchDrawGrayscale Exception EOutOfResources

Please post bug reports, feature requests, or any question regarding the DELPHI AREA projects here.

TPrintPreview StretchDrawGrayscale Exception EOutOfResources

Postby EPusch » October 13th, 2008, 9:39 am

Hi,

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
EPusch
Member
Member
 
Posts: 1
Joined: October 13th, 2008, 9:29 am
Location: Germany

Postby Kambiz » October 13th, 2008, 1:30 pm

Hi Edwin,

Thanks for the fix. I'll include it in the next release.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm


Return to DELPHI AREA Projects

Who is online

Users browsing this forum: No registered users and 2 guests

cron