JSR234是高级媒体API,在原有的MMA的基础上增加了很多Control,目前nokia的s60第三版已经开始支持jsr234,他主要支持对图片、声音等多媒体信息的一些高级处理,下面是使用其对图片缩放的方法:
/** */
/**
* 实现对图片的缩放
* @param path String 缩放图片的路径
* @param newWidth int 新的宽度
* @param newHeight int 新的高度
* @return Image 缩放以后得到的Image对象
*/
public Image zoomImage(String path, int newWidth, int newHeight) ... {
Image re = null;
MediaProcessor mp = null;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try ...{
mp = GlobalManager.createMediaProcessor("image/png");
InputStream in = this.getClass().getResourceAsStream(path);
mp.setInput(in,MediaProcessor.UNKNOWN);
mp.setOutput(baos);
ImageTransformControl itc = (ImageTransformControl)mp.getControl("javax.microedition.amms.control.imageeffect.ImageTransformControl");
int sw = itc.getSourceWidth();
int sh = itc.getSourceHeight();
int ow = newWidth;
int oh = newHeight;
itc.setSourceRect(0,0,sw,sh);
itc.setTargetSize(ow,oh,0);
itc.setEnabled(true);
mp.start();
mp.complete();
byte b[] = baos.toByteArray();
System.out.println(b.length);
int[] ints = new int[b.length / 4];
int intcount, bytecount;
for (intcount = 0, bytecount = 0; bytecount < b.length; ) ...{
ints[intcount] =
(( ((int)(b[bytecount + 0])) << 24) & 0xFF000000) | //A
(( ((int)(b[bytecount + 1])) << 16) & 0x00FF0000) | //R
(( ((int)(b[bytecount + 2])) << 8) & 0x0000FF00) | //G
(( ((int)(b[bytecount + 3])) & 0x000000FF) ); //B
intcount++;
bytecount+=4;
}
re = Image.createRGBImage(
ints, ow, oh, true);
} catch (MediaException ex) ...{
ex.printStackTrace();
}
return re;
}
* 实现对图片的缩放
* @param path String 缩放图片的路径
* @param newWidth int 新的宽度
* @param newHeight int 新的高度
* @return Image 缩放以后得到的Image对象
*/
public Image zoomImage(String path, int newWidth, int newHeight) ... {
Image re = null;
MediaProcessor mp = null;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try ...{
mp = GlobalManager.createMediaProcessor("image/png");
InputStream in = this.getClass().getResourceAsStream(path);
mp.setInput(in,MediaProcessor.UNKNOWN);
mp.setOutput(baos);
ImageTransformControl itc = (ImageTransformControl)mp.getControl("javax.microedition.amms.control.imageeffect.ImageTransformControl");
int sw = itc.getSourceWidth();
int sh = itc.getSourceHeight();
int ow = newWidth;
int oh = newHeight;
itc.setSourceRect(0,0,sw,sh);
itc.setTargetSize(ow,oh,0);
itc.setEnabled(true);
mp.start();
mp.complete();
byte b[] = baos.toByteArray();
System.out.println(b.length);
int[] ints = new int[b.length / 4];
int intcount, bytecount;
for (intcount = 0, bytecount = 0; bytecount < b.length; ) ...{
ints[intcount] =
(( ((int)(b[bytecount + 0])) << 24) & 0xFF000000) | //A
(( ((int)(b[bytecount + 1])) << 16) & 0x00FF0000) | //R
(( ((int)(b[bytecount + 2])) << 8) & 0x0000FF00) | //G
(( ((int)(b[bytecount + 3])) & 0x000000FF) ); //B
intcount++;
bytecount+=4;
}
re = Image.createRGBImage(
ints, ow, oh, true);
} catch (MediaException ex) ...{
ex.printStackTrace();
}
return re;
}