Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何操作BuffereImage_Java_Image Processing_Processing_Bufferedimage - Fatal编程技术网

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制作彩色图像灰度怎么样?使用一些着色过滤器?模糊它?磨快它?好的,你抓到我了。我倾向于在图像操作方面做得更少。:)