Example usage for android.graphics Bitmap setHasAlpha

List of usage examples for android.graphics Bitmap setHasAlpha

Introduction

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

Prototype

public void setHasAlpha(boolean hasAlpha) 

Source Link

Document

Tell the bitmap if all of the pixels are known to be opaque (false) or if some of the pixels may contain non-opaque alpha values (true).

Usage

From source file:Main.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
private static void setAlphaIfAvailable(Bitmap bitmap, boolean hasAlpha) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1 && bitmap != null) {
        bitmap.setHasAlpha(hasAlpha);
    }//from   w  ww.  j a v  a 2 s .c o m
}

From source file:Main.java

/**
 * Fills the bitmap's pixels of the specified Color to transparency.
 * //w ww.  jav  a 2s.  c  o  m
 * @param aBitmap bitmap to process
 * @param aColor color to fill
 * @return bmp
 */
@SuppressLint("NewApi")
public static Bitmap eraseBG(Bitmap aBitmap, int aColor) {
    int width = aBitmap.getWidth();
    int height = aBitmap.getHeight();
    Bitmap b = aBitmap.copy(Config.ARGB_8888, true);
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB_MR1) {
        b.setHasAlpha(true);
    }

    int[] pixels = new int[width * height];
    aBitmap.getPixels(pixels, 0, width, 0, 0, width, height);

    for (int i = 0; i < width * height; i++) {
        if (pixels[i] == aColor) {
            pixels[i] = 0;
        }
    }

    b.setPixels(pixels, 0, width, 0, 0, width, height);

    return b;
}

From source file:Main.java

/**
 * Crop bitmap image into a round shape/*from  w  w w.  j av  a  2s.  c om*/
 *
 * @param bitmap   the bitmap
 * @param diameter the diameter of the resulting image
 * @return the rounded bitmap
 */
private static Bitmap getRoundedShape(@NonNull Bitmap bitmap, int diameter) {

    Bitmap resultBitmap = Bitmap.createBitmap(diameter, diameter, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(resultBitmap);
    Path path = new Path();
    path.addCircle(((float) diameter - 1) / 2, ((float) diameter - 1) / 2, (((float) diameter) / 2),
            Path.Direction.CCW);

    canvas.clipPath(path);
    resultBitmap.setHasAlpha(true);
    canvas.drawBitmap(bitmap, new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()),
            new Rect(0, 0, diameter, diameter), null);
    return resultBitmap;
}

From source file:com.balieiro.facebook.FriendItem.java

/**
  * The credit of the image processing performed by this method belongs
  * to the author of this site:/*from   ww  w.  j  a  v  a 2 s .c o m*/
  * http://www.piwai.info/transparent-jpegs-done-right/
  * There is an amazing explanation on how to perform this kind of 
  * images transformations.
  */
private static Bitmap getRoundedBitmap(Bitmap source, int pictureMask) {

    BitmapFactory.Options options = new BitmapFactory.Options();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // Starting with Honeycomb, we can load the bitmap as mutable.
        options.inMutable = true;
    }
    // We could also use ARGB_4444, but not RGB_565 (we need an alpha layer).
    options.inPreferredConfig = Bitmap.Config.ARGB_8888;
    Bitmap bitmap;
    if (source.isMutable()) {
        bitmap = source;
    } else {
        bitmap = source.copy(Bitmap.Config.ARGB_8888, true);
        source.recycle();
    }
    // The bitmap is opaque, we need to enable alpha compositing.
    bitmap.setHasAlpha(true);

    Canvas canvas = new Canvas(bitmap);
    Bitmap mask = BitmapFactory.decodeResource(MyFacebookApp.getContext().getResources(), pictureMask);
    Paint paint = new Paint();
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
    canvas.drawBitmap(mask, 0, 0, paint);
    // We do not need the mask bitmap anymore.
    mask.recycle();

    return bitmap;
}

