请问:如何将一副bmp图片旋转90度之后,通过savetofile保存后是旋转90度之后的结果?我用的是fcImager控件,里面有属性angle实现旋转效果,但保存之后仍然是旋转之前的图片。
我搜索过之前csdn的文章,有一篇文章说fcImager控件不行。用象素矩阵实现旋转可以,不过速度太慢了,不能接受。小弟初学delphi不久,希望有高手能指点一下小弟,小弟不胜感激!
我搜索过之前csdn的文章,有一篇文章说fcImager控件不行。用象素矩阵实现旋转可以,不过速度太慢了,不能接受。小弟初学delphi不久,希望有高手能指点一下小弟,小弟不胜感激!
解决方案 »
- ClientSocket和ServerSocket的问题
- 已在Excel中做好固定模版,如何将此模板存放在Access中以方便数据导出?
- telnet的demo中不能断开服务器
- 谁用过或研究过Tera Term? 请高手指点一下。
- 烦了我一星期的问题
- 關于api函數GetFileTime的用法
- 怎样用sqlserver存取声音文件??
- 十万火急,求教delphi高手,
- 请教用WebBrowser查看源文件问题,在线等
- 如何使dbgrideh中的下拉列表仅可选择,不可编辑?
- dbexpress的不能applyupdates?
- 为什么x 总提示 错误 value assigned to x never used
Google上找例子吧http://lysoft.7u7.net
点扫描的话,如果图片不大,还是不慢的
function TPic.AdjustPosition(Bmp, BmpDest: TBitmap; Angle: Double): integer;
var
i, j, iRotationAxis, iOriginal, iPrime, iPrimeRotated, jRotationAxis, jOriginal,
jPrime, jPrimeRotated: Integer;
RowOriginal: pRGBArray;
RowRotated: pRGBArray;
Theta, sinTheta, cosTheta: DOUBLE;
R, G, B: byte;
FColor: TColor;
SavFormat: TPixelFormat;
begin
//最大程度保证不丢失图象
if bmp.Width>bmp.Height then
begin
BmpDest.Width := Bmp.Width;
BmpDest.Height := Bmp.Width;
end
else
begin
BmpDest.Width := Bmp.height;
BmpDest.Height := Bmp.height;
end;
// BmpDest.PixelFormat := pf24bit;
SavFormat := Bmp.PixelFormat;
Bmp.PixelFormat := pf24bit;
BmpDest.PixelFormat := Bmp.PixelFormat;
iRotationAxis := Bmp.Width div 2;
jRotationAxis := Bmp.Height div 2;
Theta := Angle * PI / 180;
sinTheta := SIN(Theta);
cosTheta := COS(Theta);
FColor := Bmp.Canvas.Pixels[0, 0];
B := FColor mod 256;
G := round((FColor div 256) mod 256);
R := round((FColor div 256) div 256); for j := BmpDest.Height - 1 downto 0 do
begin
RowRotated := BmpDest.Scanline[j];
jPrime := 2 * (j - jRotationAxis) + 1;
for i := BmpDest.Width - 1 downto 0 do
begin
iPrime := 2 * (i - iRotationAxis) + 1;
iPrimeRotated := ROUND(iPrime * CosTheta - jPrime * sinTheta);
jPrimeRotated := ROUND(iPrime * sinTheta + jPrime * cosTheta);
iOriginal := (iPrimeRotated - 1) div 2 + iRotationAxis;
jOriginal := (jPrimeRotated - 1) div 2 + jRotationAxis;
if (iOriginal >= 0) and (iOriginal <= Bmp.Width - 1) and
(jOriginal >= 0) and (jOriginal <= Bmp.Height - 1)
then
begin
RowOriginal := Bmp.Scanline[jOriginal];
RowRotated[i] := RowOriginal[iOriginal]
end
else
begin
RowRotated[i].rgbtBlue := B;
RowRotated[i].rgbtGreen := G;
RowRotated[i].rgbtRed := R
end;
end;
end;
Bmp.PixelFormat := SavFormat;
BmpDest.PixelFormat := Bmp.PixelFormat;
result:=1;
end;procedure TForm1.N14Click(Sender: TObject);
var
bmpdest : TBitmap;
begin
bmp :=TBitmap.Create;
bmpdest :=Tbitmap.Create;
bmp.Assign(Image1.Picture.Bitmap);
PicDeal.AdjustPosition(Bmp, bmpdest,90);
form1.Image2.Picture.Bitmap.Assign(BmpDest);
bmp.Free;
end;
pRGBArray = ^TRGBArray;
{$EXTERNALSYM pRGBArray}
TRGBArray = array[0..MaxPixelCount - 1] of TRGBTriple;
Bitmap.PixelFormat := pf32Bit;//调用
Rotate90(Bitmap);PBGRA = ^TBGRA;
TBGRA = packed record
B, G, R, A: Byte;
end;procedure Rotate90(const ABitmap: TBitmap);
var
I, J: Integer;
RowIn, RowOut, POut: PBGRA;
Bmp: TBitmap;
Width, Height: Integer;
LineSize: Integer;
begin
Bmp := TBitmap.Create;
Bmp.Width := ABitmap.Height;
Bmp.Height := ABitmap.Width;
Bmp.PixelFormat := pf32Bit;
Width := ABitmap.Width-1;
Height := ABitmap.Height-1;
LineSize := Bmp.Width;
RowIn := ABitmap.ScanLine[Height];
POut := PBGRA(Cardinal(Bmp.ScanLine[0]) - 4);
for j := 0 to Height do
begin
Inc(POut);
RowOut := POut;
for I := 0 to Width do
begin
RowOut^ := RowIn^;
Inc(RowIn);
Dec(RowOut, LineSize);
end;
end;
ABitmap.Assign(Bmp);
Bmp.Free;
end;