尝试扩展时出现ArrayIndexOutOfBoundsException

时间:2016-11-18 13:35:25

标签: java scale bufferedimage libvlc vlcj

一直试图将视图缩小到不同的规模,但我遇到了一些麻烦。上下文位于视频播放器内(使用VLCJ)。

此代码用于缩放图像,但在第一帧之后,由于某种原因,图像停止使用下一张图像进行更新。

public void newFrameRecieved(int[] rgbBuffer)
{
    this.image.setRGB(0, 0, this.size.width, this.size.height, rgbBuffer, 0, this.size.width);


    after = new BufferedImage(this.getWidth(), this.getHeight(), this.image.getType());
    at = new AffineTransform();
    scalingFactorX = (double)this.getWidth()/ (double)this.image.getWidth();
    scalingFactorY = (double)this.getHeight()/ (double)this.image.getHeight();
    at.scale(scalingFactorX, scalingFactorY);
    scaleOp = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
    this.image = scaleOp.filter(this.image, after);


    repaint();
}

如果中间部分(this.image.setRGB(......)和repaint();之间的所有代码都被删除,那么它可以工作(除了缩放部分......)

非常感谢你们提供的任何帮助! 收到的错误如下:

JNA: Callback uk.co.caprica.vlcj.player.direct.DefaultDirectMediaPlayer$DisplayCallback@4516af24 threw the following exception:
java.lang.ArrayIndexOutOfBoundsException: Coordinate out of bounds!
    at sun.awt.image.IntegerInterleavedRaster.setDataElements(IntegerInterleavedRaster.java:301)
    at java.awt.image.BufferedImage.setRGB(BufferedImage.java:1059)
    at myVlcjWrapper.VideoSurfacePanel.newFrameRecieved(VideoSurfacePanel.java:65)

我理解这个问题我对如何修复它一无所知! 谢谢!

1 个答案:

答案 0 :(得分:0)

在做了很多错误搜索后,我最终得到了这段工作代码!

public void newFrameRecieved(int[] rgbBuffer, Dimension max)
{
    before = new BufferedImage(max.width, max.height, BufferedImage.TYPE_INT_ARGB);
    before.setRGB(0, 0, max.width, max.height, rgbBuffer, 0, max.width);
    after = new BufferedImage(this.getWidth(), this.getHeight(), this.image.getType());
    at = new AffineTransform();
    scalingFactorX = (double)after.getWidth()/ (double)before.getWidth();
    scalingFactorY = (double)after.getHeight()/ (double)before.getHeight();
    at.scale(scalingFactorX, scalingFactorY);
    scaleOp = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
    this.image = scaleOp.filter(before, after);

    repaint();
}

这是一个微小的变化,但它做到了!最好发布它以防万一有人再次在这里找到他们的方式。 谢谢你的帮助! :)