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


Java Image.getWidth方法代码示例

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


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

示例1: getNewDimensions

import javax.microedition.lcdui.Image; //导入方法依赖的package包/类
/**
 * Used for scaling an image.  Checks to see if an image is bigger than the
 * provided dimensions, and provides new dimensions such that the image
 * scales to fit within the dimensions given. If the image is smaller (in both width and height)
 * than the given dimensions, returns the original image dimensions.
 * @param source image
 * @return int array [height, width]
 */
public static int[] getNewDimensions(Image im, int height, int width){
  double scalef = im.getHeight()*1.0/im.getWidth();
  int w = 1;
  int h = 1;
  if(im.getHeight() > height && im.getWidth() <= width){ //height is overbounds
      h = height;
      w = (int)Math.floor(h/scalef);
  }else if (im.getHeight() <= height && im.getWidth() > width){  //width is overbouds
      w = width;
      h = (int)Math.floor(w*scalef);
  }else if (im.getHeight() > height && im.getWidth() > width){ //both are overbounds
      if(height > width){    //screen width is smaller dimension, so reduce im width and scale height
          w = width;
          h = (int)Math.floor(w*scalef);
      }else if(height <= width){ //reduce height and scale width
          h = height;
          w = (int)Math.floor(h/scalef);
      }
  }else{
      h = im.getHeight();
      w = im.getWidth();
  }
      int[] dim = {h,w};
      return dim;
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:34,代码来源:ImageUtils.java

示例2: CTonsCinza

import javax.microedition.lcdui.Image; //导入方法依赖的package包/类
/**
 * Constrói um CTonsCinza a partir de uma Image
 */
CTonsCinza(Image img) {
   
    Larg = img.getWidth();
    Alt = img.getHeight();
    
    TonsCinza = new int[Alt][Larg];
    raw = new int[Larg*Alt];

    img.getRGB(raw, 0, Larg, 0, 0, Larg, Alt);
    
    for (int y = 0; y < Alt; y++) {
        for (int x = 0; x < Larg; x++) {
            pixel=raw[x+y*Larg];
            
            azul=pixel & 0x0000FF;
            verde=(pixel & 0xFF00) >> 8;
            vermelho=(pixel & 0xFF0000) >> 16;
            pixel=azul*11+verde*59+vermelho*30;
            pixel*=0.01;
            TonsCinza[y][x] = pixel;
        }
    }
}
 
开发者ID:gstiebler,项目名称:tio_patinhas,代码行数:27,代码来源:UCBitmap.java

示例3: CBitmap

import javax.microedition.lcdui.Image; //导入方法依赖的package包/类
CBitmap(Image img) {
    
    Larg = img.getWidth();
    Alt = img.getHeight();

    raw = new int[Larg*Alt];

    img.getRGB(raw, 0, Larg, 0, 0, Larg, Alt);
    
    PMCor = new Cor[Alt][Larg];

    for (int y = 0; y < Alt; y++) {
        for (int x = 0; x < Larg; x++) {
            PMCor[y][x] = new Cor(raw[x+y*Larg]);
        }
    }
}
 
开发者ID:gstiebler,项目名称:tio_patinhas,代码行数:18,代码来源:UCBitmap.java

示例4: drawImage

import javax.microedition.lcdui.Image; //导入方法依赖的package包/类
public void drawImage(Image img, int x, int y, int anchor) {
       if (delegate != null) {
           delegate.drawImage(img, x, y, anchor);
       } else {
           int newx = x;
           int newy = y;
   
           if (anchor == 0) {
               anchor = javax.microedition.lcdui.Graphics.TOP | javax.microedition.lcdui.Graphics.LEFT;
           }
   
           if ((anchor & javax.microedition.lcdui.Graphics.RIGHT) != 0) {
               newx -= img.getWidth();
           } else if ((anchor & javax.microedition.lcdui.Graphics.HCENTER) != 0) {
               newx -= img.getWidth() / 2;
           }
           if ((anchor & javax.microedition.lcdui.Graphics.BOTTOM) != 0) {
               newy -= img.getHeight();
           } else if ((anchor & javax.microedition.lcdui.Graphics.VCENTER) != 0) {
               newy -= img.getHeight() / 2;
           }
   
           if (img.isMutable()) {
               canvas.drawBitmap(((AndroidMutableImage) img).getBitmap(), newx, newy, strokePaint);
           } else {
               canvas.drawBitmap(((AndroidImmutableImage) img).getBitmap(), newx, newy, strokePaint);
           }
       }
}
 
开发者ID:Helltar,项目名称:AMPASIDE,代码行数:30,代码来源:AndroidDisplayGraphics.java

示例5: 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

示例6: 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

示例7: getRGBIntImageData

import javax.microedition.lcdui.Image; //导入方法依赖的package包/类
public int[] getRGBIntImageData(Object image) {
    if (!isImage(image)) return null;
    
    Image img = (Image)image;
    
    int w = img.getWidth();
    int h = img.getHeight();
    int[] data = new int[w * h]; 
    
    img.getRGB(data, 0, w, 0, 0, w, h);
    return data;
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:13,代码来源:MIDPImageAccessor.java

示例8: createImage

import javax.microedition.lcdui.Image; //导入方法依赖的package包/类
public Image createImage(Image image, int x, int y, int width, int height, int transform) {
	// TODO AndroidDisplayGraphics.drawRegion code is similar
	if (image == null)
		throw new NullPointerException();
	if (x + width > image.getWidth() || y + height > image.getHeight() || width <= 0 || height <= 0 || x < 0
			|| y < 0)
		throw new IllegalArgumentException("Area out of Image");

       Bitmap img;
       if (image.isMutable()) {
           img = ((AndroidMutableImage) image).getBitmap();
       } else {
           img = ((AndroidImmutableImage) image).getBitmap();
       }            

       Matrix matrix = new Matrix();
       switch (transform) {
       case Sprite.TRANS_NONE: {
           break;
       }
       case Sprite.TRANS_ROT90: {
       	matrix.preRotate(90);
           break;
       }
       case Sprite.TRANS_ROT180: {
           matrix.preRotate(180);
           break;
       }
       case Sprite.TRANS_ROT270: {
           matrix.preRotate(270);
           break;
       }
       case Sprite.TRANS_MIRROR: {
       	matrix.preScale(-1, 1);
           break;
       }
       case Sprite.TRANS_MIRROR_ROT90: {
       	matrix.preScale(-1, 1);
       	matrix.preRotate(-90);
           break;
       }
       case Sprite.TRANS_MIRROR_ROT180: {
       	matrix.preScale(-1, 1);
           matrix.preRotate(-180);
           break;
       }
       case Sprite.TRANS_MIRROR_ROT270: {
       	matrix.preScale(-1, 1);
           matrix.preRotate(-270);
           break;
       }
       default:
           throw new IllegalArgumentException("Bad transform");
       }

	return new AndroidImmutableImage(Bitmap.createBitmap(img, x, y, width, height, matrix, true));
}
 
开发者ID:Helltar,项目名称:AMPASIDE,代码行数:58,代码来源:AndroidDeviceDisplay.java

示例9: getImageWidth

import javax.microedition.lcdui.Image; //导入方法依赖的package包/类
public int getImageWidth(Object image) {
    if (!isImage(image)) return -1;
    
    Image img = (Image)image;
    return img.getWidth();
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:7,代码来源:MIDPImageAccessor.java

示例10: setStaticTileSet

import javax.microedition.lcdui.Image; //导入方法依赖的package包/类
/**
    * Change the static tile set.  <p>
    *
    * Replaces the current static tile set with a new static tile set.
    * See the constructor {@link #TiledLayer(int, int, Image, int, int)}
    * for information on how the tiles are created from the
    * image.<p>
    *
    * If the new static tile set has as many or more tiles than the
    * previous static tile set,
    * the the animated tiles and cell contents will be preserve.  If
    * not, the contents of
    * the grid will be cleared (all cells will contain index 0) and
    * all animated tiles
    * will be deleted.
    * <P>
    * @param image the <code>Image</code> to use for creating the
    * static tile set
    * @param tileWidth the width in pixels of a single tile
    * @param tileHeight the height in pixels of a single tile
    * @throws NullPointerException if <code>image</code> is <code>null</code>
    * @throws IllegalArgumentException if <code>tileHeight</code>
    *  or <code>tileWidth</code> is less than <code>1</code>
    * @throws IllegalArgumentException if the <code>image</code>
    *  width is not an integer  multiple of the <code>tileWidth</code>
    * @throws IllegalArgumentException if the <code>image</code>
    *  height is not an integer  multiple of the <code>tileHeight</code>
    */
   public void setStaticTileSet(Image image, int tileWidth, int tileHeight) {
       // if img is null img.getWidth() will throw NullPointerException
       if (tileWidth < 1 || tileHeight < 1 ||
    ((image.getWidth() % tileWidth) != 0) || 
           ((image.getHeight() % tileHeight) != 0)) {
            throw new IllegalArgumentException();
}
       setWidthImpl(columns * tileWidth);
setHeightImpl(rows * tileHeight);

       int noOfFrames = 
         (image.getWidth() / tileWidth) * (image.getHeight() / tileHeight);

       // the zero th index is left empty for transparent tile
       // so it is passed in  createStaticSet as noOfFrames + 1

if (noOfFrames >= (numberOfTiles - 1)) {
    // maintain static indices
    createStaticSet(image, noOfFrames + 1, tileWidth, tileHeight, true);
} else {
           createStaticSet(image, noOfFrames + 1, tileWidth, 
                               tileHeight, false);
}	
   }
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:53,代码来源:TiledLayer.java

示例11: createStaticSet

import javax.microedition.lcdui.Image; //导入方法依赖的package包/类
/**
    * create the Image Array.
    *
    * @param image Image to use for creating the static tile set
    * @param noOfFrames total number of frames
    * @param tileWidth The width, in pixels, of a single tile
    * @param tileHeight The height, in pixels, of a single tile
    * @param maintainIndices 
    */

   private void createStaticSet(Image image, int noOfFrames, int tileWidth, 
                     int tileHeight, boolean maintainIndices) {

       cellWidth = tileWidth;
       cellHeight = tileHeight;

int imageW = image.getWidth();
int imageH = image.getHeight();

sourceImage = image;

numberOfTiles = noOfFrames;
tileSetX = new int[numberOfTiles];
tileSetY = new int[numberOfTiles];

if (!maintainIndices) {
           // populate cell matrix, all the indices are 0 to begin with
           for (rows = 0; rows < cellMatrix.length; rows++) {
               int totalCols = cellMatrix[rows].length;
               for (columns = 0; columns < totalCols; columns++) {
                   cellMatrix[rows][columns] = 0;
               }
           }
    // delete animated tiles
    anim_to_static = null;
} 

       int currentTile = 1;

       for (int locY = 0; locY < imageH; locY += tileHeight) {
           for (int locX = 0; locX < imageW; locX += tileWidth) {

	tileSetX[currentTile] = locX;
	tileSetY[currentTile] = locY;

               currentTile++;
           }
       }
   }
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:50,代码来源:TiledLayer.java

示例12: Sprite

import javax.microedition.lcdui.Image; //导入方法依赖的package包/类
/**
 * Creates a new animated Sprite using frames contained in 
 * the provided Image.  The frames must be equally sized, with the 
 * dimensions specified by <code>frameWidth</code> and 
 * <code>frameHeight</code>.  They may be laid out in the image 
 * horizontally, vertically, or as a grid.  The width of the source 
 * image must be an integer multiple of the frame width, and the height
 * of the source image must be an integer multiple of the frame height.
 * The  values returned by {@link Layer#getWidth} and 
 * {@link Layer#getHeight} will reflect the frame width and frame height
 * subject to the Sprite's current transform.
 * <p>
 * Sprites have a default frame sequence corresponding to the raw frame
 * numbers, starting with frame 0.  The frame sequence may be modified
 * with {@link #setFrameSequence(int[])}.
 * <p>
 * By default, the Sprite is visible and its upper-left corner is 
 * positioned at (0,0) in the painter's coordinate system.
 * <p>
 * @param image the <code>Image</code> to use for <code>Sprite</code>
 * @param frameWidth the <code>width</code>, in pixels, of the
 * individual raw frames
 * @param frameHeight the <code>height</code>, in pixels, of the
 * individual raw frames
 * @throws NullPointerException if <code>img</code> is <code>null</code>
 * @throws IllegalArgumentException if <code>frameHeight</code> or
 * <code>frameWidth</code> is less than <code>1</code>
 * @throws IllegalArgumentException if the <code>image</code>
 * width is not an integer multiple of the <code>frameWidth</code>
 * @throws IllegalArgumentException if the <code>image</code>
 * height is not an integer multiple of the <code>frameHeight</code>
 */
public Sprite(Image image, int frameWidth, int frameHeight) {

    super(frameWidth, frameHeight);
    // if img is null img.getWidth() will throw NullPointerException
    if ((frameWidth < 1 || frameHeight < 1) ||
        ((image.getWidth() % frameWidth) != 0) ||
        ((image.getHeight() % frameHeight) != 0)) {
         throw new IllegalArgumentException();
    }

    // construct the array of images that 
    // we use as "frames" for the sprite.
    // use default frame , sequence index = 0  
    initializeFrames(image, frameWidth, frameHeight, false);

    // initialize collision rectangle
    initCollisionRectBounds();

    // current transformation is TRANS_NONE
    setTransformImpl(TRANS_NONE);

}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:55,代码来源:Sprite.java

示例13: initializeFrames

import javax.microedition.lcdui.Image; //导入方法依赖的package包/类
/**
 * create the Image Array.
 *
 * @param image Image to use for Sprite
 * @param fWidth width, in pixels, of the individual raw frames
 * @param fHeight height, in pixels, of the individual raw frames
 * @param maintainCurFrame true if Current Frame is maintained
 */
private void initializeFrames(Image image, int fWidth, 
                    int fHeight, boolean maintainCurFrame) {

    int imageW = image.getWidth();
    int imageH = image.getHeight();
        
    int numHorizontalFrames = imageW / fWidth;
    int numVerticalFrames   = imageH / fHeight;

    sourceImage = image;

    srcFrameWidth = fWidth;
      srcFrameHeight = fHeight;

    numberFrames = numHorizontalFrames*numVerticalFrames;

    frameCoordsX = new int[numberFrames];
    frameCoordsY = new int[numberFrames];

    if (!maintainCurFrame) {
        sequenceIndex = 0;
    }

    if (!customSequenceDefined) {
        frameSequence = new int[numberFrames];
    }

    int currentFrame = 0;

    for (int yy = 0; yy < imageH; yy += fHeight) {
        for (int xx = 0; xx < imageW; xx += fWidth) {

            frameCoordsX[currentFrame] = xx;
            frameCoordsY[currentFrame] = yy;
    
            if (!customSequenceDefined) {
                frameSequence[currentFrame] = currentFrame;
            }
            currentFrame++;

        }
    }
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:52,代码来源:Sprite.java

示例14: TiledLayer

import javax.microedition.lcdui.Image; //导入方法依赖的package包/类
/**
    * Creates a new TiledLayer.  <p>
    *
    * The TiledLayer's grid will be <code>rows</code> cells high and
    * <code>columns</code> cells wide.  All cells in the grid are initially
    * empty (i.e. they contain tile index 0).  The contents of the grid may
    * be modified through the use of {@link #setCell} and {@link #fillCells}.
    * <P>
    * The static tile set for the TiledLayer is created from the specified
    * Image with each tile having the dimensions of tileWidth x tileHeight.
    * The width of the source image must be an integer multiple of
    * the tile width, and the height of the source image must be an integer
    * multiple of the tile height; otherwise, an IllegalArgumentException
    * is thrown;<p>
    *
    * The entire static tile set can be changed using 
    * {@link  #setStaticTileSet(Image, int, int)}.
    * These methods should be used sparingly since they are both
    * memory and time consuming.
    * Where possible, animated tiles should be used instead to
    * animate tile appearance.<p>
    *
    * @param columns the width of the <code>TiledLayer</code>,
    * expressed as a number of cells
    * @param rows the height of the <code>TiledLayer</code>,
    * expressed as a number of cells
    * @param image the <code>Image</code> to use for creating
    *  the static tile set
    * @param tileWidth the width in pixels of a single tile
    * @param tileHeight the height in pixels of a single tile
    * @throws NullPointerException if <code>image</code> is <code>null</code>
    * @throws IllegalArgumentException if the number of <code>rows</code>
    *  or <code>columns</code> is less than <code>1</code>
    * @throws IllegalArgumentException if <code>tileHeight</code>
    *  or <code>tileWidth</code> is less than <code>1</code>
    * @throws IllegalArgumentException if the <code>image</code>
    *  width is not an integer multiple of the <code>tileWidth</code>
    * @throws IllegalArgumentException if the <code>image</code>
    * height is not an integer multiple of the <code>tileHeight</code>
    */
   public TiledLayer(int columns, int rows, Image image, int tileWidth,
	      int tileHeight) {
// IllegalArgumentException will be thrown 
// in the Layer super-class constructor
       super(columns < 1 || tileWidth < 1 ? -1 : columns * tileWidth, 
         rows < 1 || tileHeight < 1 ? -1 : rows * tileHeight);

       // if img is null img.getWidth() will throw NullPointerException
       if (((image.getWidth() % tileWidth) != 0) || 
           ((image.getHeight() % tileHeight) != 0)) {
            throw new IllegalArgumentException();
}
       this.columns = columns;
this.rows = rows;

       cellMatrix = new int[rows][columns];

       int noOfFrames = 
           (image.getWidth() / tileWidth) * (image.getHeight() / tileHeight);
       // the zero th index is left empty for transparent tile
       // so it is passed in  createStaticSet as noOfFrames + 1
       // Also maintain static indices is true
// all elements of cellMatrix[][] 
// are set to zero by new, so maintainIndices = true
       createStaticSet(image,  noOfFrames + 1, tileWidth, tileHeight, true);
   }
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:67,代码来源:TiledLayer.java

示例15: drawImageCentered

import javax.microedition.lcdui.Image; //导入方法依赖的package包/类
/**
 * Draws an image centered to the given rectangular area.
 * @param g Graphics context.
 * @param img Image to draw.
 * @param x X-coordinate.
 * @param y Y-coordiante.
 * @param maxW Maximum width of image.
 * @param maxH Maximum height of image.
 */
public static void drawImageCentered(Graphics g, Image img, int x, int y, int maxW, int maxH){
	if (Log.TEST) Log.note("[Util#drawImageCentered]-->");
    if (img != null) {
        int imgXOff = x + (maxW - img.getWidth()) / 2;
        int imgYOff = y + (maxH - img.getHeight()) / 2;
        g.drawImage(img, imgXOff, imgYOff, Graphics.TOP | Graphics.LEFT);
    }
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:18,代码来源:Util.java


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