Jump to content

  • Log In with Google      Sign In   
  • Create Account

Magnifier Tool


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Getov   Members   -  Reputation: 471

Like
0Likes
Like

Posted 18 December 2012 - 09:45 AM

Hi, I did make some simple magnifier tool - a rectangle screen that zooms the content in it. But I got stuck at one place. I made it to capture the screen only once and added an option to refresh (recapture the screen). What I want to do is I want it to capture the screen constantly (say every 0.5 seconds), like the Windows Magnifier Tool. I guess what I have to do but I am not sure how to implement it.
That's my code so far:
http://pastebin.com/2qnBh23g
http://pastebin.com/qE5g7E24

I added a Timer to capture the screen every second:

[source lang="java"]time = new Timer(1000, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { magnifierPanel.getScreen(); } }); time.start();[/source]
The problem here is that each time it captures the screen , it also captures the magnifier itself and it's kinda broken way to do it.

After that I tried:
[source lang="java"]time = new Timer(1000, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setVisible(false); magnifierPanel.getScreen(); setVisible(true); } }); time.start();[/source]
But in this case , the whole magnifier area (the rectangle screen in my case) is blinking, because it constantly swaps between setVisible - false and true.

I will be glad if you help me to find a solution ! Thanks Posted Image .

Sponsor:

#2 vsg1990   Members   -  Reputation: 252

Like
0Likes
Like

Posted 19 December 2012 - 02:34 AM

From the looks of it, and from a Google search, it seems that createScreenCapture simply takes too long for what you are trying to do. I don't think Java has any built in methods that are fast enough for what you are trying to achieve. Maybe look for some sort of native library for the os you are running it on? Also I changed setVisible to setOpacity since it doesn't make the taskbar icon blink constantly.

--Vince

Edited by vsg1990, 19 December 2012 - 02:35 AM.


#3 Getov   Members   -  Reputation: 471

Like
0Likes
Like

Posted 19 December 2012 - 05:15 AM

My OS is Windows 7 64 bit, setOpacity doesn't seem to work fine for me. I'll be glad if you have any other ideas and if someone know specific library for doing that job. I did find JxCaputre library but I don't know if it will be of any use.

#4 PsychotikRabbit   Members   -  Reputation: 171

Like
0Likes
Like

Posted 19 December 2012 - 08:02 AM

Instead of creating a screenshot with a timer can't you just use the original image and scale it when its painted ?

I did not write this code, it seems to do what you need to do by scaling the image with AffineTransform on its paint. Of course you would adjust the scaling
depending on the zoom of your magnifier.

	protected void paintComponent(Graphics g)
	{
		super.paintComponent(g);
		Graphics2D g2 = (Graphics2D)g;
		g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
							RenderingHints.VALUE_INTERPOLATION_BICUBIC);
		int w = getWidth();
		int h = getHeight();
		int imageWidth = image.getWidth();
		int imageHeight = image.getHeight();
		double x = (w - scale * imageWidth)/2;
		double y = (h - scale * imageHeight)/2;
		AffineTransform at = AffineTransform.getTranslateInstance(x,y);
		at.scale(scale, scale);
		g2.drawRenderedImage(image, at);
	}

With this it won't flicker anymore because you won't need to use setVisible and to take a bunch of screenshots every second.

Edited by PsychotikRabbit, 19 December 2012 - 08:04 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS