imageutil.java

来自「本程序是一个演示动画效果的程序」· Java 代码 · 共 24 行

JAVA
24
字号

import javax.microedition.lcdui.*;
import java.io.*;

public class ImageUtil {

  public static Image getFixImage(String imageName,int width,int height) {
    Image img = null;
    try {
      img = Image.createImage(imageName);
    }
    catch (IOException ex) {
      ex.printStackTrace();
    }
    int imgWidth = img.getWidth();
    int imgHeight = img.getHeight();
    int actWidth = ((int)(imgWidth / width))*width;
    int actHeight = ((int)(imgHeight / height))*height;
    Image retImage = Image.createImage(actWidth,actHeight);
    Graphics gPaint = retImage.getGraphics();
    gPaint.drawImage(img,0,0,Graphics.LEFT|Graphics.TOP);
    return retImage;
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?