• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

delphiImage处理

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

procedure ResizeBmp(Src,Dst:String);
var SrcBM,DstBM:TBitMap;
Rect:TRect;
NewW,NewH,PicW,PicH:Integer;
HDivW:Double;
begin
SrcBM:=TBitMap.Create;
SrcBM.LoadFromFile(Src);
PicW:=SrcBM.Width;
PicH:=SrcBM.Height;
NewH:=768;
NewW:=1024;
DstBM:=TBitMap.Create;
with DstBM do begin
Width:=NewW;
Height:=NewH;
Rect.TopLeft:=Point(0,0);
Rect.BottomRight:=Point(NewW,NewH);
Canvas.Rectangle(0,0,Width,Height);
Canvas.StretchDraw(Rect,TGraphic(SrcBM));
SaveToFile(Dst);
FreeImage;
Free;
end;
end;

 

 

 

unit Unit1;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls, System.Math;

type
TForm1 = class(TForm)
img1: TImage;
btn1: TButton;
btn2: TButton;
grp1: TGroupBox;
img2: TImage;
btn3: TButton;
btn4: TButton;
img3: TImage;
btn5: TButton;
procedure btn1Click(Sender: TObject);
procedure btn2Click(Sender: TObject);
procedure btn3Click(Sender: TObject);
procedure btn5Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.btn1Click(Sender: TObject);
var
bmp: TBitmap;
oRect: TRect;
begin
bmp := TBitmap.Create;

bmp.LoadFromFile('D:\12.bmp');
// img1.Picture.LoadFromFile('D:\2.bmp');
// img1.Width := img1.Picture.Width;
// img1.Height := img1.Picture.Height;
// img1.Width := img1.Picture.Width + 50;
// img1.Height := img1.Picture.Height + 50;
// img1.ClientWidth := 200;
// img1.ClientHeight := 200;
oRect.Left := Round((img1.ClientRect.Width - bmp.Width)/2);
oRect.Top := Round((img1.ClientRect.Height - bmp.Height)/2);
oRect.Width := bmp.Width;
oRect.Height:= bmp.Height;
img1.Canvas.StretchDraw(oRect, bmp);
img1.Center := true;
end;

procedure TForm1.btn2Click(Sender: TObject);
begin
img1.Canvas.TextOut(0,0, 'haha');
end;

procedure TForm1.btn3Click(Sender: TObject);
var SrcBM,DstBM:TBitMap;
Rect:TRect;
NewW,NewH,PicW,PicH:Integer;
HDivW:Double;
scale_X, scale_Y: double;
zoom: double;
izoom: Integer;
begin
SrcBM:=TBitMap.Create;
SrcBM.LoadFromFile('D:\12.bmp');
PicW:=SrcBM.Width;
PicH:=SrcBM.Height;
zoom := img2.Width/SrcBM.Width;
NewH:=Round(SrcBM.Height * zoom);
NewW:=Round(SrcBM.Width * zoom);
DstBM:=TBitMap.Create;
with DstBM do
begin
Width:=NewW;
Height:=NewH;
Rect.TopLeft:=Point(0,0);
Rect.BottomRight:=Point(NewW,NewH);
Canvas.Rectangle(0,0,Width,Height);
Canvas.StretchDraw(Rect,TGraphic(SrcBM));
img2.Picture.Bitmap.Assign(DstBM);
img2.Canvas.TextOut(0, 0, '111');
// FreeImage;
// Free;
end;
SrcBM.Free;
DstBM.Free;
end;

{
procedure TForm1.btn3Click(Sender: TObject);
var SrcBM,DstBM:TBitMap;
Rect:TRect;
NewW,NewH,PicW,PicH:Integer;
HDivW:Double;
begin
SrcBM:=TBitMap.Create;
SrcBM.LoadFromFile('D:\12.bmp');
PicW:=SrcBM.Width;
PicH:=SrcBM.Height;
NewH:=100;
NewW:=80;
DstBM:=TBitMap.Create;
with DstBM do
begin
Width:=NewW;
Height:=NewH;
Rect.TopLeft:=Point(0,0);
Rect.BottomRight:=Point(NewW,NewH);
Canvas.Rectangle(0,0,Width,Height);
Canvas.StretchDraw(Rect,TGraphic(SrcBM));
img2.Picture.Bitmap.Assign(DstBM);
img2.Canvas.TextOut(0, 0, '111');
// FreeImage;
// Free;
end;
SrcBM.Free;
DstBM.Free;
end;
}

procedure TForm1.btn5Click(Sender: TObject);
begin
img3.Picture.LoadFromFile('D:\12.bmp');

end;

end.

 

object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 810
ClientWidth = 1035
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object img1: TImage
Left = 32
Top = 24
Width = 105
Height = 105
end
object btn1: TButton
Left = 143
Top = 40
Width = 75
Height = 25
Caption = 'btn1'
TabOrder = 0
OnClick = btn1Click
end
object btn2: TButton
Left = 143
Top = 104
Width = 75
Height = 25
Caption = 'btn2'
TabOrder = 1
OnClick = btn2Click
end
object grp1: TGroupBox
Left = 256
Top = 24
Width = 633
Height = 721
Caption = 'grp1'
TabOrder = 2
object img2: TImage
Left = 80
Top = 48
Width = 105
Height = 105
end
object img3: TImage
Left = 72
Top = 232
Width = 289
Height = 273
end
object btn3: TButton
Left = 264
Top = 40
Width = 75
Height = 25
Caption = 'btn3'
TabOrder = 0
OnClick = btn3Click
end
object btn4: TButton
Left = 264
Top = 104
Width = 75
Height = 25
Caption = 'btn4'
TabOrder = 1
end
object btn5: TButton
Left = 416
Top = 264
Width = 75
Height = 25
Caption = 'btn5'
TabOrder = 2
OnClick = btn5Click
end
end
end


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
matlab画甘特图发布时间:2022-07-18
下一篇:
VC 与Matlab混合编程之引擎操作详解发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap