Monday, April 22, 2013

Load Image from DB and Show it in browser using Google Web Toolkit

A widget that displays the image at a given URL. The image can be in 'unclipped' mode (the default) or 'clipped' mode. In clipped mode, a viewport is overlaid on top of the image so that a subset of the image will be displayed. In unclipped mode, there is no viewport - the entire image will be visible. Whether an image is in clipped or unclipped mode depends on how the image is constructed, and how it is transformed after construction. Methods will operate differently depending on the mode that the image is in. These differences are detailed in the documentation for each method.
If an image transitions between clipped mode and unclipped mode, any Element-specific attributes added by the user (including style attributes, style names, and style modifiers), except for event listeners, will be lost.
reference : 

public String getImage (String id) {
       String imageDataAsString = new String();
       byte imageBytes[] = new byte[5000];
       imageBytes = imageService.getImageById(id);
return encodeasBase64(imageBytes);


//convert data to base64 string
// * base64 codec ported with GWT will not going to work , use commons codec  *
// * this method is responsible to convert byteArray to base64 
//     * encoded string 

public String encodeasBase64(byte[] imageByteArray) {
  StringBuilder imageDataAsbase64String = new StringBuilder();
  String  encodedString = new 



  return imageDataAsbase64String.toString();

// Data will come from GWT rpc call , rpc call can be initiate upon click event
public void displayImage(String result) {
    Image image = new Image(result);
    HorizontalPanel imagePanel = new HorizontalPanel();
    DialogBox dialogueBox = new DialogBox();


No comments:

Post a Comment