码迷,mamicode.com
首页 > Windows程序 > 详细

delphi 处理缩放图像

时间:2017-11-09 21:02:57      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:eve   ice   ide   pen   bit   压缩   font   phi   ble   

procedure TTMEImageDeviceIdentifyFrom.DrawText(AImage : TImage; AFile: string);
var
I: Integer;
iWidth, iHeight: Integer;
oInfo: TTextInfoAry;
oRect, Rect: TRect;
bmp, dbmp: TBitmap;
iX, iY: Integer;
zoom: double;
NewW,NewH:Integer;
begin
bmp := TBitmap.Create;
dbmp := TBitmap.Create;
try
bmp.LoadFromFile(AFile);
if (bmp.Width > AImage.Width) or (bmp.Height > AImage.Height) then
begin
if bmp.Width > AImage.Width then
zoom := AImage.Width/bmp.Width
else
zoom := AImage.Height / bmp.Height;
NewH:=Round(bmp.Height * zoom);
NewW:=Round(bmp.Width * zoom);
with dbmp do
begin
Width:=NewW ;
Height:=NewH ;
dbmp.PixelFormat:=pfDevice;
SetStretchBltMode(dbmp.Canvas.Handle,COLORONCOLOR);//设置指位图拉伸模式
stretchblt(dbmp.Canvas.Handle,0,0,dbmp.Width,dbmp.Height,bmp.Canvas.Handle,0,0,bmp.Width,bmp.Height,srccopy); //从源矩形中复制一个位图到目标矩形并适当压缩
// Rect.TopLeft:=Point(0,0);
// Rect.BottomRight:=Point(NewW,NewH);
// Canvas.Rectangle(0,0,Width,Height);
// Canvas.StretchDraw(Rect,TGraphic(bmp));
end;
oRect.Left := Round((AImage.ClientRect.Width - dbmp.Width)/2);
oRect.Top := Round((AImage.ClientRect.Height - dbmp.Height)/2);
oRect.Width := dbmp.Width;
oRect.Height:= dbmp.Height;
AImage.Canvas.StretchDraw(oRect, dbmp);
end
else
begin
oRect.Left := Round((AImage.ClientRect.Width - bmp.Width)/2);
oRect.Top := Round((AImage.ClientRect.Height - bmp.Height)/2);
oRect.Width := bmp.Width;
oRect.Height:= bmp.Height;
AImage.Canvas.StretchDraw(oRect, bmp);
end;

iX := 6;
iY := 0;
AImage.Canvas.Font.Size := 14;
AImage.Canvas.Pen.Style := psClear;
AImage.Canvas.Brush.Style := bsClear;
ParseVectorDrawingText(FSelText, oInfo);
for I := Low(oInfo) to High(oInfo) do
begin
iWidth := AImage.Canvas.TextWidth(oInfo[I].Text);
iHeight := Round(AImage.Canvas.TextHeight(oInfo[I].Text));
oRect.Width := oRect.Width + iWidth;
oRect.Height := oRect.Height + iHeight;
if oRect.Left > iWidth then
oRect.Left := oRect.Left - iWidth;

iY := I * iHeight;
oInfo[I].InstPt.X := iX;
oInfo[I].InstPt.Y := iY ;
end;
for I := Low(oInfo) to High(oInfo) do
AImage.Canvas.TextOut(Round(oInfo[I].InstPt.X), Round(oInfo[I].InstPt.Y), oInfo[I].Text);
finally
bmp.Free;
dbmp.Free;
end;
end;

delphi 处理缩放图像

标签:eve   ice   ide   pen   bit   压缩   font   phi   ble   

原文地址:http://www.cnblogs.com/zhangzhifeng/p/7810980.html

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