【发布时间】:2023-03-28 10:52:01
【问题描述】:
所以我有一个表示像素数据(8 位灰度)的字节数组。没有标题。没什么。只是数据。我想从这些数据中创建一个缓冲图像。我做了
image = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_GRAY);
image.getRaster().setDataElements(0, 0, w, h, data);
this.x = w;
this.y = h;
scalemode=false;
exactmode=true;
其中 w 是像素宽度,h 像素高度,data 是字节数组,图像是 BufferedImage
这是我的绘画方法
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
int rx = (this.getWidth() - x) / 2;
int ry = (this.getHeight() - y) / 2;
g2d.drawImage(image, rx, ry,x,y, null);
}
然而,我得到了这张图片(真实的图片是指纹,大部分是白色像素)
出了什么问题?我尝试按原样保存数据,然后在 Photoshop 中查看。数据很好。
[编辑] 别管这个问题。我搞砸了代码的其他部分并且不知道。感谢您的所有投入
【问题讨论】:
-
data是什么类型? -
数据为 byte[] 1byte = 1pixel
-
在每个像素上绘制每个字节...
-
那是图像的 1 像素边框部分吗?
-
没有边框不是图片的一部分
标签: java image bufferedimage grayscale