set Bitmap Alpha - Android Graphics

Android examples for Graphics:Bitmap Color

Description

set Bitmap Alpha

Demo Code


//package com.java2s;

import android.graphics.Bitmap;

import android.graphics.Bitmap.Config;

public class Main {

    public static Bitmap setAlpha(Bitmap sourceImg, int number) {
        int[] argb = new int[sourceImg.getWidth() * sourceImg.getHeight()];
        sourceImg.getPixels(argb, 0, sourceImg.getWidth(), 0, 0,
                sourceImg.getWidth(), sourceImg.getHeight());
        number = number * 255 / 100;//from w  ww  . j a  va 2s  . c o m
        for (int i = 0; i < argb.length; i++) {
            argb[i] = (number << 24) | (argb[i] & 0x00FFFFFF);
        }
        sourceImg = Bitmap.createBitmap(argb, sourceImg.getWidth(),
                sourceImg.getHeight(), Config.ARGB_8888);
        return sourceImg;
    }
}

Related Tutorials