如何在j2me中实现图片缩放功能??最好给个例子,小弟是新手,请各位不吝赐教。。。。。。
------解决方案--------------------------------------------------------
网上有实例代码,基本就是在画的时候省略一些相素,或者多画一个相素
------解决方案--------------------------------------------------------
插值算法,楼主搜一下就可以找到,另外如果手机支持jsr234可以采用下面的办法
http://blog.csdn.net/liujun999999/archive/2007/07/20/1700368.aspx
------解决方案--------------------------------------------------------
转载请注明出处!!
------解决方案--------------------------------------------------------
可以看看我整理的两个算法。
http://blog.csdn.net/hunhun1981/archive/2007/09/26/1801322.aspx
其中的第一个方法不错,很方便,指定新图像的尺寸就可以。使用的是垂直和水平两个方向的插值算法。效果很好。
如果有更高的需求,可以考虑双线性插值,不过它需要浮点支持,或者自己模拟浮点。从手机显示屏的尺寸和分辨率来看,这个算法足够了。
楼上的代码似乎就是kobjects提供的开源代码啊!鄙视!下面提供kobjects的完整代码,真要用,还是看我blog中的第一个算法,不知道作者是谁。
1 /* Copyright (c) 2002,2003, Stefan Haustein, Oberhausen, Rhld., Germany
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
4 * of this software and associated documentation files (the “Software”), to deal
5 * in the Software without restriction, including without limitation the rights
6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 * sell copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions:
9 *
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
12 *
13 * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19 * IN THE SOFTWARE. */
20
21 package org.kobjects.lcdui;
22
23
24 import javax.microedition.lcdui.*;
25
26
27 /** This class provides a single static method that allows to scale an image */
28
29
30 public class ScaleImage {
31
32 /**
33 * Creates a new, scaled version of the given image.
34 *
35 * @param src: The source image
36 * @param dstW: The destination (scaled) image width
37 * @param dstH: The destination (scaled) image height
38 * @return Image: A new Image object with the given width and height.
39 */
40
41 public static Image scaleImage (Image src, int dstW, int dstH) {
42 int srcW = src.getWidth();
43 int srcH = src.getHeight();
44
45 Image tmp = Image.createImage(dstW, srcH);
46 Graphics g = tmp.getGraphics();
47
48 int delta = (srcW << 16) / dstW;
49 int pos = delta/2;
50
51 for (int x = 0; x < dstW; x++) {
52 g.setClip(x, 0, 1, srcH);
53 g.drawImage(src, x - (pos >> 16), 0, Graphics.LEFT | Graphics.TOP);
54 pos += delta;
55 }
56
57 Image dst = Image.createImage(dstW, dstH);
58 g = dst.getGraphics();
59
60 delta = (srcH << 16) / dstH;
61 pos = delta/2;
62
63 for (int y = 0; y < dstH; y++) {
64 g.setClip(0, y, dstW, 1);
65 g.drawImage(tmp, 0, y - (pos >> 16), Graphics.LEFT | Graphics.TOP);
66 pos += delta;
67 }
68
69 return dst;
70 }
71
72
73 }