【问题标题】:ArrayIndexOutOfBoundsException while trying to scale尝试缩放时出现 ArrayIndexOutOfBoundsException
【发布时间】:2016-11-18 13:35:24
【问题描述】:

一直在尝试将视图缩小到不同的比例,但我遇到了一些麻烦。上下文在视频播放器内(使用 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)

我明白这个问题我只是不知道如何解决它! 谢谢!

【问题讨论】:

  • 您要缩放的图像有多大?以像素为单位
  • image.setRGB 是做什么的?
  • 因为它是现实中的视频流,我不能说我很确定。但我很确定它是 1920x1080!
  • 简化 image.setRGB 将缓冲区写入图像。
  • 我不怀疑你很确定。 ;-) 我只是告诉你堆栈跟踪另有说明。您不会超过方法中的第一行。问题是您的size 成员变量与作为rgbBuffer 传入的尺寸不匹配。

标签: java scale bufferedimage libvlc vlcj


【解决方案1】:

经过大量错误搜索后,我最终得到了这段工作代码!

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-07
    • 1970-01-01
    • 2020-09-01
    相关资源
    最近更新 更多