How to join 2 images in Google engine in Java

I saw python codes to combine two images in the google engine using "compound". But I need Java codes to use "composite" to combine the two images. Show the actual code will be very useful.

+5
source share
1 answer

This is my first answer, so I hope they don’t hammer me too badly. Since no one answered this, and I spent a little time on it today, I thought that I would provide some code.

The main reason why it took me too much time is because for some reason, the DevServer simulation of the image API is not working correctly, and composite images are incorrect when using devserver. I always behaved with values ​​in devserver until I just loaded the test code into AppEngine and it worked as expected. Argg!

In any case, the code below assumes that you have two 300x300 images, one in aImage and the other in bImage, which you want to paste side by side in a new canvas with a size of 600x300, which is created in the resulting Image newImage:

List<Composite> listComposites=new ArrayList<Composite>();

Composite aPaste = ImagesServiceFactory.makeComposite(aImage, 0, 0, 1f, Composite.Anchor.TOP_LEFT);
listComposites.add( aPaste );

Composite bPaste = ImagesServiceFactory.makeComposite(bImage, 300, 0, 1f, Composite.Anchor.TOP_LEFT);
listComposites.add( bPaste );

Image newImage = imagesService.composite(listComposites, 600, 300, 0xff333333L, ImagesService.OutputEncoding.JPEG);

makeComposite 0,0 TOP_LEFT. makeComposite 300,0. 1.0. . JPEG. , , devserver, App Engine.

+8

All Articles