Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411807 Posts in 69416 Topics- by 58462 Members - Latest Member: Moko1910

May 29, 2024, 01:43:17 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)[Java] Zooming & Grid
Pages: [1]
Print
Author Topic: [Java] Zooming & Grid  (Read 1195 times)
mesotes
Level 0
**


<3


View Profile
« on: May 27, 2010, 04:25:41 PM »

hello everyone.

Im currently developing a kind of pixel editor. therefore, zoom functionality is mandatory.
I want to avoid posting all the code, so I hope this overview of how the app is structured is enough to get the idea.

I have these classes:

Painter (extends JApplet):
The main class here I do stuff so the PaintScrolling shows up

PaintScrolling (extends JScrollpane implements MouseWheelListener)
In here I have a PaintPanel "_canvas" and the zoom functionality which currently looks like this:
Code:
public void zoomOut(final MouseWheelEvent e)
    {
        // Get the mouse position with respect to the zoomPanel
        final Point pointOnZoomPanel = SwingUtilities.convertPoint(
                        e.getComponent(), e.getPoint(), _canvas);

        // Resize panel
        final Dimension currSize = _canvas.getSize();
        _canvas.setPreferredSize(
                        new Dimension(
                                        (int)(currSize.width * ZOOM_OUT_FACTOR),
                                        (int)(currSize.height * ZOOM_OUT_FACTOR) ));

        // find out where our point on the zoom panel is now that we've resized it
        final Point newViewPos = new Point();
        newViewPos.x = (int)((ZOOM_OUT_FACTOR * currSize.width) * (e.getPoint().x/(double)currSize.width));
        newViewPos.y = (int)((ZOOM_OUT_FACTOR * currSize.height) * (e.getPoint().y/(double)currSize.height));
       
        // move the viewport to the new position to keep the area our mouse was in the same spot
        getViewport().setViewPosition(newViewPos);

        _canvas.revalidate();
        repaint();
    }

PaintPanel (extends JPanel implements Mousestuffs)
This is the actual canvas I draw on..
In here youll find the BufferedImage.


My question is: What do I need to do to scale the image and gets all pixely?
So I want to draw in such a state of course but how do I "translate" it back
into the original image..

Also, I want to add a Pixelgrid.. which makes me confused everytime I think about it Sad
I absolutely have no idea how I should do that.. Sad

On request I could upload the source.

Thanks for your help and time.
Logged
oahda
Level 10
*****



View Profile
« Reply #1 on: May 27, 2010, 05:00:33 PM »

Is there no way for you to retrieve the colour of each pixel in the image?
That way you should be able to just loop through the pixels, copy their colour, draw a rectangle of the desired size at the proper position, and move on to the next pixel until you've drawn the image at a larger scale.
Logged

mesotes
Level 0
**


<3


View Profile
« Reply #2 on: May 27, 2010, 05:15:49 PM »

that sounds horrible slow.
otherwise i cant imagine another way to make a grid possible.
when i draw pixel per pixel that way, i could leave space to draw the grid.
that would "solve" the grid problem..
Logged
oahda
Level 10
*****



View Profile
« Reply #3 on: May 28, 2010, 06:57:37 AM »

that sounds horrible slow.
otherwise i cant imagine another way to make a grid possible.
when i draw pixel per pixel that way, i could leave space to draw the grid.
that would "solve" the grid problem..
As I quick solution, I mean. One could always go ahead and work with complex algorithms.
I understood this as a pixel editor for reasonably small images, so for them, it wouldn't be too slow, I guess.
I also, for some reason, thought of this as a private editor rather than a public project, in which case it wouldn't be as important either, but maybe I was wrong. I don't know why I assumed that.
I guess it's not bad to try, though, just to see how slow it actually is.
Logged

Dacke
Level 10
*****



View Profile
« Reply #4 on: May 28, 2010, 07:10:04 AM »

I think this may be helpful. Java image filters. There is a zoom example at the bottom of the page.
http://java.sun.com/docs/books/tutorial/2d/images/drawimage.html
Logged

programming • free software
animal liberation • veganism
anarcho-communism • intersectionality • feminism
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic