Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert byte array to image in Java using Google apps engine

so far i m trying

BufferedImage img = ImageIO.read(new ByteArrayInputStream(bytes));

but its give an error does don't support ImageIO in Apps engine.

like image 486
Prashant Khaire Avatar asked Jun 04 '26 23:06

Prashant Khaire


2 Answers

The Image service Java API lets you apply transformations to images, The app prepares an Image object with the image data to transform, and a Transform object with instructions on how to transform the image, Check this link

 byte[] oldImageData;  // ...

        ImagesService imagesService = ImagesServiceFactory.getImagesService();

        Image oldImage = ImagesServiceFactory.makeImage(oldImageData);
        Transform resize = ImagesServiceFactory.makeResize(200, 300);

        Image newImage = imagesService.applyTransform(resize, oldImage);

        byte[] newImageData = newImage.getImageData();
like image 198
Mangesh Mandavgane Avatar answered Jun 06 '26 13:06

Mangesh Mandavgane


App Engine works in a sandbox, thus a lot of Java libraries are not accessible. For details, see this link [1].

The workaround provided in the other answer let's your buffer an image but it doesn't directly answer your question why you got the ImageIO error.

[1] - JRE whitelist for Google App Engine - https://cloud.google.com/appengine/docs/java/jrewhitelist

like image 30
Ying Li Avatar answered Jun 06 '26 13:06

Ying Li