Esempio n. 1
1
  @Override
  public Pixmap newPixmap(String fileName, PixmapFormat format) {
    Config config = null;
    if (format == PixmapFormat.RGB565) config = Config.RGB_565;
    else if (format == PixmapFormat.ARGB4444) config = Config.ARGB_4444;
    else config = Config.ARGB_8888;

    Options options = new Options();
    options.inPreferredConfig = config;

    InputStream in = null;
    Bitmap bitmap = null;
    try {
      in = assets.open(fileName);
      bitmap = BitmapFactory.decodeStream(in);
      if (bitmap == null)
        throw new RuntimeException("Couldn't load bitmap from asset '" + fileName + "'");
    } catch (IOException e) {
      throw new RuntimeException("Couldn't load bitmap from asset '" + fileName + "'");
    } finally {
      if (in != null) {
        try {
          in.close();
        } catch (IOException e) {
        }
      }
    }

    if (bitmap.getConfig() == Config.RGB_565) format = PixmapFormat.RGB565;
    else if (bitmap.getConfig() == Config.ARGB_4444) format = PixmapFormat.ARGB4444;
    else format = PixmapFormat.ARGB8888;

    return new AndroidPixmap(bitmap, format);
  }
 public TiledBitmapCanvas(Bitmap bitmap, int tileSize, int maxVersions) {
   mWidth = bitmap.getWidth();
   mHeight = bitmap.getHeight();
   mConfig = bitmap.getConfig();
   mTileSize = tileSize;
   mMaxVersions = maxVersions;
   load(bitmap);
 }
Esempio n. 3
0
  public static Bitmap colorMatrixBmp(Bitmap bmp, float[] matrixSrc) {

    int width = bmp.getWidth();
    int height = bmp.getHeight();

    ColorMatrix matrix = new ColorMatrix();
    matrix.set(matrixSrc);
    ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix);
    Paint p = new Paint();
    p.setColorFilter(filter);
    Bitmap colorBmp = Bitmap.createBitmap(width, height, bmp.getConfig());
    Canvas c = new Canvas(colorBmp);
    c.drawBitmap(bmp, 0, 0, p);
    return colorBmp;
  }
Esempio n. 4
0
  public static Bitmap blackWhiteBmp(Bitmap bmp) {
    // black and white

    int width = bmp.getWidth();
    int height = bmp.getHeight();

    ColorMatrix matrix = new ColorMatrix();
    float[] src = {
      0.308F, 0.609F, 0.082F, 0, 0, 0.308F, 0.609F, 0.082F, 0, 0, 0.308F, 0.609F, 0.082F, 0, 0, 0,
      0, 0, 1, 0
    };
    matrix.set(src);
    ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix);
    Paint p = new Paint();
    p.setColorFilter(filter);
    Bitmap colorBmp = Bitmap.createBitmap(width, height, bmp.getConfig());
    Canvas c = new Canvas(colorBmp);
    c.drawBitmap(bmp, 0, 0, p);
    return colorBmp;
  }