Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8179873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:05:41+00:00 2026-06-07T00:05:41+00:00

I want to pass an ImageIcon instance by value as we know that by

  • 0

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.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T00:05:42+00:00Added an answer on June 7, 2026 at 12:05 am

    If you want to copy an ImageIcon you could try: img2 = new ImageIcon(img1.getImage()); I would make sure that I read in and wrote out .png (lossless) images, not .jpg (lossy) images.

    But this should have no bearing on image quality, and I doubt will solve your problem. I fear your problem lies elsewhere in code not shown, that you may be degrading your image quality by resizing the image or by storing and retrieving it via lossy methods such as with .jpg files, or by reducing the number of bytes per pixel…

    Otherwise if you’re still having problems, consider telling us more about the problems because again I fear that the problem is more with the loss of image quality than in the sharing of references.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to pass an integer value to a form in .Net so that
I want to pass around some values in an array that will always be
I want to pass external XML a variable. How do I do this? WHAT
I want pass a parameter of javascript functiona which is a string. This javascript
I want to pass an array of key-value pairs as an argument to a
I want to pass the parameter that List.sortBy takes through to another function. My
I want pass a value to ssis package, but i have an error back
I want to pass a keydown event to another element. Along the way I
i want to pass the value of a datetimepicker to my Codebehind(C#) and save
I want to pass value of i as a parameter for autosuggest. My intention

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.