ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 distort a picture
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

klausdoege

Germany
389 Posts

Posted - Oct 29 2011 :  10:33:35  Show Profile  Reply
Hello,
I look for a possibility to distort a picture to the trapeze.
Is that possible with Imageen?

Klaus

xequte

39142 Posts

Posted - Oct 30 2011 :  02:20:07  Show Profile  Reply
Sorry Klaus

Do you mean to perform a quadrilateral stretch of an image?


Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

klausdoege

Germany
389 Posts

Posted - Oct 30 2011 :  05:07:14  Show Profile  Reply
Hallo Nigel,
sorry the Attach from example don't work.

Original:
----------------------------
|..........................|
|..........................|
|..........................|
----------------------------
after distorsion:
|--------------|
|................|
|..................|
--------------------
Top wide must be smaller then bottom wide

Klaus
Go to Top of Page

rmklever

Norway
52 Posts

Posted - Oct 31 2011 :  11:18:26  Show Profile  Reply
Hi klausdoege,

Here is a routine that can be used to perform wanted action.

Hope this helps.

procedure fxPerspectiv(Src: TBitmap; x0, y0, x1, y1, x2, y2, x3, y3: Double;
Background: TColor);
var
delx1, dely1, delx2, dely2, delx3, dely3: double;
a11, a12, a13, a21, a22, a23, a31, a32, a33: double;
a, b, c, d, e, f, g, h, i: double;
x, y: integer;
fu, fv: double;
s1, s2: PLine24;
iRGB, bRGB: tRGB24;
ptrD, ptrS, width, height: integer;
dst: tBitmap;
bool: boolean;

function RC(x, y: integer): trgb24;
begin
if ((x >= 0) and (x <= width - 1)) and ((y >= 0) and (y <= height - 1)) then
RC := pRGB24(PtrS * y + (x * 3) + Integer(s1))^
else
RC := bRGB;
end;

function Bilinear(x, y: double): tRGB24;
var
j, k, r, g, b: integer;
cx, cy, m0, m1: double;
p0, p1, p2, p3: trgb24;
begin
j := trunc(x);
k := trunc(y);
cx := x - floor(x);
cy := y - floor(y);
p0 := RC(j, k);
p1 := RC(j + 1, k);
p2 := RC(j, k + 1);
p3 := RC(j + 1, k + 1);
m0 := p0.r + cx * (p1.r - p0.r);
m1 := p2.r + cx * (p3.r - p2.r);
r := trunc(m0 + cy * (m1 - m0));
m0 := p0.g + cx * (p1.g - p0.g);
m1 := p2.g + cx * (p3.g - p2.g);
g := trunc(m0 + cy * (m1 - m0));
m0 := p0.b + cx * (p1.b - p0.b);
m1 := p2.b + cx * (p3.b - p2.b);
b := trunc(m0 + cy * (m1 - m0));
Bilinear.r := r;
Bilinear.g := g;
Bilinear.b := b;
end;

begin
bRGB.r := Background and $000000FF;
bRGB.g := (Background and $0000FF00) shr 8;
bRGB.b := (Background and $00FF0000) shr 16;

Width := Src.Width;
Height := Src.Height;

dst := TBitmap.Create;
dst.PixelFormat := pf24bit;
dst.Canvas.Brush.Color := Background;
dst.Width := Width;
dst.Height := Height;

s2 := dst.ScanLine[0];
ptrD := integer(dst.ScanLine[1]) - integer(s2);
s1 := src.ScanLine[0];
ptrS := integer(src.ScanLine[1]) - integer(s1);

delx1 := x1 - x2;
dely1 := y1 - y2;
delx2 := x3 - x2;
dely2 := y3 - y2;
delx3 := x0 - x1 + x2 - x3;
dely3 := y0 - y1 + y2 - y3;

if (delx3 = 0) and (dely3 = 0) then
begin
a11 := x1 - x0;
a21 := x2 - x1;
a31 := x0;
a12 := y1 - y0;
a22 := y2 - y1;
a32 := y0;
a13 := 0;
a23 := 0;
end
else
begin
a13 := (delx3 * dely2 - delx2 * dely3) / (delx1 * dely2 - dely1 * delx2);
a23 := (delx1 * dely3 - dely1 * delx3) / (delx1 * dely2 - dely1 * delx2);
a11 := x1 - x0 + (a13 * x1);
a21 := x3 - x0 + (a23 * x3);
a31 := x0;
a12 := y1 - y0 + a13 * y1;
a22 := y3 - y0 + a23 * y3;
a32 := y0;
end;
a := a22 - a23 * a32;
b := a23 * a31 - a21;
c := a21 * a32 - a31 * a22;
d := a32 * a13 - a12;
e := a11 - a31 * a13;
f := a31 * a12 - a11 * a32;
g := a12 * a23 - a22 * a13;
h := a21 * a13 - a11 * a23;
i := a11 * a22 - a21 * a12;
for y := 0 to dst.Height - 1 do
begin
for x := 0 to dst.Width - 1 do
begin
fu := ((a * x + b * y + c) / (g * x + h * y + i)) * width;
fv := ((d * x + e * y + f) / (g * x + h * y + i)) * height;
iRGB := Bilinear(fu, fv);
pRGB24(PtrD * y + (x * 3) + Integer(s2))^ := iRGB;
end;
end;
BitBlt(src.Canvas.Handle, 0, 0, dst.Width, dst.Height, dst.Canvas.Handle, 0,
0, SRCCOPY);
dst.Free;
end;

Roy M Klever
Klever on Delphi - www.rmklever.com
Go to Top of Page

fab

1310 Posts

Posted - Nov 01 2011 :  00:30:08  Show Profile  Reply
Please look at TImageEnProc.PerspectiveDraw() method.
Go to Top of Page

klausdoege

Germany
389 Posts

Posted - Nov 01 2011 :  12:12:10  Show Profile  Reply
Hello Roy, Fabrizio,
thank you for the tips.
I will try it.

Klaus
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: