尝试缩放时出现 ArrayIndexOutOfBoundsException
ArrayIndexOutOfBoundsException while trying to scale
一直在尝试将视图缩小到不同的比例,但我遇到了一些麻烦。上下文在视频播放器中(使用 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)
我明白这个问题我只是不知道如何解决它!
谢谢!
经过大量错误搜索后,我得到了这段有效代码!
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();
}
这是一个微小的变化,但它起到了作用!认为最好 post 它以防万一有人再次找到这里。
感谢您的帮助! :)
一直在尝试将视图缩小到不同的比例,但我遇到了一些麻烦。上下文在视频播放器中(使用 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)
我明白这个问题我只是不知道如何解决它! 谢谢!
经过大量错误搜索后,我得到了这段有效代码!
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();
}
这是一个微小的变化,但它起到了作用!认为最好 post 它以防万一有人再次找到这里。 感谢您的帮助! :)