栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何在Java中显示像素值数组中的图像?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何在Java中显示像素值数组中的图像?

image.getData()
返回栅格的 副本 。也许如果
image.setData(raster)
在修改栅格后调用,您将看到结果。

同样,应该给setPixels一个足够大的数组,以填充栅格的所有波段(A,R,G,B)。在将像素大小增加为28 * 28 *4之前,我已经获得了数组索引超出范围的异常。

对于TYPE_INT_RGB,以下内容应产生白色图像:

public class ASD{  public static Image getImageFromArray(int[] pixels, int width, int height)  {    BufferedImage image =        new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);    WritableRaster raster = (WritableRaster) image.getData();    raster.setPixels(0, 0, width, height, pixels);    image.setData(raster);    return image;  }  public static void main(String[] args) throws IOException  {    Jframe jf = new Jframe();    JLabel jl = new JLabel();    //3 bands in TYPE_INT_RGB    int NUM_BANDS = 3;    int[] arrayimage = new int[28 * 28 * NUM_BANDS];    for (int i = 0; i < 28; i++)    {      for (int j = 0; j < 28; j++) {        for (int band = 0; band < NUM_BANDS; band++)          arrayimage[((i * 28) + j)*NUM_BANDS + band] = 255;      }    }    ImageIcon ii = new ImageIcon(getImageFromArray(arrayimage, 28, 28));    jl.setIcon(ii);    jf.add(jl);    jf.pack();    jf.setVisible(true);  }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/497040.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号