2

Technical problem: On an App Engine server, I want to generate an image (ideally PNG, but not necessarily) by loading and processing a number of other PNGs. I then want to transfer this image to a client, which is programmed using GWT. I tried using the java.awt libraries, but I get

java.awt.Image is not supported by Google App Engine's Java runtime environment

Is there anything else which is available in java/gwt/App Engine that I can use to do this, or do I have to use another library? If so, is there anything you can suggest which has no dependencies to something not supported by App Engine?

Background for those who are interested: I am writing a little multi player browser game, which is about space ships. The user can construct his ship from different modules (available as PNG). On a map (Canvas class), I want to display the ships from other users, which should be a minimized version of the ship they constructed. So my ideas was to generate and save the image upon construction (which should happen not very often) and then deliver it to other users.

Mark
  • 55
  • 5

2 Answers2

1

The Image API worked fine, however transferring the image was the next problem: com.google.appengine.api.images.Image is not available on the GWT client side, I have to use com.google.gwt.user.client.ui.Image here.

One possible way was to encode the image as Base64 and transfer it as a String. Server side:

// image is an instance of com.google.appengine.api.images.Image
return "data:image/png;base64," + Base64.encodeToString(image.getImageData());

On client side, this String can be easily processed:

com.google.gwt.user.client.ui.Image image = new Image(theBase64String);

It should be noted that many Base64 implementations produce an encoding that the constructor com.google.gwt.user.client.ui.Image does not understand. See this question for details.

Community
  • 1
  • 1
Mark
  • 55
  • 5
0

I would consider the Image API and if necessary the File System API from Google - they are great and easy to use. Think you should accomplish your goal with those tools.

conFusl
  • 919
  • 6
  • 12