List of usage examples for android.graphics ComposeShader ComposeShader
private ComposeShader(Shader shaderA, Shader shaderB, int nativeMode)
From source file:github.madmarty.madsonic.util.ImageLoader.java
private Bitmap createReflection(Bitmap originalImage) { // int reflectionH = 80; int width = originalImage.getWidth(); int height = originalImage.getHeight(); // Height of reflection int reflectionHeight = height / 2; // The gap we want between the reflection and the original image final int reflectionGap = 4; // Create a new bitmap with same width but taller to fit reflection Bitmap bitmapWithReflection = Bitmap.createBitmap(width, (height + reflectionHeight), Bitmap.Config.ARGB_8888);/*from w ww . j ava2 s . com*/ //// ---- Bitmap reflection = Bitmap.createBitmap(width, reflectionHeight, Bitmap.Config.ARGB_8888); Bitmap blurryBitmap = Bitmap.createBitmap(originalImage, 0, height - reflectionHeight, height, reflectionHeight); // cheap and easy scaling algorithm; down-scale it, then // upscale it. The filtering during the scale operations // will blur the resulting image blurryBitmap = Bitmap .createScaledBitmap( Bitmap.createScaledBitmap(blurryBitmap, blurryBitmap.getWidth() / 2, blurryBitmap.getHeight() / 2, true), blurryBitmap.getWidth(), blurryBitmap.getHeight(), true); // This shadier will hold a cropped, inverted, // blurry version of the original image BitmapShader bitmapShader = new BitmapShader(blurryBitmap, TileMode.CLAMP, TileMode.CLAMP); Matrix invertMatrix = new Matrix(); invertMatrix.setScale(1f, -1f); invertMatrix.preTranslate(0, -reflectionHeight); bitmapShader.setLocalMatrix(invertMatrix); // This shader holds an alpha gradient Shader alphaGradient = new LinearGradient(0, 0, 0, reflectionHeight, 0x80ffffff, 0x00000000, TileMode.CLAMP); // This shader combines the previous two, resulting in a // blurred, fading reflection ComposeShader compositor = new ComposeShader(bitmapShader, alphaGradient, PorterDuff.Mode.DST_IN); Paint reflectionPaint = new Paint(); reflectionPaint.setShader(compositor); // Draw the reflection into the bitmap that we will return Canvas canvas = new Canvas(reflection); canvas.drawRect(0, 0, reflection.getWidth(), reflection.getHeight(), reflectionPaint); /// ----- // Create a new Canvas with the bitmap that's big enough for // the image plus gap plus reflection Canvas finalcanvas = new Canvas(bitmapWithReflection); // Draw in the original image finalcanvas.drawBitmap(originalImage, 0, 0, null); // Draw in the gap Paint defaultPaint = new Paint(); // transparent gap defaultPaint.setColor(0); finalcanvas.drawRect(0, height, width, height + reflectionGap, defaultPaint); // Draw in the reflection finalcanvas.drawBitmap(reflection, 0, height + reflectionGap, null); return bitmapWithReflection; }
From source file:de.vanita5.twittnuker.view.ColorPickerView.java
private void drawSatValPanel(final Canvas canvas) { final RectF rect = mSatValRect; if (BORDER_WIDTH_PX > 0) { mBorderPaint.setColor(mBorderColor); canvas.drawRect(mDrawingRect.left, mDrawingRect.top, rect.right + BORDER_WIDTH_PX, rect.bottom + BORDER_WIDTH_PX, mBorderPaint); }/*from www.j av a2s .c o m*/ if (mValShader == null) { mValShader = new LinearGradient(rect.left, rect.top, rect.left, rect.bottom, 0xffffffff, 0xff000000, TileMode.CLAMP); } final int rgb = Color.HSVToColor(new float[] { mHue, 1f, 1f }); mSatShader = new LinearGradient(rect.left, rect.top, rect.right, rect.top, 0xffffffff, rgb, TileMode.CLAMP); final ComposeShader mShader = new ComposeShader(mValShader, mSatShader, PorterDuff.Mode.MULTIPLY); mSatValPaint.setShader(mShader); canvas.drawRect(rect, mSatValPaint); final Point p = satValToPoint(mSat, mVal); mSatValTrackerPaint.setColor(0xff000000); canvas.drawCircle(p.x, p.y, PALETTE_CIRCLE_TRACKER_RADIUS - 1f * mDensity, mSatValTrackerPaint); mSatValTrackerPaint.setColor(0xffdddddd); canvas.drawCircle(p.x, p.y, PALETTE_CIRCLE_TRACKER_RADIUS, mSatValTrackerPaint); }