I'm trying to resize my BufferedImage (my drawing area) without losing drawn figures on image and resume to draw after resizing.(Like in Paint.NET) I'm doing this with JSplitPane from edges and it's happening but when I want to resume to draw, the cursor (the pen) has been about 3 cm away from the drawn figure(shape) because the figures grow with image. It just gets better when I remove the whole picture. and
I looked at the answers in Google and StackoverFlow, but it did not work with me.How can I get rid of this issue?
I tried like this so far:
Class UI
jSplitPane.addPropertyChangeListener(JSplitPane.DIVIDER_LOCATION_PROPERTY, (PropertyChangeEvent evt) -> {
double imageHeight = jSplitPane.getDividerLocation();
double imageWidth = imageHeight * 1.6;
top.setDividerLocation((int) imageWidth);
drawGround.changeImageSizeDynmcally((int) imageWidth, (int) imageHeight);
drawGround.repaint();
});
Class DrawGround
BufferedImage masterImage = new BufferedImage(AREA_WIDTH, AREA_HEIGHT, BufferedImage.TYPE_INT_ARGB);
//image is master image drawing at first time.
public void changeImageSizeDynmcally(int w, int h) {
AREA_WIDTH = w;
AREA_HEIGHT = h;
repaint();
BufferedImage scaledImage = new BufferedImage(AREA_WIDTH, AREA_HEIGHT, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2D = scaledImage.createGraphics();
g2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2D.drawImage(masterImage, 0, 0, null);
g2D.dispose();
}
After this method I have
`@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
if (masterImage != null) {
g2D = (Graphics2D) masterImage.getGraphics();
g2D.setComposite(AlphaComposite.Src);
bla,bla,bla`