c# - Coordinate Mismatch Problem -
- loaded jpg picture box (in size mode zoomed).
- i drawn rectangle on picture box , taken coordinate.
- opens jpg in paint , observed coordinate (where drawn rectangle on picture box). when compare rectangle coordinate(x , y) paint coordinate not same.
i changed size mode normal , observed coordinates same image size large display partially. use zoom size mode property.
say image size 2825x3538 , keep picture box size mode normal, image shows partially in picture box. changed picture box mode zoom (to fit system screen resolution). , coordinate miss matched when compare normal mode zoom mode.
how can achieve same coordinates.
private void opentoolstripmenuitem_click(object sender, eventargs e) {openfd.filename = ""; openfd.title = "open image"; openfd.initialdirectory = "c"; openfd.filter = "jpeg|*.jpg|bmp|*.bmp|all files|*.*.*"; if (openfd.showdialog() == dialogresult.ok) { file = openfd.filename; image = image.fromfile(file); picturebox1.image = image; svc = screen.primaryscreen; picturebox1.width = svc.bounds.width; picturebox1.height = svc.bounds.height-100; mybitmap1 = new bitmap (picturebox1.image); mybitmap1.setresolution(300, 300); picturebox1.image = mybitmap1; } }
private void picturebox1_mousedown(object sender, mouseeventargs e) { if (mybitmap == null) { mybitmap = new bitmap(picturebox1.width, picturebox1.height); mybitmap.setresolution(300, 300); } }
private void picturebox1_paint(object sender, painteventargs e) {
using (g = graphics.fromimage(mybitmap)) { using (pen pen = new pen(color.green, m)) { e.graphics.drawrectangle(pen, r); e.graphics.drawstring(lab[c].tostring(), new font(lab[c].tostring(), 8f), new solidbrush(label1.forecolor), r); } } }
Comments
Post a Comment