Rank: Advanced Member
Groups: Member, Administration, Moderator Joined: 8/3/2003(UTC) Posts: 1,070
Thanks: 1 times Was thanked: 12 time(s) in 12 post(s)
|
Hello, Sorry for late answer. As the size of image is changed while it is tranformed by projective points algorithm, you should move position of your polygon after transformation. You can calculate polygon offset in particular case only when source polygon is corner-aligned rectangle: (0, 0, image width, image height). In common case there is no way to calculate offset values because of implementation aspects of algorithm. So offset will be: X position: destPointX[i] -= minDestX, where minDestX - minimum x-coordinate value of destination polygon; Y position: destPointY[i] -= minDestY, where minDesty - minimum y-coordinate value of destination polygon;
Pay attention that there is a problem in DragRectangle setter - points were calcualted wrong. The correct version of setter is the following: Code: public System.Drawing.Rectangle DragRectangle {
get { return dragRec; }
set {
dragRec = value;
//'Init source points
destPointX[0] = oldPointX[0] = dragRec.X;
destPointY[0] = oldPointY[0] = dragRec.Y;
//destPointX[1] = oldPointX[1] = dragRec.Width;
destPointX[1] = oldPointX[1] = dragRec.Right;
destPointY[1] = oldPointY[1] = dragRec.Y;
//destPointX[2] = oldPointX[2] = dragRec.Width;
destPointX[2] = oldPointX[2] = dragRec.Right;
//destPointY[2] = oldPointY[2] = dragRec.Height;
destPointY[2] = oldPointY[2] = dragRec.Bottom;
destPointX[3] = oldPointX[3] = dragRec.X;
//destPointY[3] = oldPointY[3] = dragRec.Height;
destPointY[3] = oldPointY[3] = dragRec.Bottom;
}
}
Click handler of "Tranform" button will be the followingCode:private void button2_Click(object sender, EventArgs e) {
try {
//Apply projective transform and store the result.
GMBitmap.Bitmap.ApplyInPlace = false;
int widthBefore = GMBitmap.Bitmap.Data.Width;
int heightBefore = GMBitmap.Bitmap.Data.Height;
GMBitmap.Bitmap = GMBitmap.Bitmap.Transforms.ProjectivePoints(
destPointX[0], destPointY[0],
destPointX[1], destPointY[1],
destPointX[2], destPointY[2],
destPointX[3], destPointY[3],
oldPointX[0], oldPointY[0],
oldPointX[1], oldPointY[1],
oldPointX[2], oldPointY[2],
oldPointX[3], oldPointY[3],
0,
InterpolationMode.InterpolationModeHighQuality,
FitMode.FitModeCircumscribed);
GMBitmap.Bitmap.ApplyInPlace = true;
double minDestX = double.MaxValue;
double minDestY = double.MaxValue;
for (int i = 0; i < 4; i++)
{
if (minDestX > destPointX[i])
minDestX = destPointX[i];
if (minDestY > destPointY[i])
minDestY = destPointY[i];
}
for (int i = 0; i < 4; i++)
{
destPointX[i] -= minDestX;
destPointY[i] -= minDestY;
}
for (int i = 0; i < 4; i++) {
oldPointX[i] = destPointX[i];
oldPointY[i] = destPointY[i];
}
} catch (Exception ex) {
lbMessage.Text = ex.Message;
}
}
As you develop .NET application I advise you to upgrade Graphics Mill for ActiveX to Graphics Mill for .NET. Graphics Mill for .NET is native for .NET platform and has a lot of improvements in comparison with ActiveX version. More information you can read on our site.Edited by user Monday, December 17, 2007 12:29:54 PM(UTC)
| Reason: Not specified |
|