From source file:org.catrobat.paintroid.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {

    initLocaleConfiguration();/*  w w  w .j  av  a2s.  co m*/
    Configuration config = getApplicationContext().getResources().getConfiguration();
    PaintroidApplication.isRTL = (config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL);

    ColorPickerDialog.init(this);
    IndeterminateProgressDialog.init(this);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    initActionBar();
    mInputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

    PaintroidApplication.catroidPicturePath = null;
    String catroidPicturePath = null;
    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        catroidPicturePath = extras.getString(getString(R.string.extra_picture_path_catroid));

        Log.d(PaintroidApplication.TAG, "catroidPicturePath: " + catroidPicturePath);
    }
    if (catroidPicturePath != null) {
        PaintroidApplication.openedFromCatroid = true;
        if (!catroidPicturePath.equals("")) {
            PaintroidApplication.catroidPicturePath = catroidPicturePath;
            PaintroidApplication.scaleImage = false;
        }
        ActionBar supportActionBar = getSupportActionBar();
        if (supportActionBar != null) {
            supportActionBar.setDisplayHomeAsUpEnabled(true);
            supportActionBar.setDisplayShowHomeEnabled(true);
        }
    } else {
        PaintroidApplication.openedFromCatroid = false;
    }
    PaintroidApplication.orientation = getResources().getConfiguration().orientation;
    PaintroidApplication.drawingSurface = (DrawingSurface) findViewById(R.id.drawingSurfaceView);
    PaintroidApplication.perspective = new Perspective(PaintroidApplication.drawingSurface.getHolder());
    mDrawingSurfaceListener = new DrawingSurfaceListener();
    BrushPickerView.init(this);
    mBottomBar = new BottomBar(this);
    mTopBar = new TopBar(this, PaintroidApplication.openedFromCatroid);
    mLayerSideNav = (NavigationView) findViewById(R.id.nav_view_layer);
    mLayersAdapter = new LayersAdapter(this, PaintroidApplication.openedFromCatroid,
            PaintroidApplication.drawingSurface.getBitmapCopy());

    int colorPickerBackgroundColor = PaintroidApplication.colorPickerInitialColor;
    ColorPickerDialog.getInstance().setInitialColor(colorPickerBackgroundColor);

    PaintroidApplication.drawingSurface.setOnTouchListener(mDrawingSurfaceListener);

    if (PaintroidApplication.openedFromCatroid && catroidPicturePath != null
            && catroidPicturePath.length() > 0) {
        initializeWhenOpenedFromCatroid();

        loadBitmapFromUriAndRun(Uri.fromFile(new File(catroidPicturePath)), new RunnableWithBitmap() {
            @Override
            public void run(Bitmap bitmap) {
                if (!bitmap.hasAlpha()) {
                    bitmap.setHasAlpha(true);
                }
                handleAndAssignImage(bitmap);
            }

            private void handleAndAssignImage(Bitmap bitmap) {
                Command command = new LoadCommand(bitmap);
                PaintroidApplication.commandManager.commitCommandToLayer(
                        new LayerCommand(LayerListener.getInstance().getCurrentLayer()), command);

            }
        });

    } else if (PaintroidApplication.openedFromCatroid) {
        initializeWhenOpenedFromCatroid();
    } else {
        initialiseNewBitmap();
    }

    if (PaintroidApplication.openedFromCatroid == false)
        LayerListener.init(this, mLayerSideNav, PaintroidApplication.drawingSurface.getBitmapCopy(), false);

    if (!PaintroidApplication.commandManager.isCommandManagerInitialized()
            || PaintroidApplication.openedFromCatroid)
        initCommandManager();

    initNavigationDrawer();
    initKeyboardIsShownListener();
}

From source file:com.hotstar.player.adplayer.player.PlayerFragment.java

/**
 * Initialize the player fragment by setting up views, media player and
 * feature managers/*from ww  w.j  a v a2s  . co  m*/
 * 
 * @param intent
 *            the intent that contains the video item
 */
