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


Java Graphics.setClip方法代码示例

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


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

示例1: createThumbnail

import javax.microedition.lcdui.Graphics; //导入方法依赖的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.Graphics; //导入方法依赖的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

示例3: paintVideo

import javax.microedition.lcdui.Graphics; //导入方法依赖的package包/类
/**
 * Paint video into canvas - in USE_DIRECT_VIDEO mode
 */
public void paintVideo(Graphics g) {
    // Don't paint if Canvas visible flag is false
    if (!pvis || !cvis || painting)
        return;
    
    painting = true;
    
    // Save the clip region
    int cx = g.getClipX();
    int cy = g.getClipY();
    int cw = g.getClipWidth();
    int ch = g.getClipHeight();
    // Change the clip to clip the video area
    g.clipRect(dx, dy, dw, dh);
    
    // Check if its within the bounds
    if (g.getClipWidth() > 0 && g.getClipHeight() > 0 && pvis) {
        int w = dw, h = dh;
        if (w > videoWidth)
            w = videoWidth;
        if (h > videoHeight)
            h = videoHeight;
        try {
            if (rgbData != null) {
                synchronized (rgbData) {
                    if (scaled) {
                        g.drawRGB(scaledData, 0, dw, dx, dy, dw, dh, useAlpha);
                    } else {
                        g.drawRGB(rgbData, 0, videoWidth, dx, dy, w, h, useAlpha);
                    }
                }
            }
        } finally {
            // Revert the clip region
            g.setClip(cx, cy, cw, ch);
            painting = false;
        }
    } else {
        g.setClip(cx, cy, cw, ch);
        painting = false;
    }
    if (TRACE_FRAMERATE) {
        if (frameStartTime == 0) {
            frameStartTime = System.currentTimeMillis();
        } else {
            frameCount++;
            if ((frameCount % 30) == 0) {
                int frameRate = (int) ( (frameCount * 1000) / (System.currentTimeMillis() - frameStartTime + 1));
                System.err.println("Frame Rate = " + frameRate);
            }
        }
    }
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:57,代码来源:MIDPVideoRenderer.java


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