码迷,mamicode.com
首页 > 其他好文 > 详细

将memo转化为JPG输出,使用Memo1.PaintTo(Bitmap.Canvas)

时间:2018-01-05 22:34:34      阅读:219      评论:0      收藏:0      [点我收藏+]

标签:paint   html   int   form   ext   map   begin   try   message   

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)

标签:paint   html   int   form   ext   map   begin   try   message   

原文地址:https://www.cnblogs.com/findumars/p/8207058.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!