首页 > 网站 > 建站经验 > 正文

!安卓开发中Bitmap源码实例

2019-11-02 14:56:43
字体:
来源:转载
供稿:网友

 安卓开发中Bitmap源码实例

  package android.graphics;

  import java.awt.image.BufferedImage;

  import java.io.File;

  import java.io.IOException;

  import java.io.InputStream;

  import javax.imageio.ImageIO;

  public final class Bitmap extends _Original_Bitmap {

  private BufferedImage mImage;

  public Bitmap(File input) throws IOException {

  super(1, true, null, -1);

  mImage = ImageIO.read(input);

  }

  public Bitmap(InputStream is) throws IOException {

  s

南瓜园影院[www.aikan.tv/special/nanguayuanyingyuan/]
uper(1, true, null, -1);

  mImage = ImageIO.read(is);

  }

  Bitmap(BufferedImage image) {

  super(1, true, null, -1);

  mImage = image;

  }

  public BufferedImage getImage() {

  return mImage;

  }

  // ----- overriden methods

  public enum Config {

  // these native values must match up with the enum in SkBitmap.h

  ALPHA_8 (2),

  RGB_565 (4),

  ARGB_4444 (5),

  ARGB_8888 (6);

  Config(int ni) {

  this.nativeInt = ni;

  }

  final int nativeInt;

  /* package */ static Config nativeToConfig(int ni) {

  return sConfigs[ni];

  }

  private static Config sConfigs[] = {

  null, null, ALPHA_8, null, RGB_565, ARGB_4444, ARGB_8888

  };

  }

  @Override

  public int getWidth() {

  return mImage.getWidth();

  }

  @Override

  public int getHeight() {

  return mImage.getHeight();

  }

  /**

  * Returns an immutable bitmap from the source bitmap. The new bitmap may

  * be the same object as source, or a copy may have been made.

  */

  public static Bitmap createBitmap(Bitmap src) {

  return createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), null, false);

  }

  /**

  * Returns an immutable bitmap from the specified subset of the source

  * bitmap. The new bitmap may be the same object as source, or a copy may

  * have been made.

  *

  * @param source The bitmap we are subsetting

  * @param x The x coordinate of the first pixel in source

  * @param y The y coordinate of the first pixel in source

  * @param width The number of pixels in each row

  * @param height The number of rows

  */

  public static Bitmap createBitmap(Bitmap source, int x, int y,

  int width, int height) {

  return new Bitmap(source.mImage.getSubimage(x, y, width, height));

  }

  /**

  * Returns an immutable bitmap from subset of the source bitmap,

  * transformed by the optional matrix.

  *

  * @param source The bitmap we are subsetting

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表