/* * 15 Juni 2009 21:39 */ import java.io.IOException; import javax.microedition.lcdui.*; import javax.microedition.midlet.*; /** * @author Dyah Fajar */ public class Thumbnail_pic extends MIDlet implements CommandListener{ private Display dsp; private Form frm; private Command exit, start; public Thumbnail_pic() { dsp = Display.getDisplay(this); exit = new Command("Exit", Command.EXIT, 0); start = new Command("Start", Command.OK, 0); frm = new Form("Thumbnail Picture"); frm.addCommand(exit); frm.addCommand(start); frm.setCommandListener(this); } public void startApp() { dsp.setCurrent(frm); } public void pauseApp() { } public void destroyApp(boolean unconditional) { } public void commandAction(Command c, Displayable d) { if (c == exit){ notifyDestroyed(); destroyApp(true); } else if (c == start){ Image img1, img2; img1= null; img2=null; try { img1 = Image.createImage("/Cute.jpg"); img2 = Image.createImage("/hmm..3.jpg"); } catch (IOException ex) { ex.printStackTrace(); } frm.append(createThumbnail(img1)); frm.append(createThumbnail(img2)); dsp.setCurrent(frm); } } private Image createThumbnail (Image img){ int sourceWidth = img.getWidth(); int sourceHeight = img.getHeight(); int thumbWidth = 64; int thumbHeight = -1; if (thumbHeight == -1){ thumbHeight = thumbWidth * sourceHeight / sourceWidth; } Image thumb = Image.createImage(thumbWidth, thumbHeight); Graphics g = thumb.getGraphics(); for (int y = 0; y < thumbHeight; y++){ for (int x = 0; x < thumbWidth; x++){ g.setClip(x, y, 1, 1); int dx = x * sourceWidth/thumbWidth; int dy = y * sourceHeight/thumbHeight; g.drawImage(img, x-dx, y-dy, Graphics.LEFT | Graphics.TOP); } } Image immutablethumb = Image.createImage(thumb); return immutablethumb; } } |
Komentar
Asyik.. dapat pelajaran baru...
BalasHapusTerimakasih... :D