private void initialize(Intent intent) {
    videoItem = (VideoItem) intent.getExtras().getSerializable("CONTENT_INFO");
    AdVideoApplication.logger.i(LOG_TAG + "#initialize",
            "Initializing the media player with item [" + videoItem.getTitle() + "].");

    playerClickableAdFragment = (PlayerClickableAdFragment) getActivity().getSupportFragmentManager()
            .findFragmentById(R.id.playerClickInfo);
    playerFrame = (FrameLayout) playerFragmentView.findViewById(R.id.playerFrame);

    ViewGroup controlBarView = (ViewGroup) playerFragmentView.findViewById(R.id.ControlBarItem);
    controlBar = new PlayerControlBar(getActivity(), controlBarView);

    // ViewGroup controlTopBarView = (ViewGroup) playerFragmentView.findViewById(R.id.ControlTopBarItem);
    // controlTopBar = new PlayerControlTopBar(getActivity(), controlTopBarView);

    ViewGroup controlAdBarView = (ViewGroup) playerFragmentView.findViewById(R.id.AdControlBarItem);
    controlAdBar = new PlayerAdControlBar(getActivity(), controlAdBarView);

    spinner = (ProgressBar) playerFragmentView.findViewById(R.id.pbBufferingSpinner);

    overlayAdImageView = (ImageView) playerFragmentView.findViewById(R.id.overlayAdImageView);
    overlayAdGifView = (GifImageView) playerFragmentView.findViewById(R.id.overlayAdGifView);
    overlayAdGifView.setOnFrameAvailable(new GifImageView.OnFrameAvailable() {
        @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
        @Override
        public Bitmap onFrameAvailable(Bitmap bitmap) {
            return bitmap;
        }
    });

    java.io.InputStream is;
    is = mActivity.getResources().openRawResource(R.drawable.vpaid_ad_icon);

    vpaidAdIconGifView = (GifImageView) playerFragmentView.findViewById(R.id.vpaidAdIconGifView);
    vpaidAdIconGifView.setBytes(BytesManager.getBytes(is));
    vpaidAdIconGifView.setOnFrameAvailable(new GifImageView.OnFrameAvailable() {
        @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
        @Override
        public Bitmap onFrameAvailable(Bitmap src) {
            if (src == null)
                return src;

            int width = src.getWidth();
            int height = src.getHeight();
            Bitmap b = src.copy(Bitmap.Config.ARGB_8888, true);
            b.setHasAlpha(true);

            int[] pixels = new int[width * height];
            src.getPixels(pixels, 0, width, 0, 0, width, height);

            for (int i = 0; i < width * height; i++) {
                if ((pixels[i] == WHITE_COLOR) || (pixels[i] == BLACK_COLOR)) {
                    pixels[i] = 0;
                }
            }

            b.setPixels(pixels, 0, width, 0, 0, width, height);
            return b;
        }
    });
    vpaidAdIconGifView.setVisibility(View.INVISIBLE);
    vpaidAdIconGifView.setOnClickListener(vPaidADIconClickListener);

    thumbnailPlayImageView = (ImageView) playerFragmentView.findViewById(R.id.thumbnailPlayImageView);
    thumbnailPlayImageView.setVisibility(View.INVISIBLE);
    thumbnailImageView = (ImageView) playerFragmentView.findViewById(R.id.thumbnailImageView);
    thumbnailImageView.setVisibility(View.INVISIBLE);
    thumbnailImageView.setOnClickListener(thumbnailViewClickListener);
    OverlayAdResourceManager.getInstance().preloadImage(videoItem.getThumbnail().getLargeThumbnailUrl());

    //      audioProfile = (TextView) playerFragmentView.findViewById(R.id.audioTextView);
    //      audioProfile.setText(R.string.qosAudioProfile);
    //      audioProfile.setVisibility(View.INVISIBLE);
    //
    //      _ccButton = (ImageButton) playerFragmentView.findViewById(R.id.sbPlayerControlCC);
    //      _rewindButton = (ImageButton) playerFragmentView.findViewById(R.id.playerRewind);
    ((CustomFrameLayout) playerFrame).addOnSizeChangeListener(new OnSizeChangeListener() {

        @Override
        public void onSizeChanged() {
            // Scale player, since container size has changed.
            handler.post(new Runnable() {

                @Override
                public void run() {
                    setPlayerViewSize(savedMovieWidth, savedMovieHeight);
                }
            });
        }
    });

    createPlayer();
    setupViews();
    createManagers();
    prepareMedia();
}