使用JSR234实现对图片的缩放

JSR234是高级媒体API,在原有的MMA的基础 上增加了很多Control,目前nokia的s60第三版已经开始支持jsr234,他主要支持对图片、声音等多媒体信息的一些高级处理,下面是使用其对图片缩放的方法:3GEYEd4E w�d3ynf'h
3GEYE�g9}.A7n(P!RL
 
9I-wm"st@'H3 /** *//**
wy/Z+dp'G3      * 实现对图片的缩放3GEYE0L|7[r0S7o1z
     * @param path String 缩放图片的路径
;k8U;e9R_!Q3      * @param newWidth int 新的宽度3GEYEM6boR;XsH
     * @param newHeight int 新的高度3GEYE fo.r'Q$Y ]5eN/M:Q
     * @return Image 缩放以后得到的Image对象
K,t nxnZ3      */3GEYE W4Bo!g&q9^ul`~5Pi/}
    public Image zoomImage(String path,int newWidth,int newHeight)...{3GEYEj'?{3p9A%tV
        Image re = null;
M%If*T!E+s+v3         MediaProcessor mp = null;
-k'@ QZ%Uh}q3         ByteArrayOutputStream baos = new ByteArrayOutputStream();3GEYEm+z @"xuT~
        try ...{
S1W(OOG9e7@){3             mp = GlobalManager.createMediaProcessor("image/png");3GEYE0O4k*W6NGy b3qB
            InputStream in = this.getClass().getResourceAsStream(path);
@\6q,e�YI*w"c'xq!p3             mp.setInput(in,MediaProcessor.UNKNOWN);
U"[^ yS2f3             mp.setOutput(baos);3GEYEo4L%m6Hw)[)JQb
            ImageTransformControl itc = (ImageTransformControl)mp.getControl("javax.microedition.amms.control.imageeffect.ImageTransformControl");3GEYE Ag;n8M ]F L
            int sw = itc.getSourceWidth();
-P)zXG8~(k,s3             int sh = itc.getSourceHeight();3GEYE\+a�\g#At C8o
            int ow = newWidth;3GEYE G p qulF}
            int oh = newHeight;
.iq/e;ViE7Z._$f3             itc.setSourceRect(0,0,sw,sh);
){X1]%[R r3D3             itc.setTargetSize(ow,oh,0);3GEYE}3by tvQ
            itc.setEnabled(true);
.l i6^3|(D3             mp.start();
R$u;P$\A�e3             mp.complete();3GEYE9D6WE8j;w/f
            byte b[] = baos.toByteArray();
.x[ B b/`_3             System.out.println(b.length);3GEYE@x8_Xh(F'Q
            int[] ints = new int[b.length / 4];3GEYE ?iQ4P#bx
            int intcount, bytecount;3GEYE*f+^O/^8_&?u@([
            for (intcount = 0, bytecount = 0; bytecount < b.length; ) ...{3GEYEK9kMH)Hs x
                ints[intcount] =3GEYEoI[+kK
                    (( ((int)(b[bytecount + 0])) << 24) & 0xFF000000) |  //A
2ESusRz3                     (( ((int)(b[bytecount + 1])) << 16) & 0x00FF0000) |  //R3GEYE%iu,Y`9o1T!H
                    (( ((int)(b[bytecount + 2])) << 8)  & 0x0000FF00) |  //G
&m+y} {n/a3                     (( ((int)(b[bytecount + 3]))        & 0x000000FF) ); //B
@ha([C8q3                 intcount++;
yo y l6r3                 bytecount+=4;3GEYEm5? v-|3B.UR
            }3GEYED"m�_@5Cv5k V
3GEYEx A;u)fdL/_]Gx
            re = Image.createRGBImage(3GEYE[1Z,Xf f�?*`|Ki9{
            ints, ow, oh, true);3GEYER M6m"K6rAyeN OI7Y
           3GEYE6z6H3JK:a6c.l t
        } catch (MediaException ex) ...{3GEYECK L \lx�@s
            ex.printStackTrace();
E#z z0r.FaW.z3         }
$F$vX,X h!~A3
1P2sRq2N3         return re;
awKX&W3N'm3     }
%|5k+G3z*dD^3 在J2ME中可以直接使用这个方法,当然,先确定你的手机 支持jsr234,缩放只是对图片处理的一个很小的方面,有兴趣的可以看看WTK2.5中关于JSR234的DEMO


'`$BkQ(a9Sx2C6|,? y3


g z(\.fFTYv2`3

JSR234并不是一个一定要实现的JSR ,以前我的做法是自己写一个缩放算法

你可能感兴趣的:(C++,c,算法,F#,Nokia)