Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
I have a picturebox (origBox) within a panel with auto scroll set on.
A number of lines are drawn on the origBox. Later on a graphics path is drawn on the origBox. Now I am trying to crop and magnify a part of the origBox picturebox contents (bitmap) to another picturebox (cropBox). The cropping and magnification work, but there is a problem:
I use a rectangle to select a part of the origBox. The rectangle covers image of the lines drawn directly on the origBox and part of the graphics path drawn on the origBox. However, on the cropBox, only the selected lines are displayed; the part of graphics path that was selected is missing.
 
Could anyone, please, explain why this happens? Is graphics path a transparent layer that is not picked by copying a part of a picturebox (eg. origBox) bitmap?
 
Thanks.
Posted 9-Jan-13 11:09am
captab1217
Comments
Sergey Alexandrovich Kryukov at 9-Jan-13 17:19pm
   
Wrong way, go back! I explained it all in my answer, please see.
—SA

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

First of all, you try to abuse PictureBox, as too many do. This control is totally useless, unless you want to do something very simple, in a very simplified way. In all other cases, it presents just hassled giving nothing in return. I'll tell you what to do instead.
 
Please see my past answers:
How do I clear a panel from old drawing[^],
draw a rectangle in C#[^],
Append a picture within picturebox[^].
 
See also:
Drawing Lines between mdi child forms[^],
capture the drawing on a panel[^],
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^],
How to speed up my vb.net application?[^].
 
And magnification is done by System.Drawing.Graphics.Transform: http://msdn.microsoft.com/en-us/library/system.drawing.graphics.transform.aspx[^].
 
As to cropping, it's not needed at all (if you are not using PictureBox which will only screw up it Smile | :) ). For rendering (see above), use some control of required size, all rendering will be cropped by its bounds. As simple as that.
 
—SA
  Permalink  
Comments
captab1 at 9-Jan-13 21:24pm
   
Let me clarify, my original statement of the problem. When I say I draw on picturebox origBox, I actually create a bitmap, a graphics canvas for the bitmap, and then draw on the canvas. Once this is done, I use the origBox to display what was drawn by assigning the bitmap to the picturebox origBox.
 
The drawing is displayed fine, but trying to copy part of it (crop) to cropBox bitmap suffers from the above described problem.
Sergey Alexandrovich Kryukov at 9-Jan-13 22:17pm
   
OK, it clearly justifies that you should not use PictureBox, all my recommendations are valid. Please see.
You just went in wrong directions, but it's not too late to fix it. Besides, you will save a lot of time, because doing all your manipulations are highly excessive...
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web02 | 2.8.140926.1 | Last Updated 9 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100