I want to pass an ImageIcon instance by value as we know that by default it is pass reference by value. Is there any way to sort out this issue?
ImageIcon img1 = new ImageIcon();
ImageIcon img2 = new ImageIcon();
img1 = img2; // both share the same reference.......
I tried using ImageIcon's getImage()
and setImage()
.
But actually my program includes writing image to file and the quality of the image seems to change.
In short is there a way by which on using a function
img1 = func(img2); // both do not share the same refernce. But the value is copied
At least how can I retain the exact image quality on using getImage()
or setImage()
?
Some additional information as per request.
The one I'm using is a jpg image, and I've included the function exactly as
image = img1.getimage();
img2.setImage(image);
I've maintained a separate java class where it holds the default ImageIcon containg jpg image and I'm retrieving the image from it using some of the class methods like
ImageIcon defaulticon = new ImageIcon("d:\\default.jpg");
public void getdefaultimage(ImageIcon img)
{
img.setImage(defaulticon.getImage());
}
// The class which I maintained specifically for this purpose is a pure java class.