Picture zoom function on the J2ME

sponsored links
public static Image ZoomImage (Image src, int desW, int desH)
(
Image desImg = null;
int srcW = src.getWidth (); / / original image width
int srcH = src.getHeight (); / / original image is high
int [] srcBuf = new int [srcW * srcH]; / / original image pixel information cache

src.getRGB (srcBuf, 0, srcW, 0, 0, srcW, srcH);

/ / Calculate interpolation table
int [] tabY = new int [desH];
int [] tabX = new int [desW];

int sb = 0;
int db = 0;
int tems = 0;
int temd = 0;
int distance = srcH> desH? srcH: desH;
for (int i = 0; i <= distance; i + +) (/ * vertical * /
tabY [db] = sb;
tems + = srcH;
temd + = desH;
if (tems> distance) (
tems -= distance;
sb + +;
)
if (temd> distance) (
temd -= distance;
db + +;
)
)

sb = 0;
db = 0;
tems = 0;
temd = 0;
distance = srcW> desW? srcW: desW;
for (int i = 0; i <= distance; i + +) (/ * horizontal * /
tabX [db] = (short) sb;
tems + = srcW;
temd + = desW;
if (tems> distance) (
tems -= distance;
sb + +;
)
if (temd> distance) (
temd -= distance;
db + +;
)
)

/ / Generate graphics pixel buf after zooming
int [] desBuf = new int [desW * desH];
int dx = 0;
int dy = 0;
int sy = 0;
int oldy = -1;
for (int i = 0; i <desH; i + +) (
if (oldy == tabY [i]) (
System.arraycopy (desBuf, dy - desW, desBuf, dy, desW);
) Else (
dx = 0;
for (int j = 0; j <desW; j + +) (
desBuf [dy + dx] = srcBuf [sy + tabX [j]];
dx + +;
)
sy + = (tabY [i] - oldy) * srcW;
)
oldy = tabY [i];
dy + = desW;
)

/ / Generate image
desImg = Image.createRGBImage (desBuf, desW, desH, false);
return desImg;
)

This function is collecting I used the Internet to the, not to mention results, performance or something. Only to find it very easy to use.
 with a very long time, unfortunately do not know who. Really would like to thank the author. This function uses the midp2.0 of getRGB () function, efficiency, well, basically nothing was optimized. In addition, the following can be provided under a midp1.0 the zoom function, which is achieved using a variable picture. Unfortunately, this function is not written by me.
 reproduced in kobjects. However, relatively poor performance does, after all, so many points to draw Well, with the processing image data is not comparable.

/ * Copyright (c) 2002,2003, Stefan Haustein, Oberhausen, Rhld., Germany
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* Of this software and associated documentation files (the "Software"), to deal
* In the Software without restriction, including without limitation the rights
* To use, copy, modify, merge, publish, distribute, sublicense, and / or
* Sell copies of the Software, and to permit persons to whom the Software is
* Furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* All copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE. * /

package org.kobjects.lcdui;

import javax.microedition.lcdui .*;

/ ** This class provides a single static method that allows to scale an image * /

public class ScaleImage (

/ **
* Creates a new, scaled version of the given image.
*
* @ Param src: The source image
* @ Param dstW: The destination (scaled) image width
* @ Param dstH: The destination (scaled) image height
* @ Return Image: A new Image object with the given width and height.
* /

public static Image scaleImage (Image src, int dstW, int dstH) (
int srcW = src.getWidth ();
int srcH = src.getHeight ();

Image tmp = Image.createImage (dstW, srcH);
Graphics g = tmp.getGraphics ();

int delta = (srcW <<16) / dstW;
int pos = delta / 2;

for (int x = 0; x <dstW; x + +) (
g.setClip (x, 0, 1, srcH);
g.drawImage (src, x - (pos>> 16), 0, Graphics.LEFT | Graphics.TOP);
pos + = delta;
)

Image dst = Image.createImage (dstW, dstH);
g = dst.getGraphics ();

delta = (srcH <<16) / dstH;
pos = delta / 2;

for (int y = 0; y <dstH; y + +) (
g.setClip (0, y, dstW, 1);
g.drawImage (tmp, 0, y - (pos>> 16), Graphics.LEFT | Graphics.TOP);
pos + = delta;
)

return dst;
)

)

To use them all at a glance, provide the original image object and the target width with Gaodu, it generates a new image, the image effect, and feel are similar, I think the first method better.
In the J2ME platform, there is no need to seek the most extreme effects, just enough. Once again, thank the authors of these two functions.

This article comes from CSDN blog, reproduced, please indicate the source: http://blog.csdn.net/yshen_dublin/archive/2009/08/06/4415978.aspx

Transfer from csdn
  • del.icio.us
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of Picture zoom function on the J2ME

  • hibernate call stored procedure

    hibernate call stored procedure

  • hibernate using c3p0 connection pooling

    Private http://www.lifevv.com/tenyo/doc/20070605102040991.html c3p0 for open source's JDBC connection pool, with the release hibernate. This article describes how to use the hibernate configuration in c3p0. c3p0 connection pool configuration is v ...

  • Hibernate configuration parameters hibernate.hbm2ddl.auto

    Hibernate in the configuration file: <properties> <property name="hibernate.hbm2ddl.auto" value="create" /> </ properties> Parameter Description: validate load hibernate, the authentication to create a database t ...

  • Build flex + spring + blazeds + hibernate application

    Build flex + spring + blazeds + hibernate application First, set up the project blazeds 1, will blazeds.war extract to a directory, such as: myflex /; 2, set up java works were such as: MyFlex, in the orientation of selection create project from exis ...

  • Hibernate connection pool configuration

    Hibernate connection pool configuration <! - Jdbc -> <property name="connection.driver_class"> oracle.jdbc.driver.OracleDriver </ property> <property name="connection.url"> jdbc: oracle: thin: @ 10.203.14.132:15

  • hibernate generic generic DAO

    package org.lzpeng.dao; import java.io.Serializable; import java.util.List; import org.hibernate.Criteria; import org.hibernate.Query; import org.hibernate.criterion.Criterion; import org.springside.modules.orm.hibernate.Page; /** * * @version 2009-1-10 *

  • Struts2 + hibernate + spring problem user log in

    dao layer services layer action jsp <tr> <td align="center"> <b> user name: </ b> </ td> <td> <s: textfield name = "czyNumber" cssClass = "textstyle" theme = "simple" size = &q

  • Based on JDBC, JPA Annotation achieve simple CRUD Generic Dao

    The origin of ideas are pretty long history of reasons: [Use iBATIS history] The use of iBATIS has been a long time, the system is to use the CRUD template tool to generate the code, although there are tools to generate, but looked at a lot of CRUD the Sq

  • Hibernate secondary cache

    Hibernate cache: 2-bit cache, also known as process-level cache or SessionFactory level cache, secondary cache can be shared by all of the session Cache configuration and the use of: Will echcache.xml (the document code in hibernate package directory ...

  • Hibernate's lazy strategy

    hibernate Lazy strategy can be used in: <class> tag, it can be true / false Tags can <PROPERTY> values true / false type of necessary tools to enhance <set> <list> can tag values true / false / extra <many-to-one> <on ...

blog comments powered by Disqus
Recent
Recent Entries
Tag Cloud
Random Entries