1,183
社区成员
发帖
与我相关
我的任务
分享
uses jpeg;
function RotateJPG90(AJPG:TJPEGImage):TBitmap;//顺时针90
var
bmp:TBitmap;
p,pBuf:PChar;
w,h,y,x,LineSize,nOfs:Integer;
begin
bmp:=TBitmap.Create;
bmp.PixelFormat:=pf24bit;
bmp.Assign(AJPG);
w:=bmp.Width;
h:=bmp.Height;
LineSize:=w*3;
GetMem(pBuf,LineSize*h);
try
for y:=0 to bmp.Height-1 do
begin
p:=bmp.ScanLine[y];
for x:=0 to bmp.Width-1 do
begin
nOfs:=(x*h+h-y-1)*3;
Move(p^,pBuf[nOfs],3);
Inc(p,3);
end;
end;
bmp.Width:=h;
bmp.Height:=w;
LineSize:=h*3;
for y:=0 to bmp.Height-1 do
begin
nOfs:=y*LineSize;
Move(pBuf[nOfs],bmp.scanline[y]^,LineSize);
end;
result:=bmp;
finally
FreeMem(pBuf);
end;
end;
function RotateJPG270(AJPG:TJPEGImage):TBitmap;//顺时针270
var
bmp:TBitmap;
p,pBuf:PChar;
w,h,y,x,LineSize,nOfs:Integer;
begin
bmp:=TBitmap.Create;
bmp.PixelFormat:=pf24bit;
bmp.Assign(AJPG);
w:=bmp.Width;
h:=bmp.Height;
LineSize:=w*3;
GetMem(pBuf,LineSize*h);
try
for y:=0 to bmp.Height-1 do
begin
p:=bmp.ScanLine[h-y-1];
for x:= bmp.Width-1 downto 0 do
begin
nOfs:=(x*h+h-y-1)*3;
Move(p^,pBuf[nOfs],3);
Inc(p,3);
end;
end;
bmp.Width:=h;
bmp.Height:=w;
LineSize:=h*3;
for y:=0 to bmp.Height-1 do
begin
nOfs:=y*LineSize;
Move(pBuf[nOfs],bmp.scanline[y]^,LineSize);
end;
result:=bmp;
finally
FreeMem(pBuf);
end;
end;
function RotateJPG180(AJPG:TJPEGImage):TBitmap;//顺时针180
var
bmp:TBitmap;
p1,p2:PChar;
h,y,x:Integer;
begin
bmp:=TBitmap.Create;
try
bmp.PixelFormat:=pf24bit;
bmp.Assign(AJPG);
result:=TBitmap.Create;
Result.PixelFormat:=pf24bit;
Result.Width:=bmp.Width;
Result.Height:=bmp.Height;
h:=bmp.Height;
for y:=0 to bmp.Height-1 do
begin
p1:=result.ScanLine[y];
p2:=PChar(Integer(bmp.ScanLine[h-1-y])+bmp.Width*3);
for x:=0 to bmp.Width-1 do
begin
Move(p2^,p1^,3);
inc(p1,3);
Dec(p2,3);
end;
end;
finally
bmp.Free;
end;
end;
function FlipVertical(AJPG:TJPEGImage):TBitmap;//水平镜像
var
bmp:TBitmap;
p1,p2:PChar;
h,y,LineSize:Integer;
begin
bmp:=TBitmap.Create;
try
bmp.PixelFormat:=pf24bit;
bmp.Assign(AJPG);
Result:=TBitmap.Create;
Result.PixelFormat:=pf24bit;
Result.Width:=bmp.Width;
Result.Height:=bmp.Height;
LineSize:=bmp.Width*3;
h:=bmp.Height;
for y:=0 to bmp.Height-1 do
begin
p1:=result.ScanLine[y];
p2:=bmp.ScanLine[h-1-y];
Move(p2^,p1^,LineSize);
end;
finally
bmp.Free;
end;
end;
function FlipHorizontal(AJPG:TJPEGImage):TBitmap;//垂直镜像
var
bmp:TBitmap;
p1,p2:PChar;
y,x:Integer;
begin
bmp:=TBitmap.Create;
try
bmp.PixelFormat:=pf24bit;
bmp.Assign(AJPG);
Result:=TBitmap.Create;
Result.PixelFormat:=pf24bit;
Result.Width:=bmp.Width;
Result.Height:=bmp.Height;
for y:=0 to bmp.Height-1 do
begin
p1:=result.ScanLine[y];
p2:=PChar(Integer(bmp.ScanLine[y])+bmp.Width*3);
for x:=0 to bmp.Width-1 do
begin
Move(p2^,p1^,3);
inc(p1,3);
Dec(p2,3);
end;
end;
finally
bmp.Free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
jpg:TJPEGImage;
bmp:TBitmap;
begin
bmp:=nil;
jpg:=TJPEGImage.Create;
try
jpg.LoadFromFile('c:\1.jpg');
bmp:=RotateJPG90(jpg);//顺时针90
// bmp:=RotateJPG180(jpg);//顺时针180
// bmp:=RotateJPG270(jpg);//顺时针270
// bmp:=FlipHorizontal(jpg);//垂直镜像
// bmp:=FlipVertical(jpg);//水平镜像
Image1.Picture.Assign(bmp);
finally
bmp.Free;
jpg.Free;
end;
end;
uses jpeg;
function RotateJPG90(AJPG:TJPEGImage):TBitmap;
var
bmp:TBitmap;
p,pBuf:PChar;
w,h,y,x,LineSize,nOfs:Integer;
begin
bmp:=TBitmap.Create;
bmp.PixelFormat:=pf24bit;
bmp.Assign(AJPG);
w:=bmp.Width;
h:=bmp.Height;
LineSize:=w*3;
GetMem(pBuf,LineSize*h);
try
for y:=0 to bmp.Height-1 do
begin
p:=bmp.ScanLine[y];
for x:=0 to bmp.Width-1 do
begin
nOfs:=((x+1)*h-y-1)*3;
Move(p^,pBuf[nOfs],3);
Inc(p,3);
end;
end;
bmp.Width:=h;
bmp.Height:=w;
LineSize:=h*3;
for y:=0 to bmp.Height-1 do
begin
nOfs:=y*LineSize;
Move(pBuf[nOfs],bmp.scanline[y]^,LineSize);
end;
result:=bmp;
finally
FreeMem(pBuf);
end;
end;