1. 程式人生 > >將memo轉化為JPG輸出,使用Memo1.PaintTo(Bitmap.Canvas)

將memo轉化為JPG輸出,使用Memo1.PaintTo(Bitmap.Canvas)

ali send sig .text ctr ace rap reat bit

unit unit1;

interface

uses
Windows, Messages, SysUtils, Graphics, Controls, Forms, StdCtrls,
Classes;

type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;

procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var

Form1: TForm1;

implementation
uses jpeg;
{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
vBitmap: TBitmap;
vJpegImage: TJpegImage;
vOldHeight: Integer;
begin
Canvas.Font.Assign(Memo1.Font);
vOldHeight := Memo1.Height;
Memo1.ClientHeight := Canvas.TextHeight(‘|‘) * Memo1.Lines.Count + 2;

vBitmap := TBitmap.Create;
vJpegImage := TJpegImage.Create;
try
vBitmap.Height := Memo1.ClientHeight;
vBitmap.Width := Memo1.ClientWidth;
Memo1.PaintTo(vBitmap.Canvas, -2, -2);
vJpegImage.Assign(vBitmap);
vJpegImage.CompressionQuality := 75;
vJpegImage.Compress;
vJpegImage.SaveToFile(‘輸出.jpg‘);
// Image1.Picture.Graphic := vJpegImage;
finally
vBitmap.Free;
Memo1.Height := vOldHeight;
end;

end;

http://www.cnblogs.com/wxy8/archive/2011/01/13/1934477.html

將memo轉化為JPG輸出,使用Memo1.PaintTo(Bitmap.Canvas)