Note that there are some explanatory texts on larger screens.

plurals
  1. POabnormal resizing of java.awt.Image on using getImage() and getScaledInstance()
    primarykey
    data
    text
    <p>I m making a <code>java rmi based application</code> where i pass and receive an ImageIcon object from the server... (the image is stored in a separate URL in server)</p> <p><strong>The function involves the following....</strong></p> <pre><code> 1. Getting the image from the server at first....(on button press A) 2. Replacing it with a image file in the client[optional]....(on button press B) 3. Remove the image with a default image[optional]....(on button press C) 4. Sending it back to the Server....................(On button press D)..... </code></pre> <p><strong>Here the image is displayed in a</strong><code>jlabel</code> <strong>called</strong><code>img_label</code></p> <p>The codes i've used are as follows.....</p> <p><strong>Variables used</strong></p> <pre><code> java.awt.Image img; javax.swing.ImageIcon CurrentImageIcon; javax.swing.ImageIcon DefaultImageIcon; // CurrentImageIcon contains the image to be displayed in the img_label.... // img is used for copying as well for scaling...... // DefaultImageIcon holds the default Image...... </code></pre> <p><strong>On Button Press A</strong></p> <pre><code> img = temp.getImage(); CurrentImageIcon = new ImageIcon(img); // Assuming temp holds the ImageIcon taken from the server....... img=img.getScaledInstance(83,85 , Image.SCALE_DEFAULT); img_label.setIcon(new ImageIcon(img)); img_label.revalidate(); img_label.repaint(); </code></pre> <p><strong>On Button Press B</strong></p> <pre><code> String url_text = jTextField.getText(); // taking the url frm the field..... CurrentImageIcon = new ImageIcon(url_text); img=CurrentImageIcon.getImage(); img=img.getScaledInstance(83,85 , Image.SCALE_DEFAULT); img_label.setIcon(new ImageIcon(img)); img_label.revalidate(); img_label.repaint(); </code></pre> <p><strong>On Button Press C</strong></p> <pre><code> img = DefaultImageIcon.getImage(); CurrentImageIcon = new ImageIcon(img); img=img.getScaledInstance(83,85 , Image.SCALE_DEFAULT); img_label.setIcon(new ImageIcon(img)); img_label.revalidate(); img_label.repaint(); </code></pre> <p><strong>On Button Press D</strong></p> <pre><code> // ImagetoSend is an ImageIcon to be sent to the Server..... ImagetoSend = CurrentImageIcon; CurrentImageIcon = null; </code></pre> <p>Now the problem i m getting is a weird one...... <strong>The image is getting embedded as i wanted on repainting when i click this button........</strong></p> <p><code>But when i download the recently uploaded image next time on Button press A....it is displayed either magnified or reduced to size even though i included the getScaledInstance method....</code> like this...</p> <p><img src="https://i.stack.imgur.com/4LMKG.png" alt="When i click the image. It embedds correctly"> <img src="https://i.stack.imgur.com/8Ibn8.png" alt="enter image description here"></p> <p>The image i am handling is a jpg image.... I even checked the image at Server directory.....No size change has occured on that file which was uploaded from client to server. But the change is observed when it is downloaded and embedded to the jlabel... <strong><em>Can Anyone help me to sort out this issue...??</em></strong></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload