2

我正在制作一个java rmi based application我从服务器传递和接收 ImageIcon 对象的地方......(图像存储在服务器中的单独 URL 中)

该功能涉及以下......

        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).....

这里的图像显示在一个jlabel 叫做img_label

我使用的代码如下......

使用的变量

                   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......

开启按钮按下 A

                   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();

开启按钮按下 B

                   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();

开按钮 按 C

                   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();

开按钮 按 D

                   // ImagetoSend is an ImageIcon to be sent to the Server.....
                   ImagetoSend = CurrentImageIcon;
                   CurrentImageIcon = null;

现在我遇到的问题是一个奇怪的问题...... 当我点击这个按钮时,图像正在嵌入,因为我想要重新绘制......

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.... 像这样...

当我单击图像时。 它正确嵌入 在此处输入图像描述

我正在处理的图像是 jpg 图像......我什至检查了服务器目录中的图像......从客户端上传到服务器的那个文件没有发生大小变化。但是当它被下载并嵌入到 jlabel 中时会观察到变化...... 任何人都可以帮我解决这个问题......??

4

1 回答 1

1

不知何故,它被缩小了两倍。要么缩小它,然后将它发送到缩小它的服务器,要么点击两个按钮来缩放它。消除服务器端的缩减代码,看看会发生什么。

于 2012-07-05T15:28:24.407 回答