请高手给小弟解燃眉之急,帮忙写一个将bmp图像旋转90度的算法
解决方案 »
- treeview保存数据库
- 请教一个关于图片读取和存储的问题?
- 哪有Delphi6下载?在线给分!
- 在grid控件下有一个列有很多个重复的值,如何只让第一行显示,以下的为空白?
- 无聊,散分。
- LIKE为什么不能实现模糊查询?
- 有一TDBEdit控件关联一DateTime字段,如果在该控件里输入非法日期,如1999-1-32,那么当点击其它控件时,会报错:‘1999-1-32’ is not a
- 用delphi自动配置odbc数据源时如果是Sql server数据库如何配置?
- 伴水请进!(100分)
- 用DELPHI设计当下流行的多窗口式浏览器有多难?
- 求一个网络是否适合客户目前要求的问题?
- 用QReport打打印出问题,请高人指点!!!
var
nIdx, nOfs,
x, y, i,nMultiplier: integer;
nMemWidth, nMemHeight, nMemSize,nScanLineSize: LongInt;
aScnLnBuffer: PChar;
aScanLine: PByteArray;
begin
Result:=nil;
Result:=TBitmap.create;
nMultiplier := GetPixelSize(Bitmap);
nMemWidth := Bitmap.Height;
nMemHeight := Bitmap.Width;
nMemSize := nMemWidth * nMemHeight * nMultiplier;
GetMem(aScnLnBuffer, nMemSize);
try
nScanLineSize := Bitmap.Width * nMultiplier;
GetMem(aScanLine, nScanLineSize);
try
for y := 0 to Bitmap.Height-1 do
begin
Move(Bitmap.ScanLine[y]^, aScanLine^, nScanLineSize);
for x := 0 to Bitmap.Width-1 do
begin
nIdx := ((Bitmap.Width-1) - x) * nMultiplier;
nOfs := (x * nMemWidth * nMultiplier) +(y * nMultiplier);
for i := 0 to nMultiplier-1 do
Byte(aScnLnBuffer[nOfs + i]) := aScanLine[nIdx+i];
end;
end;
Bitmap.Height := nMemHeight;
Bitmap.Width := nMemWidth;
for y := 0 to nMemHeight-1 do
begin
nOfs := y * nMemWidth * nMultiplier;
Move((@(aScnLnBuffer[nOfs]))^, Bitmap.ScanLine[y]^, nMemWidth * nMultiplier);
end;
finally
FreeMem(aScanLine, nScanLineSize);
end;
finally
FreeMem(aScnLnBuffer, nMemSize);
Result.Assign(Bitmap);
end;
end;
procedure Rotate90(const Bitmap:TBitmap);
var
i, j: Integer;
rowIn,rowOut: PRGBTriple;
Bmp: TBitmap;
Width,Height: Integer;
begin
Bmp := TBitmap.Create;
Bmp.Width := Bitmap.Height;
Bmp.Height := Bitmap.Width;
Width := Bitmap.Width - 1;
Height := Bitmap.Height - 1;
for j := 0 to Height do
begin
rowIn := Bitmap.ScanLine[j];
for i := 0 to Width do
begin
rowOut := Bmp.ScanLine[i];
Inc(rowOut, Height - j);
rowOut^ := rowIn^;
Inc(rowIn);
end;
end;
Bitmap.Assign(Bmp);
end;
//逆时针旋转90度
procedure Rotate-90(const Bitmap:TBitmap);
var
i, j: Integer;
rowIn, rowOut: PRGBTriple;
Bmp: TBitmap;
Width,Height: Integer;
begin
Bmp := TBitmap.Create;
Bmp.Width := Bitmap.Height;
Bmp.Height := Bitmap.Width;
Width := Bitmap.Width - 1;
Height:= Bitmap.Height - 1;
for j := 0 to Height do
begin
rowIn := Bitmap.ScanLine[j];
for i := 0 to Width do
begin
rowOut := Bmp.ScanLine[Width - i];
Inc(rowOut,j);
rowOut^ := rowIn^;
Inc(rowIn);
end;
end;
Bitmap.Assign(Bmp);
end;
Left := 0;
Top := 0;
Height := image.Width;
Width := image.Height;
for aa := 0 to image.Height do
for ss := 0 to image.Width do
canvas.Pixels[(-aa + image.Height),
ss] := image.canvas.Pixels[ss, aa];
最后把临时的IMAGE重新写如原来的BMP中。
上面的是右转90度。