Processing large images with Delphi to save as .jpeg

In Delphi 7, I have a library that uses the TCanvas component to output some information. The resulting image is about 4800 * 6000 pixels, and I would like to print it and save it as .jpeg.

To achieve this, I created TBitmap and passed it Canvas as a parameter to the library, and then assigned the jpeg bitmap. Apparently, this takes up too much memory, because I get an exception when I try to set the width and height of the bitmap, saying: "There is not enough memory to process this command."

// output to printer
Printer.BeginDoc();
doPrint(Printer.Canvas);
Printer.EndDoc();

// output in bmp.Canvas
bmp := TBitmap.Create;
bmp.Width := Printer.PageWidth;
bmp.Height := Printer.PageHeight; // <- BAM! Exception!
doPrint(bmp.Canvas);

// save as jpeg
jpg := TJPEGImage.Create;
jpg.Assign(bmp);
jpg.SaveToFile('...');

// free
bmp.Free();
jpg.Free();

What am I doing wrong? Can I save Printer.Canvas directly as a file .jpeg?

: 2000 * 2000 4800 * 6000

+3
10

TBitmap32 Graphic32 (http://www.graphics32.org/wiki/)

+3

pixelformat bmp -, bmp, . .

+2

, , . , Device Independent :

bmp := TBitmap.Create;
bmp.HandleType := bmDIB;
bmp.Width := Printer.PageWidth;
bmp.Height := Printer.PageHeight; 

, . , . , Delphi RAM .

+1

Delphi TBitmap . , TCanvas .jpg.

0

(Windows XP, Delphi 2006) . ?

  procedure TForm3.Button3Click(Sender: TObject);
  var
     bmp : TBitmap;
  begin
     bmp := TBitmap.Create;
     bmp.PixelFormat := pf32bit;
     bmp.Width := 6000;
     bmp.Height := 4800;
     bmp.Free;
  end;
0

mghie: . EFG

0

PixelFormat pf32bit pf24bit (, , Ben Ziegler), PixelFormat ( , XP). .

0

JPEG: 32767x32767 .

TCanvas, Windows.

NativeJpg JPEG , , , JPEG, "strip by strip", .

NativeJpg , : http://www.simdesign.nl/forum/viewforum.php?f=16

tiledemo, , JPEG.

,

0

To consume less memory, you can always try creating small bitmaps. let's say you divide the height of the printer by 10 or set the maximum height to 1000. Just a suggestion, not sure if it applies in your case. This results in more than one image per page.

0
source

Not sure if this will work or help. But we created a function that will save the component in jpeg:

    function SaveComponentToJPeg(mControl: TWinControl): TJpegImage;
    var
      bmp: TPicture;
      jpg : TJpegImage;
      dc: HDC;
      wnd: HWND;
      Params: array[0..255] of Char;

    begin
      bmp:=TPicture.Create;
      jpg := TJpegImage.create;
      try
        bmp.Bitmap.Width  := mControl.Width  - 05;  // Deduct for border.
        bmp.Bitmap.Height := mControl.Height -05;  // Deduct for border.
        wnd               := mControl.Handle;  //ctiveWindow;
        dc                := GetDc(wnd);
        BitBlt(bmp.Bitmap.Canvas.Handle,0,0,bmp.Width,bmp.Height,dc,0,0,SrcCopy);
        ReleaseDc(wnd, dc);
        jpg.assign(bmp.bitmap);
        result := jpg
      finally
        bmp.Free;
      end;
    end;
-1
source

Source: https://habr.com/ru/post/1721333/


All Articles