that’s my first time here. Hope someone can give us a hint!
We are stuck while transforming images on google app engine with Java. We
basically want to achieve the following:
1) Generate a QRCode using google chartapi – DONE
2) Use urlfetch to get the qrcode just generated and use pngw/pngr
(image library for appengine) to read and modify the pixels on the
image – DONE
Now we have no idea how to:
3) save the modified image on a blobstore to then be able to show on
screen using blobstore api.
*we used the library locally and saving locally C:\test.png works
just fine.
The code is below:
* We have used a pngr library which use InputStream for the PngReader
instead of File. It works App Engine for reading and modifying pixel
by pixel data from a PNG. http://github.com/jakeri/pngj-for-Google-App-Engine
package com.qrcode.server;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.vobject.appengine.java.io.InputStream;
import ar.com.hjg.pngj.ImageLine;
import ar.com.hjg.pngj.PngReader;
import ar.com.hjg.pngj.PngWriter;
public class QrTest extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
doPost(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
try {
URL url = new URL("http://chart.apis.google.com/chart?
cht=qr&chs=400x400&chl=http://google.com&chld=L%7C0");
PngReader pngr;
pngr = new PngReader(url.openStream());
PngWriter pngw = new PngWriter("Name", pngr.imgInfo);
pngw.setOverrideFile(true); // allows to override writen file if
it already exits
//pngw.prepare(pngr); // not necesary; but this can copy some
informational chunks from original
int channels = pngr.imgInfo.channels;
if(channels<3) throw new RuntimeException("Only for truecolour
images");
for (int row = 0; row < pngr.imgInfo.rows; row++) {
ImageLine l1 = pngr.readRow(row);
for(int j=0;j<pngr.imgInfo.cols;j++){
String color_filter = Long.toHexString(l1.getPixelRGB8(j));
if (color_filter.equals("0")){
// CHANGE THE COLOR FOR EACH PIXEL (ROW X COLUMN)
l1.scanline[j*channels]= 250;
//SHOW THE HEX COLOR FOR EACH PIXEL OF THE IMAGE
String out = row +" x " + j +" - " +
Long.toHexString(l1.getPixelRGB8(j));
response.getWriter().println(out);
//SET THE NEW COLOR FOR EACH COLUMN IN
}else{
String out = " ==== NOT BLACK ===";
out ="\n"+ row +" x " + j +" - " +
Long.toHexString(l1.getPixelRGB8(j));
response.getWriter().println(out);
}
}
//pngw.writeRow(l1);
}
pngr.end();
pngw.end();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Thanks for your help. Here is my Solution:
Some helpful links: BlobStore and Getting Image from BlobKey