Example usage for android.graphics Color TRANSPARENT

List of usage examples for android.graphics Color TRANSPARENT

Introduction

In this page you can find the example usage for android.graphics Color TRANSPARENT.

Prototype

int TRANSPARENT

To view the source code for android.graphics Color TRANSPARENT.

Click Source Link

Usage

From source file:Main.java

static public int getColor(Context context, String name) {
    int identifier = context.getResources().getIdentifier(name, "color", context.getPackageName());
    if (identifier > 0) {
        return context.getResources().getColor(identifier);
    }/*from  w w  w.  jav a  2s  . c  o  m*/
    return Color.TRANSPARENT;
}

From source file:Main.java

public static Bitmap clearBitmap(Bitmap sourceBitmap) {
    Bitmap newBitmap = Bitmap.createBitmap(sourceBitmap, 0, 0, sourceBitmap.getWidth(),
            sourceBitmap.getHeight());//from   ww  w .  j  a v  a2  s.c o m
    Bitmap mutableBitmap = newBitmap.copy(Bitmap.Config.ARGB_8888, true);
    mutableBitmap.eraseColor(Color.TRANSPARENT);
    return mutableBitmap;
}

From source file:Main.java

public static Bitmap createBitmapFromView(View view) {
    // Clear any focus from the view first to remove any cursor
    view.clearFocus();//w  ww.  j a  v a 2  s  .  c  o m
    Bitmap drawingBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
    drawingBitmap.eraseColor(Color.TRANSPARENT);
    Canvas canvas = new Canvas(drawingBitmap);
    view.draw(canvas);
    return drawingBitmap;
}

From source file:Main.java

public static Bitmap drawableToBitmap(Drawable drawable) {
    if (drawable == null)
        drawable = new ColorDrawable(Color.TRANSPARENT);

    Bitmap bitmap;// ww  w  . jav a 2  s  . c om

    if (drawable instanceof BitmapDrawable) {
        BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
        if (bitmapDrawable.getBitmap() != null)
            return bitmapDrawable.getBitmap();
    }

    if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0)
        bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
    else
        bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
                Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);
    return bitmap;
}

From source file:Main.java

public static synchronized void cleansurfaceview(SurfaceHolder postureholder, SurfaceView posturesurface) {
    Canvas canvas = postureholder
            .lockCanvas(new Rect(0, 0, posturesurface.getWidth(), posturesurface.getHeight()));
    canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
    postureholder.unlockCanvasAndPost(canvas);
    Canvas canvasa = postureholder
            .lockCanvas(new Rect(0, 0, posturesurface.getWidth(), posturesurface.getHeight()));
    canvasa.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
    postureholder.unlockCanvasAndPost(canvasa);
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.KITKAT)
private static void transparentStatusBar(Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
    } else {//from  w w  w.  j  a  v  a2s.c o m
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    }
}

From source file:Main.java

