从rgb像素值创建缓冲的图像 [英] Create a buffered image from rgb pixel values

查看:128
本文介绍了从rgb像素值创建缓冲的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个RGB像素的整数数组,看起来像:

I have an integer array of RGB pixels that looks something like:

pixels[0] = <rgb-value of pixel(0,0)>
pixels[1] = <rgb-value of pixel(1,0)>
pixels[2] = <rgb-value of pixel(2,0)>
pixels[3] = <rgb-value of pixel(0,1)>
...etc...

我正在尝试从中创建一个BufferedImage.我尝试了以下方法:

And I'm trying to create a BufferedImage from it. I tried the following:

BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
img.getRaster().setPixels(0, 0, width, height, pixels);

但是所得图像的色带存在问题.图像不清楚,并且有对角线和水平线.

But the resulting image has problems with the color bands. The image is unclear and there are diagonal and horizontal lines through it.

用rgb值初始化图像的正确方法是什么?

What is the proper way to initialize the image with the rgb values?

这是我的图像的样子

Here is what my image looks like

谢谢, 杰夫

推荐答案

尝试使用setDataElements代替setPixels.

另一个选择是让图像共享阵列而不是从阵列复制(请参见

Another option is for the image to share the array instead of copying from it (see this answer for an example.)

这篇关于从rgb像素值创建缓冲的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