Example usage for android.graphics PixelFormat OPAQUE

List of usage examples for android.graphics PixelFormat OPAQUE

Introduction

In this page you can find the example usage for android.graphics PixelFormat OPAQUE.

Prototype

int OPAQUE

To view the source code for android.graphics PixelFormat OPAQUE.

Click Source Link

Document

System chooses an opaque format (no alpha bits required)

Usage

From source file:Main.java

public static Config getBitmapConfig(Drawable drawable) {
    return drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565;
}

From source file:Main.java

public static Bitmap drawableToBitmap(Drawable drawable) {
    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);
    drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
    drawable.draw(canvas);// w ww.java  2  s .c  o  m

    return bitmap;
}

From source file:Main.java

public static Bitmap bitmapFromDrawable(Drawable drawable) {
    Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
            drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
    Canvas canvas = new Canvas();
    canvas.setBitmap(bitmap);/*from  w  ww. j a  v a 2 s.  co  m*/
    drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
    drawable.draw(canvas);
    return bitmap;
}

From source file:Main.java

public static Bitmap DrawableToBitmap(Drawable drawable) {

    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);//from w w  w.j  a  v  a 2  s  .  c o  m

    return bitmap;

}

From source file:Main.java

public static Bitmap drawableToBitmap(Drawable drawable) {
    int w = drawable.getIntrinsicWidth();
    int h = drawable.getIntrinsicHeight();

    Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
            : Bitmap.Config.RGB_565;//from ww  w.  j  a v  a 2  s  .  c o  m
    Bitmap bitmap = Bitmap.createBitmap(w, h, config);
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, w, h);
    drawable.draw(canvas);
    return bitmap;
}

From source file:Main.java

public static WindowManager.LayoutParams makeLayout(int x, int y, int width, int height) {
    WindowManager.LayoutParams ll_lp;//from   w w w.j  a  va  2s  .c om

    //Just a sample layout parameters.
    ll_lp = new WindowManager.LayoutParams();
    ll_lp.format = PixelFormat.OPAQUE;
    ll_lp.height = height;
    ll_lp.width = width;
    ll_lp.gravity = Gravity.LEFT | Gravity.TOP;
    ll_lp.x = x;
    ll_lp.y = y;
    ll_lp.token = null;
    //ll_lp.gravity |= Gravity.CENTER_HORIZONTAL;
    //ll_lp.gravity |= Gravity.CENTER_VERTICAL;
    ll_lp.type = WindowManager.LayoutParams.TYPE_APPLICATION;
    ll_lp.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
    ll_lp.flags = ll_lp.flags | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
    ll_lp.flags = ll_lp.flags | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;

    return ll_lp;
}

From source file:Main.java

public static Bitmap DrawableToBitmap(Drawable drawable) {
    try {//from  w w w. j av a2 s.  com
        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 drawable2Bitmap(Drawable drawable) {
    int width = drawable.getIntrinsicWidth();
    int height = drawable.getIntrinsicHeight();
    Bitmap result = Bitmap.createBitmap(width, height,
            drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
    Canvas canvas = new Canvas(result);
    drawable.setBounds(0, 0, width, height);
    drawable.draw(canvas);//from  w w w  . java2 s.co m
    return result;
}

From source file:Main.java

public static Bitmap drawableToBitmap(Drawable drawable) {
    if (null == drawable)
        return null;
    int w = drawable.getIntrinsicWidth();
    int h = drawable.getIntrinsicHeight();
    Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
            : Bitmap.Config.RGB_565;//from  w  w w.  j a  va  2 s . c  om
    Bitmap bitmap = Bitmap.createBitmap(w, h, config);
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, w, h);
    drawable.draw(canvas);
    return bitmap;
}

From source file:Main.java

public static android.graphics.Bitmap drawableToBitmap(Drawable drawable) {
    android.graphics.Bitmap bitmap = android.graphics.Bitmap.createBitmap(

            drawable.getIntrinsicWidth(),

            drawable.getIntrinsicHeight(),

            drawable.getOpacity() != PixelFormat.OPAQUE ? android.graphics.Bitmap.Config.ARGB_8888

                    : android.graphics.Bitmap.Config.RGB_565);

    Canvas canvas = new Canvas(bitmap);

    //canvas.setBitmap(bitmap);

    drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());

    drawable.draw(canvas);//from   w  w  w .  jav  a2s  .c om

    return bitmap;
}