Top.Mail.Ru
Мастера DELPHI, Delphi programming community Титульная страница Поиск, карта сайта Написать письмо 
| Новости | Поиск | FAQ | Статьи | Книги | Новости VCL |
| Форумы ЧАТ | Орешник | KOL и MCK |
Форумы -» Основная («Начинающим»)/ Базы / WinAPI / Компоненты / Сети / Media / Игры / Corba и COM / KOL / FreePascal / .Net / Прочее / RSDN.ORG

« предыдущая ветвь | форум | следующая ветвь »

Поворот изображения [D6, WinME]


Вован2 ©   (2002-09-08 19:25:00) 

Помогите исправить процедуру.
Процедура поворота картинки. Неровно выводит првёрнутую картинку.

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:00) [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;


Наверх

Титульная страница Поиск, карта сайта Написать письмо