java drawimage 看不到图像_java – BufferedImage不显示(全黑)但可以显示Image

我是

Java图形(一般的计算机图形学)和Stack Overflow的新手,所以请帮助我,帮助我更好地表达我的问题.

目前,我正在尝试在Java GUI中与原始图像一起显示BufferedImage.这是我的代码:

Image oriImage = robot.getQwerkController().getVideoStreamService().getFrame(); //load the original image

Graphics2D hi = bufferedImage.createGraphics();

hi.drawImage(oriImage, 0,0, null); //draw the original image into the BufferedImage

hi.dispose();

images[0].put(oriImage, 1); //draws the original image in the first frame

images[1].put(bufferedImage, 2); //draws the BufferedImage in the second frame

而“put”功能如下:

public synchronized void put(Image image, int frameNumber) {

icon.setImage(image); //sets the image displayed by this icon

display.paintImageIcon(icon, frameNumber); //paint the image onto the gui

imageSet = true;

notifyAll();

}

但是,生成的GUI如下所示

所以Image工作,但BufferedImage没有.我认为它有效,因为BufferedImage是Image的子类…

任何的想法?如果需要其他代码,请告诉我〜提前致谢:)

编辑1:

我做了一些测试,而不是使用原始图像,我创建了一个全新的bufferedImage,并使用Graphics2D绘制一条线,然后尝试显示它.

这是结果:

所以它有效.因此原始图像(或发生的转换)必定有问题

编辑2:

我用bufferedImage做了类似的事情,画了一条线.结果与EDIT 1相同,因此我认为drawImage函数存在一些问题.

编辑3:

我通过在drawImage周围放置一个while循环来解决问题,让它完成图像绘制(因为如果还没有完成绘制图像,它会返回false)并且它有效! :d

boolean x = false;

while (!x) {

x = hi.drawImage(oriImage, 0,0, null); //draw the original image into the BufferedImage

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值