小编Jis*_*mud的帖子

程序不访问扩展JPanel类的方法paintComponent()

这是 JFrame

package client.connection;

import java.awt.Dimension;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import javax.swing.JFrame;


class DrawFrameRemoteControl extends JFrame
{
    private DrawPanelRemoteControl imagePanel;
    private ClientRemoteControlConnection clientRemoteControlConnection;
    private ObjectInputStream clientInputStream;
    private ObjectOutputStream clientOutputStream;
    private Dimension imageDimension;
    private Dimension serverDimension;

    public DrawFrameRemoteControl(Dimension imageDimension,ClientRemoteControlConnection clientRemoteControlConnection,ObjectInputStream clientInputStream,ObjectOutputStream clientOutputStream,Dimension serverDimension)
    {
        super("Remote Desktop Control");

        this.clientRemoteControlConnection=clientRemoteControlConnection;
        this.clientInputStream=clientInputStream;
        this.clientOutputStream=clientOutputStream;
        this.imageDimension=imageDimension;
        this.serverDimension=serverDimension;

        imagePanel=new DrawPanelRemoteControl(imageDimension);
        add(imagePanel);


        setSize(imageDimension.width,imageDimension.height);
        setResizable(false);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setVisible(true);
        setLocationRelativeTo(null);
    }

    void drawNewImageGrayscale(byte[] array)
    {
        imagePanel.setNewImageGrayscale(array);
        imagePanel.repaint();
    }
}
Run Code Online (Sandbox Code Playgroud)

这是扩展的JPanel类 -

package client.connection;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit; …
Run Code Online (Sandbox Code Playgroud)

java swing jpanel jframe repaint

5
推荐指数
1
解决办法
1972
查看次数

如何缩小BufferedImage的大小和质量?

我正在开发一个项目,一个名为"远程桌面控制"的客户端 - 服务器应用程序.我需要做的是拍摄客户端计算机的屏幕截图并将此屏幕捕获发送到服务器计算机.我可能需要每秒发送3到5张图像.但考虑到BufferedImage直接发送对于该过程来说成本太高,我需要减小图像的大小.图像质量不必损失较少.

如何减小图像的字节大小?有什么建议?

java screenshot image screen-capture

3
推荐指数
1
解决办法
1130
查看次数

通过GZIP流读取和写入对象?

我是Java新手.我想学习使用GZIPstreams.我已经尝试过这个:

ArrayList<SubImage>myObject = new ArrayList<SubImage>(); // SubImage is a Serializable class

ObjectOutputStream compressedOutput = new ObjectOutputStream(
   new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(
   new File("....")))));
compressedOutput.writeObject(myObject);
Run Code Online (Sandbox Code Playgroud)

ObjectInputStream compressedInput = new ObjectInputStream(
   new BufferedInputStream(new GZIPInputStream(new FileInputStream(
   new File("....")))));
myObject=(ArrayList<SubImage>)compressedInput.readObject();
Run Code Online (Sandbox Code Playgroud)

当程序写入myObject文件时不会抛出任何异常,但是当它到达该行时

myObject=(ArrayList<SubImage>)compressedInput.readObject();
Run Code Online (Sandbox Code Playgroud)

它抛出此异常:

Exception in thread "main" java.io.EOFException: Unexpected end of ZLIB input stream
Run Code Online (Sandbox Code Playgroud)

我怎么解决这个问题?

java compression gzip stream gzipinputstream

3
推荐指数
1
解决办法
4836
查看次数

从字节数组创建8位图像

字节数组以这种方式获得 -

BufferedImage image = new Robot().createScreenCapture(new Rectangle(screenDimension));
byte[] array = ((DataBufferByte)getGraycaleImage(image).getRaster().getDataBuffer()).getData();
//  Method getGraycaleImage returns a grayscaled BufferedImage, it works fine
Run Code Online (Sandbox Code Playgroud)

现在我如何从字节数组重建这个灰度图像?

我对ARGB,RGB或灰度图像知之甚少.我试过这个 -

private Image getGrayscaleImageFromArray(byte[] pixels, int width, int height)
{
    int[] pixels2=getIntArrayFromByteArray(pixels);
    MemoryImageSource mis = new MemoryImageSource(width, height, pixels2, 0, width);
    Toolkit tk = Toolkit.getDefaultToolkit();
    return tk.createImage(mis);
}

private int[] getIntArrayFromByteArray(byte[] pixelsByte)
{
    int[] pixelsInt=new int[pixelsByte.length];
    int i;
    for(i=0;i<pixelsByte.length;i++)
        pixelsInt[i]=pixelsByte[i]<<24 | pixelsByte[i]<<16
| pixelsByte[i]<<8 | pixelsByte[i];  // I think this line creates the problem
    return pixelsInt; …
Run Code Online (Sandbox Code Playgroud)

java rgb image-processing grayscale argb

2
推荐指数
1
解决办法
5598
查看次数

JAVA:处理插座断开连接

  1. 两台计算机通过套接字连接.如果服务器/客户端从它们的末端关闭连接(即关闭InputStream,OutputStreamSocket),那么如何通知另一端断开连接?有一种我知道的方法 - 尝试从中读取InputStream,这会抛出IOExceptionif连接关闭,但还有其他方法可以检测到这种情况吗?
  2. 另一个问题,我在互联网上看了问题,看到inputStream.available() 并没有解决这个问题.这是为什么?

附加信息:我要求采用另一种方式,因为如果我必须尝试读取InputStrem断开连接,我的项目将变得难以处理 .

java sockets inputstream outputstream stream

0
推荐指数
1
解决办法
1万
查看次数