List of usage examples for android.graphics PorterDuffXfermode PorterDuffXfermode
public PorterDuffXfermode(PorterDuff.Mode mode)
From source file:com.android.leanlauncher.IconCache.java
private void renderIconBackground(Bitmap icon, Bitmap maskImage, Canvas tempCanvas, int w, int h, boolean drawOver) { // draw the scaled bitmap with mask Bitmap mutableMask = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); Canvas maskCanvas = new Canvas(mutableMask); maskCanvas.drawBitmap(maskImage, 0, 0, new Paint()); // paint the bitmap with mask into the result Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setXfermode(new PorterDuffXfermode(drawOver ? DST_OUT : DST_IN)); tempCanvas.drawBitmap(icon, (w - icon.getWidth()) / 2, (h - icon.getHeight()) / 2, null); tempCanvas.drawBitmap(mutableMask, 0, 0, paint); paint.setXfermode(null);// ww w .j av a2 s.c o m }
From source file:com.c4mprod.utils.ImageManager.java
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); final RectF rectF = new RectF(rect); final float roundPx = 20; paint.setAntiAlias(true);// ww w. ja va 2s .co m canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); if (output != bitmap) { bitmap.recycle(); } return output; }
From source file:edu.mum.ml.group7.guessasketch.android.EasyPaint.java
@Override public boolean onOptionsItemSelected(MenuItem item) { mPaint.setXfermode(null);/*from w w w . jav a 2 s . c o m*/ mPaint.setAlpha(0xFF); switch (item.getItemId()) { case R.id.normal_brush_menu: mPaint.setShader(null); mPaint.setMaskFilter(null); return true; case R.id.color_menu: new ColorPickerDialog(this, this, mPaint.getColor()).show(); return true; case R.id.size_menu: { LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.brush, (ViewGroup) findViewById(R.id.root)); AlertDialog.Builder builder = new AlertDialog.Builder(this).setView(layout); builder.setTitle(R.string.choose_width); final AlertDialog alertDialog = builder.create(); alertDialog.show(); SeekBar sb = (SeekBar) layout.findViewById(R.id.brushSizeSeekBar); sb.setProgress(getStrokeSize()); final TextView txt = (TextView) layout.findViewById(R.id.sizeValueTextView); txt.setText( String.format(getResources().getString(R.string.your_selected_size_is), getStrokeSize() + 1)); sb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { public void onProgressChanged(SeekBar seekBar, final int progress, boolean fromUser) { // Do something here with new value mPaint.setStrokeWidth(progress); txt.setText( String.format(getResources().getString(R.string.your_selected_size_is), progress + 1)); } @Override public void onStartTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } @Override public void onStopTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } }); return true; } case R.id.erase_menu: { LayoutInflater inflater_e = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View layout_e = inflater_e.inflate(R.layout.brush, (ViewGroup) findViewById(R.id.root)); AlertDialog.Builder builder_e = new AlertDialog.Builder(this).setView(layout_e); builder_e.setTitle(R.string.choose_width); final AlertDialog alertDialog_e = builder_e.create(); alertDialog_e.show(); SeekBar sb_e = (SeekBar) layout_e.findViewById(R.id.brushSizeSeekBar); sb_e.setProgress(getStrokeSize()); final TextView txt_e = (TextView) layout_e.findViewById(R.id.sizeValueTextView); txt_e.setText( String.format(getResources().getString(R.string.your_selected_size_is), getStrokeSize() + 1)); sb_e.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { public void onProgressChanged(SeekBar seekBar, final int progress, boolean fromUser) { // Do something here with new value mPaint.setStrokeWidth(progress); txt_e.setText( String.format(getResources().getString(R.string.your_selected_size_is), progress + 1)); } public void onStartTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } public void onStopTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } }); mPaint.setShader(null); mPaint.setXfermode(new PorterDuffXfermode(Mode.CLEAR)); return true; } case R.id.clear_all_menu: { contentView.mBitmap.eraseColor(Color.TRANSPARENT); if (predictions != null) { resetPredictionsView(predictions, true); } return true; } case R.id.save_menu: sendScreenshot(false, ApiCallType.GUESS_IMAGE, ""); break; case R.id.about_menu: startActivity(new Intent(this, AboutActivity.class)); break; } return super.onOptionsItemSelected(item); }
From source file:com.benefit.buy.library.http.query.callback.BitmapAjaxCallback.java
private static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); final RectF rectF = new RectF(rect); final float roundPx = pixels; paint.setAntiAlias(true);/*from w w w . j a va 2 s. c om*/ canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; }
From source file:com.appbase.androidquery.callback.BitmapAjaxCallback.java
private static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); final RectF rectF = new RectF(rect); final float roundPx = pixels; paint.setAntiAlias(true);/*from w w w. j a v a 2s .co m*/ canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; }
From source file:com.google.android.apps.muzei.settings.ChooseSourceFragment.java
private void prepareGenerateSourceImages() { mImageFillPaint.setColor(Color.WHITE); mImageFillPaint.setAntiAlias(true);/*from ww w . j a v a2 s . c o m*/ mAlphaPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT)); mSelectedSourceImage = new BitmapDrawable(getResources(), generateSourceImage( ResourcesCompat.getDrawable(getResources(), R.drawable.ic_source_selected, null))); }
From source file:org.mariotaku.twidere.util.Utils.java
public static Bitmap createAlphaGradientBanner(final Bitmap orig) { if (orig == null) return null; final int width = orig.getWidth(), height = orig.getHeight(); final Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(bitmap); final Paint paint = new Paint(); final LinearGradient shader = new LinearGradient(width / 2, 0, width / 2, height, 0xffffffff, 0x00ffffff, Shader.TileMode.CLAMP);//from ww w . ja v a 2 s. c o m paint.setShader(shader); paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN)); canvas.drawBitmap(orig, 0, 0, null); canvas.drawRect(0, 0, width, height, paint); return bitmap; }
From source file:com.malin.rxjava.activity.MainActivity.java
private void recycleImageView() { //ImageView?? if (mGoToRecycleImageView) { Logger.d("onDestroy()> RecycleBitmap.recycleImageView(mImageView)"); RecycleBitmap.recycleImageView(mImageView); mImageView.setImageBitmap(null); }// ww w. j a va 2 s. c o m if (mManyBitmapSuperposition != null && !mManyBitmapSuperposition.isRecycled()) { mManyBitmapSuperposition.recycle(); mManyBitmapSuperposition = null; } //@link http://blog.csdn.net/yanzi1225627/article/details/8236309 if (mCanvas != null) { //? Paint paint = new Paint(); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); mCanvas.drawPaint(paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC)); mCanvas = null; } }
From source file:com.tct.mail.browse.MessageHeaderView.java
/** * Frames the input bitmap in a circle./*from www . java2 s . c o m*/ */ private static Bitmap frameBitmapInCircle(Bitmap input) { if (input == null) { return null; } // Crop the image if not squared. int inputWidth = input.getWidth(); int inputHeight = input.getHeight(); int targetX, targetY, targetSize; if (inputWidth >= inputHeight) { targetX = inputWidth / 2 - inputHeight / 2; targetY = 0; targetSize = inputHeight; } else { targetX = 0; targetY = inputHeight / 2 - inputWidth / 2; targetSize = inputWidth; } // Create an output bitmap and a canvas to draw on it. Bitmap output = Bitmap.createBitmap(targetSize, targetSize, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); // Create a black paint to draw the mask. Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setColor(Color.BLACK); // Draw a circle. canvas.drawCircle(targetSize / 2, targetSize / 2, targetSize / 2, paint); // Replace the black parts of the mask with the input image. paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(input, targetX /* left */, targetY /* top */, paint); return output; }