Question

How to calculate Pixel position when zoom in or zoom out an image in c# ....

How to calculate Pixel position when zoom in or zoom out an image in c# . I have an application in c# that displayed image when I clicked with mouse at a point on the image it give the pixel value for that point (using e.x and e.y). now i zoom in or out the image. How to get the pixel of the same point in zoomed position on run time. (I don't want to click again at the same position after zoomed). zoom in by adding 0.2 to the current zoom and zoom out by subtracting 0.2 from the current zoom. Is there any procedure that give the correct pixel value on the original image?!

Homework Answers

Answer #1

Imports System.ComponentModel
Imports System.Drawing

'Public properties for the ZoomPictureBox
Partial Public Class ZoomPictureBox

   <Category("_ZoomPictureBox"), _
   Description("Enable dragging. Set to False if you implement other means of image scrolling.")> _
   Public Property EnableMouseDragging As Boolean
       Get
           Return _EnableMouseWheelDragging
       End Get
       Set(value As Boolean)
           _EnableMouseWheelDragging = value
       End Set
   End Property

   <Category("_ZoomPictureBox"), _
   Description("Enable mouse wheel zooming. Set to false e.g. if you control zooming with a TrackBar.")> _
   Public Property EnableMouseWheelZooming As Boolean
       Get
           Return _EnableMouseWheelZooming
       End Get
       Set(value As Boolean)
           _EnableMouseWheelZooming = True
       End Set
   End Property

   <Category("_ZoomPictureBox"), _
   Description("Image to display in the ZoomPictureBox.")> _
   Public Property Image() As Image
       Get
           Return _Image
       End Get
       Set(ByVal value As Image)
           _Image = value
           If value IsNot Nothing Then
               InitializeImage()
           Else
               _imageInitialized = False
           End If
       End Set
   End Property

<Browsable(False), _
Description("The bounding rectangle of the zoomed image relative to the control origin.")> _
Public ReadOnly Property ImageBounds() As Rectangle
Get
Return _ImageBounds
End Get
End Property

<Browsable(False), _
Description("Location of the top left corner of the zoomed image relative to the control origin.")> _
Public Property ImagePosition() As Point
Get
Return _ImageBounds.Location
End Get
Set(ByVal value As Point)
Me.Invalidate(_ImageBounds)
_ImageBounds.X = value.X
_ImageBounds.Y = value.Y
Me.Invalidate(_ImageBounds)
End Set
End Property

   <Category("_ZoomPictureBox"), _
Description("The maximum zoom magnification.")> _
Public Property MaximumZoomFactor As Double
       Get
           Return _MaximumZoomFactor
       End Get
       Set(value As Double)
           _MaximumZoomFactor = value
       End Set
   End Property

   <Category("_ZoomPictureBox"), _
   Description("Minimum height of the zoomed image in pixels.")> _
   Public Property MinimumImageHeight As Integer
       Get
           Return _MinimumImageHeight
       End Get
       Set(value As Integer)
           _MinimumImageHeight = value
       End Set
   End Property

   <Category("_ZoomPictureBox"), _
   Description("Minimum width of the zoomed image in pixels.")> _
   Public Property MinimumImageWidth As Integer
       Get
           Return _MinimumImageWidth
       End Get
       Set(value As Integer)
           _MinimumImageWidth = value
       End Set
   End Property

   <Category("_ZoomPictureBox"), _
   Description("Sets the responsiveness of zooming to the mouse wheel. Choose a lower value for faster zooming.")> _
   Public Property MouseWheelDivisor As Integer
       Get
           Return _MouseWheelDivisor
       End Get
       Set(value As Integer)
           _MouseWheelDivisor = value
       End Set
   End Property

   <Browsable(False), _
   Description("Linear size of the zoomed image as a fraction of that of the source Image.")> _
   Public Property ZoomFactor() As Double
       Get
           Return _ZoomFactor
       End Get
       Set(ByVal value As Double)
           _ZoomFactor = ValidateZoomFactor(value)
           If _imageInitialized Then
               Me.Invalidate(_ImageBounds)
               _ImageBounds = GetZoomedBounds()
               Me.Invalidate(_ImageBounds)
           End If
       End Set
   End Property

   <Category("_ZoomPictureBox"), _
DefaultValue(ZoomType.MousePosition), _
Description("Image zooming around the mouse position, image center or control center")> _
Public Property ZoomMode() As ZoomType
       Get
           Return _ZoomMode
       End Get
       Set(ByVal value As ZoomType)
           _ZoomMode = value
       End Set
   End Property

