I want to pass an instance of ImageIcon by value, since we know that by default it is a link to a link by value. Is there any way to solve this problem?
ImageIcon img1 = new ImageIcon(); ImageIcon img2 = new ImageIcon(); img1 = img2;
I tried using ImageIcon getImage() and setImage() .
But in fact, my program includes writing the image to a file and the image quality seems to be changing.
In short, there is a way in which when using the function
img1 = func(img2); // both do not share the same refernce. But the value is copied
At least how can I maintain the exact image quality when using getImage() or setImage() ?
Additional information on request.
The one I use is a jpg image, and I included the function in the same way as image = img1.getimage ();
img2.setImage (image);
I supported a separate java class, where it contained the default image ImageIcon containg jpg, and I extract the image from it using some of the class methods, for example
ImageIcon defaulticon = new ImageIcon("d:\\default.jpg"); public void getdefaultimage(ImageIcon img) { img.setImage(defaulticon.getImage()); }
source share