Example usage for android.graphics Bitmap createBitmap

List of usage examples for android.graphics Bitmap createBitmap

Introduction

In this page you can find the example usage for android.graphics Bitmap createBitmap.

Prototype

public static Bitmap createBitmap(int width, int height, @NonNull Config config) 

Source Link

Document

Returns a mutable bitmap with the specified width and height.

Usage

From source file:Main.java

public static Bitmap joinBitmaps(Bitmap first, Bitmap second) {
    Bitmap result = Bitmap.createBitmap(first.getWidth(), first.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(result);
    Paint bitmapPaint = new Paint();
    if (second.getWidth() != first.getWidth() && second.getHeight() != first.getHeight()) {
        second = createScaledToFillBitmap(second, first.getWidth(), first.getHeight());
    }//from  w  ww  .j  a  v a 2  s  . c  o m

    canvas.drawBitmap(first, 0, 0, bitmapPaint);
    canvas.drawBitmap(second, 0, 0, bitmapPaint);

    return result;
}

From source file:Main.java

public static Bitmap getBitmapFromView(View v) {
    if (v == null) {
        return null;
    }/*  ww  w  .  j  ava 2 s  .c om*/
    Bitmap screenShot;
    screenShot = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas mCanvas = new Canvas(screenShot);
    mCanvas.translate(-v.getScrollX(), -v.getScrollY());
    v.draw(mCanvas);
    return screenShot;
}

From source file:Main.java

public static Bitmap flipAnimation(Bitmap animationTexture, int subImageWidth, int subImageHeight) {
    Bitmap animationTextureFlipped = Bitmap.createBitmap(animationTexture.getWidth(),
            animationTexture.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(animationTextureFlipped);
    Bitmap b;//from  w w w .j a v  a  2 s  .  c o  m
    for (int i = 0; (i + 1) * subImageHeight <= animationTexture.getHeight(); i++) {
        for (int j = 0; (j + 1) * subImageWidth <= animationTexture.getWidth(); j++) {
            b = Bitmap.createBitmap(animationTexture, j * subImageWidth, i * subImageHeight, subImageWidth,
                    subImageHeight);
            b = flip(b);
            canvas.drawBitmap(b, j * subImageWidth, i * subImageHeight, null);
        }
    }
    return animationTextureFlipped;
}

From source file:Main.java

public static Bitmap pictureDrawable2Bitmap(PictureDrawable pictureDrawable) {
    Bitmap bitmap = Bitmap.createBitmap(pictureDrawable.getIntrinsicWidth(),
            pictureDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    canvas.drawPicture(pictureDrawable.getPicture());
    return bitmap;
}

From source file:Main.java

public static Bitmap doColorFilter(Bitmap src, double red, double green, double blue) {
    int w = src.getWidth();
    int h = src.getHeight();

    Bitmap bmOut = Bitmap.createBitmap(w, h, src.getConfig());
    int A, R, G, B, pixel;
    for (int x = 0; x < w; x++) {
        for (int y = 0; y < h; y++) {
            pixel = src.getPixel(x, y);//from w  w  w . j  a  v a 2 s. c  o m
            A = Color.alpha(pixel);
            R = (int) (Color.red(pixel) * red);
            G = (int) (Color.green(pixel) * green);
            B = (int) (Color.blue(pixel) * blue);
            bmOut.setPixel(x, y, Color.argb(A, R, G, B));
        }
    }
    return bmOut;
}

From source file:Main.java

public static Bitmap convertViewToBitmap(View v) {
    if (v == null) {
        return null;
    }// ww  w. ja v  a 2s  .  c  o  m
    Bitmap screenshot;
    screenshot = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(screenshot);
    v.draw(c);
    return screenshot;
}

From source file:Main.java

public static Bitmap DrawableToBitmap(Drawable drawable) {
    try {/*from   www.  j  ava  2  s .c  o m*/
        Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
                drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
        Canvas canvas = new Canvas(bitmap);
        // canvas.setBitmap(bitmap);  
        drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
        drawable.draw(canvas);

        return bitmap;
    } catch (OutOfMemoryError e) {
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

public static Bitmap buildSequence(Context context, String text) {
    Bitmap myBitmap = Bitmap.createBitmap(160, 84, Bitmap.Config.ARGB_4444);
    Canvas myCanvas = new Canvas(myBitmap);
    Paint paint = new Paint();
    //Typeface font = Typeface.createFromAsset(context.getAssets(),"fonts/7LED.ttf");
    paint.setAntiAlias(true);/*from  w  w  w  . j  ava 2  s  .  co m*/
    paint.setSubpixelText(true);
    //paint.setTypeface(font);
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(Color.YELLOW);
    paint.setTextSize(65);
    paint.setTextAlign(Paint.Align.CENTER);
    myCanvas.drawText(text, 80, 60, paint);
    return myBitmap;
}

From source file:Main.java

public static Bitmap getPaintedBitmap(Bitmap bitmap, Paint paint, boolean deleteOld) {
    final Bitmap colorBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
    final Canvas c = new Canvas(colorBitmap);
    c.drawBitmap(bitmap, 0, 0, paint);/*from w  w w  . j  a  v  a2s .  com*/
    if (deleteOld) {
        bitmap.recycle();
    }
    return colorBitmap;
}

From source file:Main.java

public static Bitmap getScreenshotsForCurrentWindow(Activity activity) {
    View cv = activity.getWindow().getDecorView();
    Bitmap bmp = Bitmap.createBitmap(cv.getWidth(), cv.getHeight(), Bitmap.Config.ARGB_4444);
    cv.draw(new Canvas(bmp));
    return bmp;//from w  w  w  .  ja  v a 2s . co m
}