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:
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
I absolutely have no idea how I should do that..
On request I could upload the source.
Thanks for your help and time.