CIMG to PNG to CIMG

  • Basically the CIMG format is just a PNG image with some additional data (e.g. information about the uploader, original image name and dimensions etc).


    The first two bytes contain the "image version" (just ignore this), and the next four bytes contain the actual data length (number of bytes). When writing a plugin, you could use this code to turn a CIMG-File into a PNG byte[] (using the API Utils class):


    The next update will contain a method to convert a (png) byte array into a buffered image and vice versa. But it's fairly simple to convert a byte[] into a buffered image (using the javax ImageIO class). This code turns our "pngData" byte[] into a buffered image:

    Java
    try(ByteArrayInputStream bis = new ByteArrayInputStream(pngData)){
    BufferedImage bufferedImage = ImageIO.read(bis);
    }
    catch(IOException e){
    //error occurred
    }

Participate now!

Don’t have an account yet? Create a new account now and be part of our community!