把一个图像旋转任意角度,或90,180度
由于图像较大,pix和scanline不能满足要求
由于图像较大,pix和scanline不能满足要求
解决方案 »
- 求救:File not found:"PasComboxGrid.dcu"
- 关于时间段查询问题(DateTimePicker1)
- 问SQL语句
- 我要求职!有视频!! [
- 我的美女徒弟让我给她做题,我实在没时间.非常简单的题目,那个大哥帮帮忙.晚上做好.
- 请问Delphi可以连Access一同打包起来在别的机器上运行吗?谢谢。
- 如何编程用WINDOWS的计划任务定时让我的程序运行??
- 帮我解决一下这两个问题,谢谢!
- 针式打印的打印问题,帮帮忙,有没有知道的,不知道的进来看看,帮忙up,先谢了
- delphi的ListView分页显示
- 和东方快车那样那个form在前面就得到其句柄并执行指定过程如何实现
- 将16精制数转化为10精制d??问题!!谁知道更简单的??
例如ImageN
旋转时候尽量减少乘法,
用汇编进行优化。
正解2:格式化到数组(最小颗粒度),再用纯数学方式实现....偶做过dither算法,用过Canvas对象,各位可以自行想象多狗死...
var
i,j:Integer;
rowIn,rowOut:pRGBTriple;
Bmp:TBitmap;
Width,Height:Integer;
begin
Bmp:=TBitmap.Create;
if (Angle=90) or (Angle=270) then
begin
Bmp.Width := Bitmap.Height;
Bmp.Height := Bitmap.Width;
end
else
begin
Bmp.Width := Bitmap.Width;
Bmp.Height := Bitmap.Height;
end;
Width:=Bitmap.Width-1;
Height:=Bitmap.Height-1;
if Bitmap.PixelFormat<>pf32Bit then Bitmap.PixelFormat:=pf24Bit;
Bmp.PixelFormat:=Bitmap.PixelFormat;
for j := 0 to Height do
begin
rowIn := Bitmap.ScanLine[j];
for i := 0 to Width do
begin
if Angle=90 then
begin
rowOut := Bmp.ScanLine[i];
Inc(rowOut,Height - j);
end
else if Angle=270 then
begin
rowOut := Bmp.ScanLine[Width - i];
Inc(rowOut,j);
end
else if HVType=0 then
begin
rowOut := Bmp.ScanLine[j];
Inc(rowOut,Width - i);
end
else if HVType=1 then
begin
rowOut := Bmp.ScanLine[Height - j];
Inc(rowOut,i);
end
else
begin
rowOut := Bmp.ScanLine[Height - j];
Inc(rowOut,Width - i);
end;
rowOut^ := rowIn^;
Inc(rowIn);
end;
end;
Bitmap.Assign(Bmp);
end;function RotateBitmap(Bitmap:TBitmap;Angle:Integer;BackColor:TColor):TBitmap;
var
i,j,iOriginal,jOriginal,CosPoint,SinPoint : integer;
RowOriginal,RowRotated : pRGBTriple;
SinTheta,CosTheta : Extended;
AngleAdd : integer;
begin
Bitmap.PixelFormat := pf24Bit;
Result:=TBitmap.Create;
Result.PixelFormat := pf24bit;
Result.Canvas.Brush.Color:=BackColor;
Angle:=Angle Mod 360;
if Angle<0 then Angle:=360-Abs(Angle);
if Angle=0 then
Result.Assign(Bitmap)
else if Angle=90 then
begin
Result.Assign(Bitmap);
ImageRF(Result,90,-1);
end
else if (Angle>90) and (Angle<180) then
begin
AngleAdd:=90;
Angle:=Angle-AngleAdd;
end
else if Angle=180 then
begin
Result.Assign(Bitmap);
ImageRF(Result,180,-1);
end
else if (Angle>180) and (Angle<270) then
begin
AngleAdd:=180;
Angle:=Angle-AngleAdd;
end
else if Angle=270 then
begin
Result.Assign(Bitmap);
ImageRF(Result,270,-1);
end
else if (Angle>270) and (Angle<360) then
begin
AngleAdd:=270;
Angle:=Angle-AngleAdd;
end
else
AngleAdd:=0;
if (Angle>0) and (Angle<90) then
begin
SinCos((Angle + AngleAdd) * Pi / 180, SinTheta, CosTheta);
if (SinTheta * CosTheta) < 0 then
begin
Result.Width := Round(Abs(Bitmap.Width * CosTheta - Bitmap.Height * SinTheta));
Result.Height := Round(Abs(Bitmap.Width * SinTheta - Bitmap.Height * CosTheta));
end
else
begin
Result.Width := Round(Abs(Bitmap.Width * CosTheta + Bitmap.Height * SinTheta));
Result.Height := Round(Abs(Bitmap.Width * SinTheta + Bitmap.Height * CosTheta));
end;
CosTheta:=Abs(CosTheta);
SinTheta:=Abs(SinTheta);
if (AngleAdd=0) or (AngleAdd=180) then
begin
CosPoint:=Round(Bitmap.Height*CosTheta);
SinPoint:=Round(Bitmap.Height*SinTheta);
end
else
begin
SinPoint:=Round(Bitmap.Width*CosTheta);
CosPoint:=Round(Bitmap.Width*SinTheta);
end;
for j := 0 to Result.Height-1 do
begin
RowRotated := Result.Scanline[j];
for i := 0 to Result.Width-1 do
begin
Case AngleAdd of
0:
begin
jOriginal := Round((j+1-(i+1-SinPoint)*SinTheta/CosTheta)*CosTheta)-1;
iOriginal := Round((i+1-(CosPoint-j-1)*SinTheta/CosTheta)*CosTheta)-1;
end;
90:
begin
iOriginal := Round((j+1-(i+1-SinPoint)/SinTheta*CosTheta)*SinTheta)-1;
jOriginal := Bitmap.Height-Round((i+1-(CosPoint-j-1)/SinTheta*CosTheta)*SinTheta);
end;
180:
begin
jOriginal := Bitmap.Height-Round((j+1-(i+1-SinPoint)*SinTheta/CosTheta)*CosTheta);
iOriginal := Bitmap.Width-Round((i+1-(CosPoint-j-1)*SinTheta/CosTheta)*CosTheta);
end;
270:
begin
iOriginal := Bitmap.Width-Round((j+1-(i+1-SinPoint)/SinTheta*CosTheta)*SinTheta);
jOriginal := Round((i+1-(CosPoint-j-1)/SinTheta*CosTheta)*SinTheta)-1;
end;
end;
if (iOriginal >= 0) and (iOriginal <= Bitmap.Width-1)and
(jOriginal >= 0) and (jOriginal <= Bitmap.Height-1)
then
begin
RowOriginal := Bitmap.Scanline[jOriginal];
Inc(RowOriginal,iOriginal);
RowRotated^ := RowOriginal^;
Inc(RowRotated);
end
else
begin
Inc(RowRotated);
end;
end;
end;
end;
end;