Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6665079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:41:05+00:00 2026-05-26T02:41:05+00:00

that’s my first time here. Hope someone can give us a hint! We are

  • 0

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();
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:41:06+00:00Added an answer on May 26, 2026 at 2:41 am

    Thanks for your help. Here is my Solution:
    Some helpful links: BlobStore and Getting Image from BlobKey

        @Override
    public String createImage(String origFilename) {
    
        BlobKey blobKey = null;
        String modifiedURL=null;
        try {
              // Get a file service
              FileService fileService = FileServiceFactory.getFileService();
    
              // Create a new Blob file with mime-type "image/png"
              AppEngineFile file1 = fileService.createNewBlobFile("image/png");
    
    
              boolean lock = true;// This time lock because we intend to finalize
    
            // Open a channel to write to it
              FileWriteChannel writeChannel = fileService.openWriteChannel(file1, lock);
              OutputStream os = Channels.newOutputStream(writeChannel);
    
             //Fetching image from URL
    
              URL url = new URL(escapeHTML(origFilename));      //escape Special Characters     
              PngReader pngr     = new PngReader(url.openStream());
    
              //Create PngWriter to write to Output Stream
              PngWriter pngw = new PngWriter(os, pngr.imgInfo);
    
              //Modify the image
    
                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++)
                        l1.scanline[j*channels]=250; // Change the color of the pixel
                    pngw.writeRow(l1); //write rows
                }
    
    
                // Now finalize
                pngr.end();
                pngw.end();
                os.close(); // close the output stream  
    
                writeChannel.closeFinally();
    
    
                //Get the BlobKey
               blobKey= fileService.getBlobKey(file1);
    
               /*Using ImageService to retrieve Modified Image URL
               http://code.google.com/appengine/docs/java/images/overview.html
               */
               ImagesService imagesService = ImagesServiceFactory.getImagesService();
               modifiedURL= imagesService.getServingUrl(blobKey);
    
    
    
    
    
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    
        return  modifiedURL;
    
    }
    
    //This is the function to escape special characters
     public static final String escapeHTML(String s) {
         StringBuffer sb = new StringBuffer();
         int n = s.length();
         for (int i = 0; i < n; i++) {
           char c = s.charAt(i);
           switch (c) {
           case '|':
             sb.append("%7C");
             break;
           case ' ':
             sb.append("%20");
             break;
    
           default:
             sb.append(c);
             break;
           }
         }
         return sb.toString();
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's my first post here. Thanks in advance everyone that collaborates with me. I'm
That's how I'm new in here on the website so it would be super
That might sound silly but can't do it myself :( Need your help guys.
That is the question. Background: C# Params In C#, you can declare the last
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's the best way I could think of to phrase my question, here is
That's not a secret: Silverlight's DataGrid default style is beautiful while WPF's is poor.
That the razor syntax is neat, there's little arguing about. But i can't seem
That simple. Moving my layout into a fluid territory, working on scalable images. Using
That's the question. Give only one reason you think why have OODB failed or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.