Picture zoom function on the J2ME

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

分类:Mobile 时间:2010-04-23 人气:455
分享到:
blog comments powered by Disqus

相关文章

  • for java in the structure and efficiency for each test 2010-07-31

    java in for efficiency and for each contrast public class ForTest { public static void main(String[] args){ ArrayList<Integer> array=new ArrayList<Integer>(); for(int i=0;i<1000000;i++){ array.add(i); } long t1=new Date().getTime(); long si

  • Procedures to enhance the efficiency of your elaborate bitmapdata 2010-12-21

    If you are new to programming or are only contacted as flex development, perhaps you would BitmapData do not know, maybe you will have it dismissed. But as a senior as the developer, no matter the game or web application development. BitmapData is yo

  • pure IP database QQwry.dat reading java source code (change) 2010-03-29

    pure IP database QQwry.dat reading java source code, to run this program must go to download QQwry.da, due to too much, I am not here to provide a. 1, IPEntry.java / ** * * An IP range of records, including not only national and regional, but also th

  • Sorting efficiency analysis 1 2008-07-14

    Do curriculum design, write a sorting algorithm package, can be used to analyze several common sorting algorithms exchange, comparison and the number of mobile and so on. At the same time the way the data generated random, positive sequence, and reve

  • Linux System Programming Study Notes (3) Advanced File I / O 2010-04-24

    Advanced File I / O 1, Linux provides high-level I / O operations: 1) Scatter / gatter I / O: a single system call can write files from multiple buffer or read more buffer. 2) Epoll: is the poll () and select () the improved version. 3) Memory-mapped

  • Test the efficiency of Java reflection 2010-05-15

    Test is divided into three areas: 1. Instantiated efficiency; 2. The method call efficiency; 3. Members of the GET variable called efficiency; 4. Member variable called SET Test environment: Windows 7 Sun Java 1.6 The first written test preparation c

  • [Translation] AGG Reference of Basic Renderers (based renderer) (1) 2010-07-04

    Rendering Buffer Let's start here: open a store in the memory area, then its content to write simple documents in raster format, that is, PPM (Portable Pixel Map) format. While this format is not Windows native support, but many image viewer and conv

  • IP database pure java to read the source code QQwry.dat 2010-07-21

    http://blog.csdn.net/swazn_yj/archive/2007/05/16/1611020.aspx pure IP database QQwry.dat java read the source code, to run this program must have to download QQwry.dat, because too much, I've not provided. 1, IPEntry.java /** *//** * * IP range of a

  • JAVA zoom image, image cut, change colors, change the type 2010-07-22

    import java.io.*; import java.awt.*; import java.awt.image.*; import java.awt.Graphics; import java.awt.color.ColorSpace; import javax.imageio.ImageIO; public class ImageCut { /** * Zoom Image * * @param srcImageFile * Address of the source image fil

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 闽ICP备15018612号

processed in 0.097 (s). 12 q(s)