有一个2维数组,里面存放的是像素信息,不知道java中有没有类可以根据2维数组创建位图?

解决方案 »

  1.   

    ImageIconpublic ImageIcon(byte[] imageData)Creates an ImageIcon from an array of bytes which were read from an image file containing a supported image format, such as GIF or JPEG. Normally this array is created by reading an image using Class.getResourceAsStream(), but the byte array may also be statically stored in a class. If the resulting image has a "comment" property that is a string, then the string is used as the description of this icon.
      

  2.   

    javax.imageio    中有圖片io操作類
    嘗試下是否能把你的數據作爲數據流傳進某個操作類中
      

  3.   

    可以的 我正在弄这方面的问题 你可以通过文件读取 把数据读入内存图形源中 MemoryImageSource  然后把设置 rgb值 就上你数组中的像素值。然后
    Memoryimagesource = new MemoryImageSource(width,height,model,pix,0,width); 
    image=createImage(memoryimagesource);
    把图象显示出来
    最后把参考如何保存为位图文件的方式
    即 你要了解位图文件的头文件格式和信息
    BMPFileHeader和BMPInfoHeader
    最后
    BMPCodec.createBMPEncoder(new FileOutputStream("C:\\house\\test.bmp")).encode(image);
    就可以了