.Paul Sir,
I am completely in learning phase in vb.net
Let me be frank. I just copied the code from 'https://www.dotnetcurry.com/ShowArticle.aspx?ID=196
and tried to implement. I did not know the consequences for AddHandler and Handles Clause
Untill you higlighted and explained. Thank you very much.
At present I am not incorporating for percentages. Will have to work on it, if something comes up and result not achieved then will post new thread.If you want percentages, you need to use values from 0 to 1 with an appropriate change value.
I don’t know if that’s possible with a slider control
Is the below what you meant for your above comment because I did not understand ...Use of Two decimal arguments....Use two Decimal arguments instead of a Size argument
ZOOMING PART
Zooming has worked perfectly with above changes.Code:Public Function PictureBoxZoom(ByVal img As Image, zWidth As Integer, zHeight As Integer) As Image Dim bm As Bitmap = New Bitmap(img, Convert.ToInt32(img.Width * zWidth), Convert.ToInt32(img.Height * zHeight)) Return bm End Function Private Sub zoomSlider_Scroll(sender As Object, e As EventArgs) Handles zoomSlider.Scroll If zoomSlider.Value > 0 Then PictureBox1.Image = Nothing PictureBox1.Image = PictureBoxZoom(imgOriginal, zoomSlider.Value, zoomSlider.Value) End If End Sub
Last but not the least.
FYI 've succeeded in moving the image with below coding but with small issues observed
1.Two Images are seen
2. If I zoom the Orignal Image Zooms
3. If I try to move the Zoomed image. Original Image again appears with its original Size, in front of the Zoomed Image, and Orgnl.Img moves and Zoomed image is not moved
4. I would like to move the image within the border of PictureBox. The Image goes outside the border/Frame of Picturebox
5. I will appreciate the corrections, if one could help to correct it
Moving Image
nkvbCode:Private _img As Image Private _imgRect As Rectangle Private picture As Image = Nothing Private picture_offsetX As Integer = 0, picture_offsetY As Integer = 0 Private _xPos As Integer = 0 Private _yPos As Integer = 0 Private _dragging As Boolean = False Private imgpath As String = "C:\Images\Img1.JPG" Private Sub PictureBox1_MouseDown(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseDown Cursor = Cursors.Cross If e.Button <> MouseButtons.Left Then Return _dragging = True _xPos = e.X _yPos = e.Y End Sub Private Sub PictureBox1_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseMove Dim _img As Bitmap = New Bitmap(imgOriginal) If Not _dragging OrElse _img Is Nothing Then Return If e.Button = MouseButtons.Left Then picture_offsetX = picture_offsetX - (_xPos - e.X) picture_offsetY = picture_offsetY - (_yPos - e.Y) _xPos = e.X _yPos = e.Y _imgRect = New Rectangle(picture_offsetX, picture_offsetY, _img.Width, _img.Height) PictureBox1.Invalidate() End If End Sub Private Sub PictureBox1_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox1.Paint If _img IsNot Nothing Then e.Graphics.DrawImage(_img, picture_offsetX, picture_offsetY) End If End Sub




Reply With Quote