I have a custom picturebox control that allows dragging 2 bitmaps separately on the Main image,thus allowing the user to select the location of the 2 bitmaps.
For First Bitmap
Point src = e.Location;
PointF ratio = new PointF((float)src.X / ClientSize.Width, (float)src.Y / ClientSize.Height);
LaunchOrigin.textratio = ratio;
Point origin = new Point((int)(backupbit1.Width * ratio.X), (int)(backupbit1.Height * ratio.Y));
LaunchOrigin.textorigin = origin;
point.X = src.X - origin.X;
point.Y = src.Y - origin.Y;
For Second Bitmap
Point src = e.Location;
PointF ratio = new PointF((float)src.X / Width, (float)src.Y / Height);
LaunchOrigin.logoratio = ratio;
Point origin = new Point((int)(backupbit2.Width * ratio.X), (int)(backupbit2.Height * ratio.Y));
LaunchOrigin.logoorigin = origin;
point2.X = src.X - origin.X;
point2.Y = src.Y - origin.Y;
This is location is returned to the Main form which contains the full resolution image.In order to properly translate the 2 points (of the 2 bitmaps) i do the following.
Point origin = new Point((int)(bitmap.Width * textratio.X), (int)(bitmap.Height * textratio.Y));
Point pos2 = new Point((int)(textratio.X * img.Width), (int)(textratio.Y * img.Height));
cpoint.X = pos2.X - (int)(origin.X);
cpoint.Y = pos2.Y - (int)(origin.Y);
Point origin = new Point((int)(worktag.Width * logoratio.X), (int)(worktag.Height * logoratio.Y));
Point logopositionpoint = new Point((int)(logoratio.X * img.Width), (int)(logoratio.Y * img.Height));
imgpoint.X = logopositionpoint.X - origin.X;
imgpoint.Y = logopositionpoint.Y - origin.Y;
This works pretty fine when the 2 Bitmaps are placed at distant locations.But when the 2 bitmaps are placed closer to each other and the full resolution image becomes lesser in height than the reference image used for placing the bitmaps these 2 bitmaps overlap.
I'm i doing something wrong? Or do i need to do some overlap detection?
Please advice..
I crated a sample code which works on form. The form has picturebox that gets the image from the button. You can change it if the solution works. The Form has the componenets ( pictureBox, btnImage)
Here is the complete code