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 人气:398
分享到:
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 you can

  • 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 reverse f

  • 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 ...

  • 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 file * @

  • Picture tools, complete the picture of the interception, zoom (ImageHepler) 2010-11-12

    package com.lz.hr_picture.helper; import java.awt.Graphics2D; import java.awt.Rectangle; import java.awt.RenderingHints; import java.awt.geom.AffineTransform; import java.awt.image.BufferedImage; import java.awt.image.ColorModel; import java.awt.imag

  • Mouse button to zoom image 2010-12-03

    <! DOCTYPE HTML PUBLIC "- / / W3C / / DTD HTML 4.0 Transitional / / EN"> <HTML> <HEAD> <TITLE> New Document </ TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Aut

  • [Transfer] [experience] compare the efficiency of the array sorting algorithm 2010-12-20

    http://bbs.9ria.com/viewthread.php?tid=70573&extra = A lot of people entangled in the question - what good sorting algorithm. What stable, unstable pile of problems. Idle today, take a look at several algorithms measured, reported results for eve

  • Games efficiency optimization of a subset of good ways to reduce the huge container sliding the mouse consumes 2010-12-21

    As if you have some game development experience, that I believe you should know better, but the scene into sub-visual objects, the mouse will cause the sliding of Hurricane cpu; The main reason is that the traversal fp kept within the visual object. You m

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

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

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 0.152 (s). 14 q(s)