Are there any Java classes that support writing the WAP WBMP image format?

francois lascelles

Yes there is. I wrote a helper class to render WBMP images.


import java.io.*;
import java.lang.*;
import java.awt.Graphics.*;
import java.awt.Graphics2D;
import java.awt.image.*;

public class WBmpRenderer {
  // the bitmap
  protected BufferedImage iBitmap;
  // the context to draw into
  protected Graphics2D iGraphicsContext;
  // bitmap size
  protected byte iWidth;
  protected byte iHeight;

  // construct with the size of the bitmap
  public WBmpRenderer(byte aWidth, byte aHeight) 
      throws Exception {
    iWidth = aWidth;
    iHeight = aHeight;
    iBitmap = new BufferedImage(
      iWidth, iHeight, BufferedImage.TYPE_BYTE_BINARY);
    if (iBitmap == null) {
      throw new Exception(
        "cannot create BufferedImage object");
    }
    iGraphicsContext = iBitmap.createGraphics();
    if (iGraphicsContext == null) {
      throw new Exception(
        "cannot create Graphics2D object");
    }
  }

  // retreive graphic context to draw stuff into bitmap
  public Graphics2D graphicsContext() {
    return iGraphicsContext;
  }

  //
  // This send the image to the output in WBMP 
  //  (WIRELESS BITMAP)
  //
  // WBMP FORMAT:
  // BYTE 1 AND BYTE 2 = 0
  // BYTE 3 width in pixels
  // BYTE 4 height in pixels
  // the rest is the pixels (one bit per pixel)
  //
  public boolean sendToOutput(OutputStream anOut) {
    try {
      byte byteInOutput = 0;
      // write twice "0"
      anOut.write(byteInOutput);
      anOut.write(byteInOutput);
      // output the height and the width
      anOut.write(iWidth);
      anOut.write(iHeight);
      // output the bytes containing the graph
      DataBuffer locImageDataBuffer = 
        iBitmap.getData().getDataBuffer();
      int nbElementsInLocImage = 
        locImageDataBuffer.getSize();
      // one by one
      for (int count = 0; 
           count < nbElementsInLocImage; 
           ++count) {
        anOut.write((byte)
          locImageDataBuffer.getElem(count));
      }
    } catch (Exception e) {
      return false;
    }
    return true;
  }
}
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact