1,183
社区成员
发帖
与我相关
我的任务
分享
procedure TForm1.Button1Click(Sender: TObject);
var
bmp1,bmp2:TBitmap;
SrcR,DesR:TRect;
x,y:Integer;
begin
bmp1:=TBitmap.Create;
bmp2:=Tbitmap.Create;
Try
bmp1.LoadFromFile('e:\test.bmp');
x:=bmp1.Width;
y:=bmp1.Height;
SrcR:=Rect(0,0,x,y);
DesR:=Rect(x,0,0,y);
bmp2.Width:=x;
bmp2.Height:=y;
bmp2.Canvas.CopyRect(DesR,bmp1.Canvas,SrcR);
canvas.Draw(0,0,bmp2); //将反转后的图像画在窗体上
Finally
bmp1.Free;
bmp2.Free;
end;
end;
水平镜像
var
I,J :integer;
p,p1 :PByteArray;
Bmp,Bmp1 :TBitmap;
begin
Bmp :=TBitmap.Create;
Bmp.Assign(Image1.Picture.Bitmap);
Bmp1 :=TBitmap.Create ;
Bmp1.Assign(Image1.Picture.Bitmap);
for J :=0 to Bmp.Height-1 do
begin
p :=Bmp.ScanLine[J];
P1 :=Bmp1.ScanLine[J];
for I :=0 to Bmp.Width-1 do
begin
p1[3*(Bmp.Width-1-I)+2] :=p[3*I+2];
p1[3*(Bmp.Width-1-I)+1] :=p[3*I+1];
p1[3*(Bmp.Width-1-I)] :=p[3*I];
end;
end;
Bmp1.SaveToFile('c:\1.bmp');
Image1.Picture.Bitmap.Assign(Bmp1);
end;
procedure VertMirror(pBitMap:TBitmap);
var
bmp1: TBitmap;
j: integer;
p, p1: pByteArray;
begin
bmp1 := TBitmap.create;
bmp1.assign(pBitMap);
bmp1.PixelFormat := pf24bit;
for j := 0 to pBitMap.Height - 1 do
begin
p := pBitMap.ScanLine[j];
p1 := Bmp1.ScanLine[pBitMap.Height - 1 - j];
for i := 0 to pBitMap.Width - 1 do
begin
p[3 * i] := p1[3 * i];
p[3 * i + 1] := p1[3 * i + 1];
p[3 * i + 2] := p1[3 * i + 2];
end;
end;
Form1.Image1.picture.bitmap.Assign(pBitMap);
bmp1.free;
end;
//***********************************************************
//功能:任意角度旋转
//参数:Srcbmp:源位图 DestBmp:目标位图 ;angle旋转角度
//返回值:无
class procedure TGraphicUtil.Rotate(Srcbmp, DestBmp: Tbitmap;
angle: extended);
var
c1x, c1y, c2x, c2y: integer;
p1x, p1y, p2x, p2y: integer;
radius, n: integer;
alpha: extended;
c0, c1, c2, c3: tcolor;
begin
if SrcBmp.Width > SrcBmp.Height then
begin
DestBmp.width := SrcBmp.Width;
DestBmp.height := SrcBmp.Width;
end
else
DestBmp.Width := SrcBmp.Height;
DestBmp.Height := SrcBmp.Height;
//将角度转换为PI值
angle := (angle / 180) * pi;
// 计算中心点,你可以修改它
c1x := SrcBmp.width div 2;
c1y := SrcBmp.height div 2;
c2x := DestBmp.width div 2;
c2y := DestBmp.height div 2;
// 步骤数值number
if c2x < c2y then
n := c2y
else
n := c2x;
dec(n, 1);
// 开始旋转
for p2x := 0 to n do
begin
for p2y := 0 to n do
begin
if p2x = 0 then
alpha := pi / 2
else
alpha := arctan2(p2y, p2x);
radius := round(sqrt((p2x * p2x) + (p2y * p2y)));
p1x := round(radius * cos(angle + alpha));
p1y := round(radius * sin(angle + alpha));
c0 := SrcBmp.canvas.pixels[c1x + p1x, c1y + p1y];
c1 := SrcBmp.canvas.pixels[c1x - p1x, c1y - p1y];
c2 := SrcBmp.canvas.pixels[c1x + p1y, c1y - p1x];
c3 := SrcBmp.canvas.pixels[c1x - p1y, c1y + p1x];
DestBmp.Canvas.pixels[c2x + p2x, c2y + p2y] := c0;
DestBmp.canvas.pixels[c2x - p2x, c2y - p2y] := c1;
DestBmp.canvas.pixels[c2x + p2y, c2y - p2x] := c2;
DestBmp.canvas.pixels[c2x - p2y, c2y + p2x] := c3;
end;
application.processmessages
end;
end;
//***********************************************************