net.yura.mobile.util
Class ImageUtil

java.lang.Object
  extended by net.yura.mobile.util.ImageUtil

public class ImageUtil
extends Object

Author:
Yura Mamyrin

Field Summary
static int LARGESTBYTESTREAM
           
static int THUMB_MAX_SIZE
           
 
Constructor Summary
ImageUtil()
           
 
Method Summary
static javax.microedition.lcdui.Image colorize(javax.microedition.lcdui.Image original, int newColor)
           
static javax.microedition.lcdui.Image createImage(InputStream is, int cW, int cH)
          Get a scaled image directly from inputstream
static javax.microedition.lcdui.Image createImage(String filename, int cW, int cH)
          Created a sized Image from a file
static javax.microedition.lcdui.Image getJPEGthumb(byte[] fileBytes)
          Get a thumbnail image from a byte array
static javax.microedition.lcdui.Image getScaledImage(javax.microedition.lcdui.Image dispImage, int width, int height)
          Scale and resize image to fit our screen
static javax.microedition.lcdui.Image getThumbFromFile(InputStream str)
          Traverse an inputStream and return a thumbnail image if any.
static javax.microedition.lcdui.Image imageColor(javax.microedition.lcdui.Image image, int i)
          replaces all values of the blue channel with a color
static void imageColor(int[] pixels, int color)
           
static javax.microedition.lcdui.Image makeImage(int w, int h, int color)
           
static javax.microedition.lcdui.Image resize(javax.microedition.lcdui.Image inImage, int rotation, int scaleFactor, int scalePwr)
          Fit the image on our screen size (width, height)
static javax.microedition.lcdui.Image scaleImage(javax.microedition.lcdui.Image img, int newW, int newH)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LARGESTBYTESTREAM

public static int LARGESTBYTESTREAM

THUMB_MAX_SIZE

public static int THUMB_MAX_SIZE
Constructor Detail

ImageUtil

public ImageUtil()
Method Detail

colorize

public static javax.microedition.lcdui.Image colorize(javax.microedition.lcdui.Image original,
                                                      int newColor)

createImage

public static javax.microedition.lcdui.Image createImage(InputStream is,
                                                         int cW,
                                                         int cH)
Get a scaled image directly from inputstream

Parameters:
is - resource input stream
cW - screen width
cH - screen height
Returns:
Image if we can create/scale from is otherwise null

createImage

public static javax.microedition.lcdui.Image createImage(String filename,
                                                         int cW,
                                                         int cH)
                                                  throws IOException,
                                                         IOException
Created a sized Image from a file

Parameters:
filename - name of the image file
cW - device width
cH - device height
Returns:
Image returns scaled image that should fit our screen dimensions
Throws:
IOException

getJPEGthumb

public static javax.microedition.lcdui.Image getJPEGthumb(byte[] fileBytes)
Get a thumbnail image from a byte array

Parameters:
fileBytes -
Returns:
Image

getScaledImage

public static javax.microedition.lcdui.Image getScaledImage(javax.microedition.lcdui.Image dispImage,
                                                            int width,
                                                            int height)
Scale and resize image to fit our screen

Parameters:
dispImage, - the image
width - , max width
heigth, - max height
Returns:
Image - a scaled(resized) image

getThumbFromFile

public static javax.microedition.lcdui.Image getThumbFromFile(InputStream str)
                                                       throws IOException
Traverse an inputStream and return a thumbnail image if any. We build the thumbnail directly from the inputstream, thus avoiding to run out of memory on very large picture files.

Parameters:
str - the stream
Throws:
IOException

imageColor

public static final javax.microedition.lcdui.Image imageColor(javax.microedition.lcdui.Image image,
                                                              int i)
replaces all values of the blue channel with a color


imageColor

public static final void imageColor(int[] pixels,
                                    int color)

makeImage

public static javax.microedition.lcdui.Image makeImage(int w,
                                                       int h,
                                                       int color)

resize

public static javax.microedition.lcdui.Image resize(javax.microedition.lcdui.Image inImage,
                                                    int rotation,
                                                    int scaleFactor,
                                                    int scalePwr)
Fit the image on our screen size (width, height)

Parameters:
inImage - the image to be resized
scaleFactor - the factor with which we want to scale
scalePwr - shift width/height scalePwr bits
Returns:
Image - the resized image

scaleImage

public static javax.microedition.lcdui.Image scaleImage(javax.microedition.lcdui.Image img,
                                                        int newW,
                                                        int newH)