End Class

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
How to use C++ figure this question? Collection and Sorted Collection An array is great for...
How to use C++ figure this question? Collection and Sorted Collection An array is great for storing a list of values. However, one challenge when working with arrays is they have a fixed size. If you declare an array of size 10 and later need to actually store 11 elements you have to create a new array and copy everything over. C++ (and other langauges) create classes that handle this and other operations behind the scenes. In this assignment, we...
For this assignment, you will create a BPMN diagram to depict the business process to get...
For this assignment, you will create a BPMN diagram to depict the business process to get a home mortgage based on the following narrative. You can use either DrawIO or BizAgi to create the process drawing. For this process, you can assume that the loan is a refinance not a home purchase. There are some small differences in the process to refinance an existing mortgage than to get a new mortgage. In the following narrative, I'm explaining all of the...
I've posted this question like 3 times now and I can't seem to find someone that...
I've posted this question like 3 times now and I can't seem to find someone that is able to answer it. Please can someone help me code this? Thank you!! Programming Project #4 – Programmer Jones and the Temple of Gloom Part 1 The stack data structure plays a pivotal role in the design of computer games. Any algorithm that requires the user to retrace their steps is a perfect candidate for using a stack. In this simple game you...
Write a Python 3 program called “parse.py” using the template for a Python program that we...
Write a Python 3 program called “parse.py” using the template for a Python program that we covered in this module. Note: Use this mod7.txt input file. Name your output file “output.txt”. Build your program using a main function and at least one other function. Give your input and output file names as command line arguments. Your program will read the input file, and will output the following information to the output file as well as printing it to the screen:...
Looking at quid pro quo sexual harassment and hostile work environment sexual harassment laws, if Paola...
Looking at quid pro quo sexual harassment and hostile work environment sexual harassment laws, if Paola brings a sexual harassment lawsuit against VS, who will win? Paola Innocente lives with her husband and son in South City. She is 30 years old and an Italian immigrant. She worked in the fashion industry as a model in New York City until she met her husband and they moved to his hometown, St. Louis, in 2011. Since then she held many part-time...
What is the first step in planning a presentation? Gather information Analyze the situation Practice Organize...
What is the first step in planning a presentation? Gather information Analyze the situation Practice Organize the information Select the right medium Flag this Question Question 21 pts Which of the following is one way you can be sure to speak slowly and distinctly to be better understood by an international audience? Repeat keywords and phrases Keep the message simple Communicate with body language Incorporate visual aids Articulate each word carefully Flag this Question Question 31 pts How do visuals...
what is the issue in Emaar case study ? (10marks) Emaar Properties specializes in creating value-added,...
what is the issue in Emaar case study ? (10marks) Emaar Properties specializes in creating value-added, master-planned communities that meet the full spectrum of lifestyle needs. Highlights include Downtown Dubai, the 500-acre mega-project including Burj Khalifa – the world’s tallest building, and The Dubai Mall—the world’s largest shopping and entertainment destination. Emaar is extending its expertise in developing master-planned communities internationally, and has established operations in the United Arab Emirates, Saudi Arabia, Syria, Jordan, Lebanon, Egypt, Morocco, India, Pakistan, Turkey,...
Homework Draw class diagrams for your HW4 - the Tetris Game shown below: Part 1: UML...
Homework Draw class diagrams for your HW4 - the Tetris Game shown below: Part 1: UML As a review, Here are some links to some explanations of UML diagrams if you need them. • https://courses.cs.washington.edu/courses/cse403/11sp/lectures/lecture08-uml1.pdf (Links to an external site.) • http://creately.com/blog/diagrams/class-diagram-relationships/ (Links to an external site.) • http://www.cs.bsu.edu/homepages/pvg/misc/uml/ (Links to an external site.) However you ended up creating the UML from HW4, your class diagram probably had some or all of these features: • Class variables: names, types, and...
Plagiarism Certification Tests for Undergraduate College Students and Advanced High School Students These tests are intended...
Plagiarism Certification Tests for Undergraduate College Students and Advanced High School Students These tests are intended for undergraduate students in college or those under 18 years of age. Read these directions carefully! The below test includes 10 questions, randomly selected from a large inventory. Most questions will be different each time you take the test, You must answer at least 9 out of 10 questions correctly to receive your Certificate. You have 40 minutes to complete each test, and you...
Please answer the following Case analysis questions 1-How is New Balance performing compared to its primary...
Please answer the following Case analysis questions 1-How is New Balance performing compared to its primary rivals? How will the acquisition of Reebok by Adidas impact the structure of the athletic shoe industry? Is this likely to be favorable or unfavorable for New Balance? 2- What issues does New Balance management need to address? 3-What recommendations would you make to New Balance Management? What does New Balance need to do to continue to be successful? Should management continue to invest...