Форум: "Media";
Текущий архив: 2002.12.23;
Скачать: [xml.tar.bz2];
ВнизПоворот изображения Найти похожие ветки
← →
Вован2 (2002-09-08 19:25) [0]Помогите исправить процедуру.
Процедура поворота картинки. Неровно выводит првёрнутую картинку.
PROCEDURE SetAngle(Value:integer);
VAR Src,Dst:TBitmap; //Исходная и повёрнутая картинки
Angle:extended; //Угол
X,Y:integer;
Xo,Yo:integer; //Центр поворота
R,S,C:extended; //Радиус, синус и косинус
BEGIN
Angle:=Value*Pi/180;
Dst:=TBitmap.Create;
Src:=TBitmap.Create;
Src:=Image1.Bitmap;
Xo:=Src.Width div 2;
Yo:=Src.Height div 2;
SinCos(Angle,S,C);
If S*C < 0
then begin
Image1.Width:=Round(Abs(Src.Width*C-Src.Height*S));
Image1.Height:=Round(Abs(Src.Width*S-Src.Height*C));
end
else begin
Image1.Width:=Round(Abs(Src.Width*C+Src.Height*S));
Image1.Height:=Round(Abs(Src.Width*S+Src.Height*C));
end;
Dst.Width:=Image1.Width;
Dst.Height:=Image1.Height;
Dst.TransparentColor:=clWhite;
Dst.TransparentMode:=tmAuto;
Dst.Transparent:=True;
For Y:=0 to Dst.Height do
For X:=0 to Dst.Width do
begin
R:=Sqrt(Sqr(X-Xo)+Sqr(Y-Yo));
SinCos(Angle+ArcTan2((Y-Yo),(X-Xo)),S,C);
If (Round(Xo+R*C) in [0..Src.Width-1]) and (Round(Yo+R*S) in [0..Src.Height-1])
then Dst.Canvas.Pixels[X,Y]:=Src.Canvas.Pixels[Round(Xo+R*C),Round(Yo+R*S)]
else Dst.Canvas.Pixels[X,Y]:=clWhite;
end;
Image1.Canvas.Brush.Color:=clWhite;
Image1.Canvas.Brush.Style:=bsSolid;
Image1.Canvas.FillRect(Canvas.ClipRect);
Image1.Picture.Bitmap:=Dst;
Dst.Free;
Src.Free;
END;
← →
MBo (2002-09-09 09:38) [1]при повороте на n*Pi/2 возможны погрешности на точку из-за округления, поэтому в этих случаях лучше применять другие методы (они простые)
function BmpRot(const B: TBitmap;fi:integer):TBitmap;
type
TRGBTripleArray = array[word] of TRGBTriple;
pRGBTripleArray = ^TRGBTripleArray;
var
x0,y0,i,j,x1,y1,x11,y11,x2,y2:integer;
ht,wd,newht,newwd:integer;
cfi,sfi: double;
sline1,sline2: pRGBTRipleArray;
BEGIN
sfi:=sin(degtorad(fi));
cfi:=cos(degtorad(fi));
ht:=b.height;
wd:=b.width;
newwd:=abs(round(ht*sfi))+abs(round(wd*cfi));
newht:=abs(round(wd*sfi))+abs(round(ht*cfi));
Result:=TBitmap.create;
Result.Width:=newwd;
Result.Height:=newht;
Result.PixelFormat:=pf24bit;
x0:=wd div 2;
y0:=ht div 2;
for j :=newht-1 downto 0 do begin
sline2 := Result.scanline[j];
y1:= 2*(j-(newht-ht) div 2 -y0);
for i := newwd-1 downto 0 do begin
x1:=2*(i-(newwd-wd) div 2 -x0);
x2 :=round(x1 * cfi - y1 * sfi);
y2 :=round(x1 * sfi + y1 * cfi);
x11:=x2 div 2 +x0;
y11:=y2 div 2 +y0;
if (x11>=0)and(x11<wd)and(y11>=0)and(y11<ht) then begin
sline1 := b.scanline[y11];
sline2[i] := sline1[x11];
end;
end;
end;
end;
Страницы: 1 вся ветка
Форум: "Media";
Текущий архив: 2002.12.23;
Скачать: [xml.tar.bz2];
Память: 0.45 MB
Время: 0.007 c