如何将WritableRaster转换为字节数组?

时间:2015-10-05 14:37:29

标签: java thumbnails

我想将WritableRaster转换为字节数组,但无法转换为DataBufferByte

        BufferedImage thumbnail = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
        thumbnail.createGraphics().drawImage(ImageIO.read(imageFile).getScaledInstance(100, 100, Image.SCALE_SMOOTH),0,0,null);


        WritableRaster raster = thumbnail.getRaster();

        // throws ClassCastException
        // java.awt.image.DataBufferInt cannot be cast to java.awt.image.DataBufferByte
        DataBufferByte imgData = (DataBufferByte) raster.getDataBuffer();

        byte[] data = imgData.getData();

0 个答案:

没有答案