当前位置: 首页>>代码示例>>Java>>正文


Java Image.getGraphics方法代码示例

本文整理汇总了Java中javax.microedition.lcdui.Image.getGraphics方法的典型用法代码示例。如果您正苦于以下问题:Java Image.getGraphics方法的具体用法?Java Image.getGraphics怎么用?Java Image.getGraphics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.microedition.lcdui.Image的用法示例。


在下文中一共展示了Image.getGraphics方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createThumbnail

import javax.microedition.lcdui.Image; //导入方法依赖的package包/类
public static Image createThumbnail(Image image) {
    int sourceWidth = image.getWidth();
    int sourceHeight = image.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(image, x - dx, y - dy, Graphics.LEFT
                            | Graphics.TOP);
        }
    }

    Image immutableThumb = Image.createImage(thumb);

    return immutableThumb;
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:29,代码来源:ImageUtility.java

示例2: resizeImage

import javax.microedition.lcdui.Image; //导入方法依赖的package包/类
/**
* This methog resizes an image by resampling its pixels
* @param src The image to be resized
* @return The resized image
*/

public static Image resizeImage(Image src, int newWidth, int newHeight) {
      //We need to make sure we have memory available if it exists, because we're going to be allocating huuuge
     //chunks, and that might fail even if those chunks would be available if we collected.
    Runtime.getRuntime().gc();

    int srcWidth = src.getWidth();
    int srcHeight = src.getHeight();
    Image tmp = Image.createImage(newWidth, srcHeight);
    Graphics g = tmp.getGraphics();
    int ratio = (srcWidth << 16) / newWidth;
    int pos = ratio/2;

    //Horizontal Resize

    for (int x = 0; x < newWidth; x++) {
        g.setClip(x, 0, 1, srcHeight);
        g.drawImage(src, x - (pos >> 16), 0, Graphics.LEFT | Graphics.TOP);
        pos += ratio;
    }

    Image resizedImage = Image.createImage(newWidth, newHeight);
    g = resizedImage.getGraphics();
    ratio = (srcHeight << 16) / newHeight;
    pos = ratio/2;

    //Vertical resize

    for (int y = 0; y < newHeight; y++) {
        g.setClip(0, y, newWidth, 1);
        g.drawImage(tmp, 0, y - (pos >> 16), Graphics.LEFT | Graphics.TOP);
        pos += ratio;
    }
    return resizedImage;

}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:42,代码来源:ImageUtils.java


注:本文中的javax.microedition.lcdui.Image.getGraphics方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。