|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.nokia.mid.imagescale.ImageScaler
public class ImageScaler
ImageScaler
provide the capability of scaling image.
Upscaling is not completely supported due to uncontrollable memory use.
See the method definition for details.
Considering security, file path might be limited.
File read and write permission should be checked as well.
There are two ways to scale image:
scale image according to width and height
scale image according to file size
To receive events, an object must implement theImageScalerListener
interface and use theaddListener
method to register.
scale image per width, height will follow width
ImageScaler is = new ImageScaler("file:///Phone/big.jpg", "file:///Phone/small.jpg"); is.setJpegQuality(70); is.scaleImage(480, -1, true);
scale image per height, width will follow height
ImageScaler is = new ImageScaler("file:///Phone/big.jpg", "file:///Phone/small.jpg"); is.scaleImage(-1, 480, true);
scale image per width and height, not keep aspect ratio
ImageScaler is = new ImageScaler("file:///Phone/big.jpg", "file:///Phone/small.jpg"); is.scaleImage(320, 480, false);
scale image per width and height, height will keep original value, not keep aspect ratio
ImageScaler is = new ImageScaler("file:///Phone/big.jpg", "file:///Phone/small.jpg"); is.scaleImage(320, 0, false);
scale image per file size which is less than or equals to 100k
ImageScaler is = new ImageScaler("file:///Phone/big.jpg", "file:///Phone/small.jpg"); is.scaleImage(100);
Constructor Summary | |
---|---|
ImageScaler(java.lang.String srcPath,
java.lang.String destPath)
constructor. |
Method Summary | |
---|---|
void |
addListener(ImageScalerListener listener)
add a image scaler listener to be notified when scaling operation is finished. |
void |
cancel(int requestId)
cancel scale request. |
void |
removeDestFile()
the dest file is not used any more and can be removed. |
void |
removeListener(ImageScalerListener listener)
remove a image scaler listener to be notified when scaling operation is finished. |
int |
scaleImage(int maxFileSize)
Scale source image file into dest image file per file size. |
int |
scaleImage(int width,
int height,
boolean keepAspectRatio)
Scale source image file into dest image file per width and height pixels. |
void |
setAutoOrientation(boolean autoOrientation)
set flag for handling orientation info automatically. |
void |
setJpegQuality(int qual)
set quality for jpeg image. |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ImageScaler(java.lang.String srcPath, java.lang.String destPath)
java.lang.IllegalArgumentException
- if either the source or dest path is invalid.
java.lang.SecurityException
- if either the source or dest path can not be accessed.Method Detail |
---|
public void setJpegQuality(int qual)
qual
- Value 0-100, 0 for keeping the original quality.public void setAutoOrientation(boolean autoOrientation)
autoOrientation
- whether handle orientation info automatically or not.public int scaleImage(int width, int height, boolean keepAspectRatio) throws ImageScalerException
width
- width pixels, 0 for the original width, -1: not givenheight
- height pixels, 0 for the original height, -1: not givenkeepAspectRatio
- Whether keep aspect radio or not.
if keepAspectRatio is true then the other resolution will follow the given resolution.
If keepAspectRatio is false, leave the not given resolution to its original value
If both resolutions are given and keepAspectRatio is true, the scaler will reduce
the shorter dimension to maintain aspect ratio.
ImageScalerException
- if some basic errors occur such as the source file cannot
be found, or dest file is in use, or file type can not be supported, or width/height is
minus but not -1, or width/height is larger than 10000, etc
java.lang.SecurityException
- if the application does not have read access
to the source file or does not have write access to the dest file directorypublic int scaleImage(int maxFileSize) throws ImageScalerException
maxFileSize
- Max file size in kilobytes, 100%-70% of requested size can be accepted.
ImageScalerException
- if some direct errors occur such as the source file cannot
be found, or dest file is in use, or file type can not be supported, etc
java.lang.SecurityException
- if the application does not have read access
to the source file or does not have write access to the dest file directorypublic void cancel(int requestId)
public void removeDestFile() throws java.io.IOException
java.io.IOException
- if the dest file cannot be removed.
java.lang.SecurityException
- if the application does not have write access
to the dest file directorypublic void addListener(ImageScalerListener listener)
listener
- the listener to add.
If null
is used, the request will be ignored.public void removeListener(ImageScalerListener listener)
listener
- the listener to remove.
If null
is used, the request will be ignored.
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |