?
Solved

Spot magnification

Posted on 2005-05-04
9
Medium Priority
?
361 Views
Last Modified: 2012-06-22
I have an application that can view and edit images. I'm now trying to implement a spot magnification tool for it. This would turn the cursor into the little magnifying icon, and when dragged across the image it would enlarge the part of the Image that the cursor was currently over.

I have some ideas on how to start on this, but I was looking for a guide or some tips on what methods works best to do this. I haven't been able to find much on it yet.

-SEinarsson-
0
Comment
Question by:SEinarsson
  • 4
  • 3
  • 2
9 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 13926368
What ideas do you have?

Bob
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 13926753
You need the following variables:

bool magnifyToolActive;       // true when magnifying tool is active
bool drawMagnify;               // true when magnifying glass should be shown
int magnifyPointX;               // x-coordinate of magnifying glass center
int magnifyPointY;               // y-coordinate of magnifying glass center

When user selects Magnifying Glass tool (for example, form toolbar), set magnifyToolActive to true. When user unselects Magnifying Glass tool, set it to false.

MouseDown event handler:

if ( magnifyToolActive )
{
    this.Capture = true;
    drawMagnify = true;
    magnifyPointX = e.X;
    magnifyPointY = e.Y;
    Invalidate();
}

MouseMove event handler:

if ( drawMagnify )
{
    magnifyPointX = e.X;
    magnifyPointY = e.Y;
    Invalidate();
}

MouseUp event handler:

if ( drawMagnify )
{
    this.Capture = false;
    drawMagnify = false;
    Invalidate();
}

Paint event handler:

// draw image
// ...
if ( drawMagnify )
{
    // draw enlarged image fragment with center point (magnifyPointX, magnifyPointY center)
}


Except of this, when magnifyToolActive is true:
if drawMagnify is false, show magnifying glass cursor,
if drawMagnify is true, don't show cursor.
0
 

Author Comment

by:SEinarsson
ID: 13927460
My events are set up much like that, I have several other tools that can affect the image in different ways.

The questions come when I start looking at the details though. Am I drawing the enlarged image fragment ontop of the original image? Wouldn't that mean when the cursor leaves an area, I'd need to redraw the original part of the image back? Would that mean having to save the fragment of the original image being drawn over?

Another big question is how do I get a fragment of an image? Let's say I have a 500x500 image, how would I go about getting a 100x100 fragment from the middle of it?

-SEinarsson-
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 48

Accepted Solution

by:
AlexFM earned 1400 total points
ID: 13927588
Take a look at Graphics.DrawImage Method. It has different overloads to draw the whole image and parts of it with specified size. For example:

Graphics.DrawImage Method (Image, Rectangle, Rectangle, GraphicsUnit)
Draws the specified portion of the specified Image object at the specified location and with the specified size.

You need to draw image twice in the Paint handler: once the whole image, second time portion of the image in required place.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 13935052
And, that, my friend, will work :)

Bob
0
 

Author Comment

by:SEinarsson
ID: 13937683
Got it working, thanks.

A followup question... right now its a rectangle that follows the mouse and does the magnification. How would I got about making it draw as a circle instead.

I'm looking into graphics.DrawEllipse and graphics.FillEllipse right now, but Im not seeing how to use an image with it, just a pen and brush.

-SEinarsson-
0
 

Author Comment

by:SEinarsson
ID: 13938249
Tried using a TextureBrush to fill in the Ellipse, but DrawImage handles getting the fragmented image that is being magnified. I can set the entire image to the TextureBrush, but not sure on how to set it to only the fragment of the image I am trying to magnify.

-SEinarsson-
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 13942838
Use Graphics.Clip Property.
You need to create elliptic path - see GraphicsPath.AddEllipse Method, create region from this path - see Region Constructor (GraphicsPath), and select this elliptic region in the Graphics object using Graphics.Clip Property.
After selecting of the region you can draw rectangle, but actually drawing will be done only inside of elliptic clipping region.
0
 

Author Comment

by:SEinarsson
ID: 13961990
Thanks, it all works now.

-Sarkis-
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month17 days, 7 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question