Java 如何操作BuffereImage
Java 如何操作BuffereImage,java,image-processing,processing,bufferedimage,Java,Image Processing,Processing,Bufferedimage,Processing有一个名为PImage的类,您可以从中获得包含所有像素值的int数组。然后,操纵这个数组并调用updatePixels(),瞧,您已经对图像应用了效果 我想知道在BufferedImage中是否可以通过适当的机制实现同样的功能。我发现,buffereImage确实有一种方法可以将像素获取为int[]: public int[] getRGB(int startX, int startY, int
Processing
有一个名为PImage
的类,您可以从中获得包含所有像素值的int
数组。然后,操纵这个数组并调用updatePixels()
,瞧,您已经对图像应用了效果
我想知道在BufferedImage
中是否可以通过适当的机制实现同样的功能。我发现,buffereImage
确实有一种方法可以将像素获取为int[]
:
public int[] getRGB(int startX,
int startY,
int w,
int h,
int[] rgbArray,
int offset,
int scansize)
Returns an array of integer pixels in the default RGB color model (`TYPE_INT_ARGB`) and default sRGB color space, from a portion of the image data.
Color conversion takes place if the default model does not match the image `ColorModel`.
There are only 8-bits of precision for each color component in the returned data when using this method.
如何修改这些像素并在buffereImage
中显示相应的更改
我想我需要为图像获取一个可写光栅
,并使用它
public void setPixels(int x,
int y,
int w,
int h,
int[] iArray)
但是我仍然不确定。PImage类与
BuffereImage
类集成了一点:
//BufferedImage to PImage
PImage img = new PImage(yourBufferedImageInstance);
//PImage to BufferedImage
BufferedImage img = (BufferedImage)yourPImageInstance.getNative();
PImage
类与buffereImage
类集成了一个位:
//BufferedImage to PImage
PImage img = new PImage(yourBufferedImageInstance);
//PImage to BufferedImage
BufferedImage img = (BufferedImage)yourPImageInstance.getNative();
要创建
可写光栅
,必须首先选择颜色模型
。
我认为RGB默认值应该适合您的需要
ColorModel colorModel = ColorModel.getRGBdefault();
WritableRaster raster = colorModel.createCompatibleWritableRaster(width, height);
然后,您可以用像素填充它,并创建一个新的buffereImage
raster.setPixels(0, 0, width, height, pixels);
BufferedImage image = new BufferedImage(colorModel, raster, true, null);
作为提醒,这里有一种从缓冲区图像中提取像素的方法:
Raster raster = bufferedImage.getRaster();
int[] pixels = raster.getPixels(0, 0, raster.getWidth(), raster.getHeight(), (int[]) null);
要创建可写光栅
,必须首先选择颜色模型
。
我认为RGB默认值应该适合您的需要
ColorModel colorModel = ColorModel.getRGBdefault();
WritableRaster raster = colorModel.createCompatibleWritableRaster(width, height);
然后,您可以用像素填充它,并创建一个新的buffereImage
raster.setPixels(0, 0, width, height, pixels);
BufferedImage image = new BufferedImage(colorModel, raster, true, null);
作为提醒,这里有一种从缓冲区图像中提取像素的方法:
Raster raster = bufferedImage.getRaster();
int[] pixels = raster.getPixels(0, 0, raster.getWidth(), raster.getHeight(), (int[]) null);
(歪着头)你想如何操纵它们?根据我的喜好,我更喜欢使用BufferedImage
,获得Graphics2D
,然后能够通过使用仿射变换、剪裁、笔划、渐变、渲染提示绘制东西(直线、椭圆、文本、图像..)来更改它。。在容器上调用repaint()
,它就会出现在屏幕上。@andrewhompson制作彩色图像灰度怎么样?使用一些着色过滤器?模糊它?磨快它?好的,你抓到我了。我倾向于在图像操作方面做得更少。:)(歪着头)你想如何操纵它们?根据我的喜好,我更喜欢使用BufferedImage
,获得Graphics2D
,然后能够通过使用仿射变换、剪裁、笔划、渐变、渲染提示绘制东西(直线、椭圆、文本、图像..)来更改它。。在容器上调用repaint()
,它就会出现在屏幕上。@andrewhompson制作彩色图像灰度怎么样?使用一些着色过滤器?模糊它?磨快它?好的,你抓到我了。我倾向于在图像操作方面做得更少。:)