public static int[] findBoundsOfVisibleBitmap(Bitmap bitmap) {
    // Sanity check
    if (bitmap == null)
        return null;

    // Init data/*from   w  ww .  j  a va  2 s.  c om*/
    int bitmapWidth = bitmap.getWidth();
    int bitmapHeight = bitmap.getHeight();

    // Color
    int backgroundColor = Color.TRANSPARENT;

    // Bounds
    int xMin = Integer.MAX_VALUE;
    int xMax = Integer.MIN_VALUE;
    int yMin = Integer.MAX_VALUE;
    int yMax = Integer.MIN_VALUE;

    // Get pixel array
    int[][] bitmapArray = new int[bitmapHeight][bitmapWidth];
    for (int y = 0; y < bitmapHeight; y++) {
        bitmap.getPixels(bitmapArray[y], 0, bitmapWidth, 0, y, bitmapWidth, 1);
    }

    // Find bitmap bound
    boolean foundPixel = false;
    // Find xMin
    for (int x = 0; x < bitmapWidth; x += SCAN_INTERVAL) {
        boolean stop = false;
        for (int y = 0; y < bitmapHeight; y += SCAN_INTERVAL) {
            if (bitmapArray[y][x] != backgroundColor) {
                xMin = x;
                stop = true;
                foundPixel = true;
                break;
            }
        }
        if (stop)
            break;
    }

    // Image is empty...
    if (!foundPixel)
        return null;

    // Find yMin
    for (int y = 0; y < bitmapHeight; y += SCAN_INTERVAL) {
        boolean stop = false;
        for (int x = xMin; x < bitmapWidth; x += SCAN_INTERVAL) {
            if (bitmapArray[y][x] != backgroundColor) {
                yMin = y;
                stop = true;
                break;
            }
        }
        if (stop)
            break;
    }

    // Find xMax
    for (int x = bitmapWidth - 1; x >= xMin; x -= SCAN_INTERVAL) {
        boolean stop = false;
        for (int y = yMin; y < bitmapHeight; y += SCAN_INTERVAL) {
            if (bitmapArray[y][x] != backgroundColor) {
                xMax = x;
                stop = true;
                break;
            }
        }
        if (stop)
            break;
    }

    // Find yMax
    for (int y = bitmapHeight - 1; y >= yMin; y -= SCAN_INTERVAL) {
        boolean stop = false;
        for (int x = xMin; x <= xMax; x += SCAN_INTERVAL) {
            if (bitmapArray[y][x] != backgroundColor) {
                yMax = y;
                stop = true;
                break;
            }
        }
        if (stop)
            break;
    }

    // Expand bitmap with offset
    int offset = SCAN_INTERVAL;
    int left = Math.max(xMin - offset, 0);
    int top = Math.max(yMin - offset, 0);
    int right = Math.min(xMax + offset, bitmapWidth);
    int bottom = Math.min(yMax + offset, bitmapHeight);

    int[] bound = { left, top, right, bottom };
    return bound;
}

From source file:Main.java

public static Drawable getAsssetDrawableByName(Context context, String name) {
    try {//from   ww  w. ja  v a2s .co  m
        InputStream is = context.getAssets().open(name);
        return new BitmapDrawable(context.getResources(), BitmapFactory.decodeStream(is));
    } catch (IOException e) {
        e.printStackTrace();
    }
    return new ColorDrawable(Color.TRANSPARENT);
}

From source file:Main.java

/**
 * Method to create a fully-transparent Bitmap using the same size of the source passed as
 * parameter and also the same density./*from w w w .  j ava  2  s.  com*/
 *
 * @param source The original Bitmap.
 * @return A transparent Bitmap with the same size of the source.
 */
public static Bitmap clear(Bitmap source) {
    Bitmap newBitmap = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight());
    //to erase the color from a Bitmap, I must use a mutable Bitmap!!!!
    Bitmap mutableBitmap = newBitmap.copy(Bitmap.Config.ARGB_8888, true);
    mutableBitmap.eraseColor(Color.TRANSPARENT);
    return mutableBitmap;
}

From source file:Main.java

static public void setImageColorPixels(ImageView view, Bitmap myBitmap, int rgbcolor)// ,Bitmap sourceBitmap)
{

    int intArray[];

    intArray = new int[myBitmap.getWidth() * myBitmap.getHeight()];

    // copy pixel data from the Bitmap into the 'intArray' array
    myBitmap.getPixels(intArray, 0, myBitmap.getHeight(), 0, 0, myBitmap.getHeight(), myBitmap.getWidth());

    // replace the red pixels with yellow ones
    for (int i = 0; i < intArray.length; i++) {
        // System.out.println("color is--" + i + " " + intArray[i]);
        if (intArray[i] != Color.TRANSPARENT) {

            intArray[i] = rgbcolor;//ww w  . j ava  2  s. co m
        }
    }
    myBitmap.setPixels(intArray, 0, myBitmap.getHeight(), 0, 0, myBitmap.getHeight(), myBitmap.getWidth());

    view.setImageBitmap(myBitmap);
}