Java Code Examples for android.graphics.Canvas#drawBitmapMesh()
The following examples show how to use
android.graphics.Canvas#drawBitmapMesh() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RenderableThree.java From Depth with MIT License | 5 votes |
@Override public void draw(Canvas canvas) { createPath(); // alphaCanvas.drawPath(pathLeft, debugPaint); // alphaCanvas.drawPath(pathRight, debugPaint); canvas.save(); if (scaleX != 1.f || scaleY != 1f) { canvas.scale(scaleX, scaleY, x + bitmap.getWidth() / 2, y + bitmap.getHeight()); } canvas.drawBitmapMesh(bitmap, HORIZONTAL_SLICES, VERTICAL_SLICES, drawingVerts, 0, null, 0, paint); canvas.restore(); }
Example 2
Source File: RenderableThree.java From Depth with MIT License | 5 votes |
@Override public void draw(Canvas canvas) { createPath(); // alphaCanvas.drawPath(pathLeft, debugPaint); // alphaCanvas.drawPath(pathRight, debugPaint); canvas.save(); if (scaleX != 1.f || scaleY != 1f) { canvas.scale(scaleX, scaleY, x + bitmap.getWidth() / 2, y + bitmap.getHeight()); } canvas.drawBitmapMesh(bitmap, HORIZONTAL_SLICES, VERTICAL_SLICES, drawingVerts, 0, null, 0, paint); canvas.restore(); }
Example 3
Source File: RippleLayout.java From android-open-source-project-analysis with Apache License 2.0 | 5 votes |
@Override protected void dispatchDraw(Canvas canvas) { if (isRippling && bitmap != null) { canvas.drawBitmapMesh(bitmap, MESH_WIDTH, MESH_HEIGHT, targetVerts, 0, null, 0, null); } else { super.dispatchDraw(canvas); } }
Example 4
Source File: RenderableThree.java From Android-Plugin-Framework with MIT License | 5 votes |
@Override public void draw(Canvas canvas) { createPath(); // alphaCanvas.drawPath(pathLeft, debugPaint); // alphaCanvas.drawPath(pathRight, debugPaint); canvas.save(); if (scaleX != 1.f || scaleY != 1f) { canvas.scale(scaleX, scaleY, x + bitmap.getWidth() / 2, y + bitmap.getHeight()); } canvas.drawBitmapMesh(bitmap, HORIZONTAL_SLICES, VERTICAL_SLICES, drawingVerts, 0, null, 0, paint); canvas.restore(); }
Example 5
Source File: CurtainView.java From MTransition with Apache License 2.0 | 4 votes |
@Override public void onDraw(Canvas canvas) { if(this.bitmap != null){ int index = 0; float ratio = (float) touchX / (float) width; float gap = 60.0F * (direction == DIRECTION_LEFT ? ratio : (1 - ratio)); int alpha = 0; for (int y = 0; y <= bitmapHeight; y++) { float fy = height / bitmapHeight * y; float longDisSide = touchY > height - touchY ? touchY : height - touchY; float longRatio = Math.abs(fy - touchY) / longDisSide; longRatio = interpolator.getInterpolation(longRatio); float realWidth = longRatio * (touchX - delayOffsetX); float xBlock = (float) width / (float) bitmapWidth; for (int x = 0; x <= bitmapWidth; x++) { ratio = (touchX - realWidth) / (float) width; switch(direction){ case DIRECTION_LEFT: verts[index * 2] = (bitmapWidth - x) * xBlock * ratio + (x * xBlock); break; case DIRECTION_RIGHT: verts[index * 2] = x * xBlock * ratio; break; } float realHeight = height - ((float) Math.sin(x * 0.5F - Math.PI) * gap + gap); float offsetY = realHeight / bitmapHeight * y; verts[index * 2 + 1] = (height - realHeight) / 2 + offsetY; int color; int channel = 255 - (int) (height - realHeight) * 2; if (channel < 255) { alpha = (int) ((255 - channel) / 120.0F * maxAlpha) * 4; } if (newApiFlag) { channel = channel < 0 ? 0 : channel; channel = channel > 255 ? 255 : channel; color = 0xFF000000 | channel << 16 | channel << 8 | channel; colors[index] = color; } index += 1; } } canvas.drawBitmapMesh(bitmap, bitmapWidth, bitmapHeight, verts, 0, colors, 0, null); if (!newApiFlag) { alpha = alpha > 255 ? 255 : alpha; alpha = alpha < 0 ? 0 : alpha; paint.setAlpha(alpha); canvas.drawBitmapMesh(shadowMask, bitmapWidth, bitmapHeight, verts, 0, null, 0, paint); paint.setAlpha(255); } } }
Example 6
Source File: PathBitmapMesh.java From Depth with MIT License | 4 votes |
public void draw(Canvas canvas) { canvas.drawBitmapMesh(bitmap, HORIZONTAL_SLICES, VERTICAL_SLICES, drawingVerts, 0, null, 0, paint); }
Example 7
Source File: PathBitmapMesh.java From HaiNaBaiChuan with Apache License 2.0 | 4 votes |
public void draw(Canvas canvas) { canvas.drawBitmapMesh(bitmap, HORIZONTAL_SLICES, VERTICAL_SLICES, drawingVerts, 0, null, 0, paint); }
Example 8
Source File: BitmapMeshView.java From AndroidAnimationExercise with Apache License 2.0 | 4 votes |
@Override protected void onDraw(Canvas canvas) { //对bitmap按verts数组进行扭曲 //从第一个点(由第5个参数0控制)开始扭曲 canvas.drawBitmapMesh(mBitmap, WIDTH, HEIGHT, verts, 0, null, 0, null); }
Example 9
Source File: CurtainView.java From CurtainSlidingMenu with MIT License | 4 votes |
@Override public void onDraw(Canvas canvas) { if(this.bitmap != null){ int index = 0; float ratio = (float) touchX / (float) width; float gap = 60.0F * (direction == DIRECTION_LEFT ? ratio : (1 - ratio)); int alpha = 0; for (int y = 0; y <= bitmapHeight; y++) { float fy = height / bitmapHeight * y; float longDisSide = touchY > height - touchY ? touchY : height - touchY; float longRatio = Math.abs(fy - touchY) / longDisSide; longRatio = interpolator.getInterpolation(longRatio); float realWidth = longRatio * (touchX - delayOffsetX); float xBlock = (float) width / (float) bitmapWidth; for (int x = 0; x <= bitmapWidth; x++) { ratio = (touchX - realWidth) / (float) width; switch(direction){ case DIRECTION_LEFT: verts[index * 2] = (bitmapWidth - x) * xBlock * ratio + (x * xBlock); break; case DIRECTION_RIGHT: verts[index * 2] = x * xBlock * ratio; break; } float realHeight = height - ((float) Math.sin(x * 0.5F - Math.PI) * gap + gap); float offsetY = realHeight / bitmapHeight * y; verts[index * 2 + 1] = (height - realHeight) / 2 + offsetY; int color; int channel = 255 - (int) (height - realHeight) * 2; if (channel < 255) { alpha = (int) ((255 - channel) / 120.0F * maxAlpha) * 4; } if (newApiFlag) { channel = channel < 0 ? 0 : channel; channel = channel > 255 ? 255 : channel; color = 0xFF000000 | channel << 16 | channel << 8 | channel; colors[index] = color; } index += 1; } } canvas.drawBitmapMesh(bitmap, bitmapWidth, bitmapHeight, verts, 0, colors, 0, null); if (!newApiFlag) { alpha = alpha > 255 ? 255 : alpha; alpha = alpha < 0 ? 0 : alpha; paint.setAlpha(alpha); canvas.drawBitmapMesh(shadowMask, bitmapWidth, bitmapHeight, verts, 0, null, 0, paint); paint.setAlpha(255); } } }
Example 10
Source File: PathBitmapMesh.java From Android-Plugin-Framework with MIT License | 4 votes |
public void draw(Canvas canvas) { canvas.drawBitmapMesh(bitmap, HORIZONTAL_SLICES, VERTICAL_SLICES, drawingVerts, 0, null, 0, paint); }
Example 11
Source File: Smoke.java From Android-Plugin-Framework with MIT License | 4 votes |
@Override public void draw(Canvas canvas) { // alphaCanvas.drawPath(smokePath, paint); canvas.drawBitmapMesh(bitmap, HORIZONTAL_SLICES, VERTICAL_SLICES, drawingVerts, 0, null, 0, paint); }
Example 12
Source File: ImageUtil.java From Augendiagnose with GNU General Public License v2.0 | 4 votes |
/** * Deform the overlay bitmap according to a different pupil size. * * @param sourceBitmap The original overlay bitmap. * @param origPupilSize The pupil size (relative to iris) in the original overlay bitmap. * @param destPupilSize The pupil size (relative to iris) in the target overlay bitmap. * @param pupilOffsetX The x offset of the pupil center, relative to the iris size * @param pupilOffsetY The y offset of the pupil center, relative to the iris size * @return The deformed overlay bitmap. */ public static Bitmap deformOverlayByPupilSize(@NonNull final Bitmap sourceBitmap, final float origPupilSize, final float destPupilSize, @Nullable final Float pupilOffsetX, @Nullable final Float pupilOffsetY) { if (origPupilSize == 0) { // non-deformable overlay, such as pupil overlay. return sourceBitmap; } int overlaySize = sourceBitmap.getWidth(); int overlayHalfSize = overlaySize / 2; float irisRadius = overlayHalfSize * OverlayPinchImageView.OVERLAY_CIRCLE_RATIO; // the center of enlargement float targetCenterX = overlayHalfSize; float targetCenterY = overlayHalfSize; if (pupilOffsetX != null) { targetCenterX += 2 * irisRadius * pupilOffsetX / (1 - destPupilSize); } if (pupilOffsetY != null) { targetCenterY += 2 * irisRadius * pupilOffsetY / (1 - destPupilSize); } // Constants used for linear transformation of the iris part of the overlay. float linTransB = (destPupilSize - origPupilSize) / (1 - origPupilSize); float linTransM = (1 - destPupilSize) / (irisRadius * (1 - origPupilSize)); float absOrigPupilSize = origPupilSize * irisRadius; Bitmap ret = Bitmap.createBitmap(overlaySize, overlaySize, sourceBitmap.getConfig()); Canvas canvas = new Canvas(ret); float[] verts = new float[2 * (OVERLAY_MESH_SIZE + 1) * (OVERLAY_MESH_SIZE + 1)]; int vertsIndex = 0; for (int y = 0; y <= OVERLAY_MESH_SIZE; y++) { for (int x = 0; x <= OVERLAY_MESH_SIZE; x++) { // The positions of the original mesh vertices in pixels relative to the center float xPos = (float) x * overlaySize / OVERLAY_MESH_SIZE - overlayHalfSize; float yPos = (float) y * overlaySize / OVERLAY_MESH_SIZE - overlayHalfSize; float centerDist = (float) Math.sqrt(xPos * xPos + yPos * yPos); if (centerDist >= irisRadius) { // outside the iris, take original position verts[vertsIndex++] = overlayHalfSize + xPos; verts[vertsIndex++] = overlayHalfSize + yPos; } else if (centerDist == 0) { verts[vertsIndex++] = targetCenterX; verts[vertsIndex++] = targetCenterY; } else { // original direction float xDirection = xPos / centerDist; float yDirection = yPos / centerDist; // corresponding iris boundary point float xBound = overlayHalfSize + xDirection * irisRadius; float yBound = overlayHalfSize + yDirection * irisRadius; float radialPosition = linTransM * centerDist + linTransB; if (centerDist < absOrigPupilSize) { radialPosition -= linTransB * Math.pow(1 - centerDist / absOrigPupilSize, 1.5f); // MAGIC_NUMBER } verts[vertsIndex++] = targetCenterX + (xBound - targetCenterX) * radialPosition; verts[vertsIndex++] = targetCenterY + (yBound - targetCenterY) * radialPosition; } } } Paint paint = new Paint(); paint.setFilterBitmap(true); canvas.drawBitmapMesh(sourceBitmap, OVERLAY_MESH_SIZE, OVERLAY_MESH_SIZE, verts, 0, null, 0, paint); return ret; }
Example 13
Source File: Smoke.java From Depth with MIT License | 3 votes |
@Override public void draw(Canvas canvas) { // alphaCanvas.drawPath(smokePath, paint); canvas.drawBitmapMesh(bitmap, HORIZONTAL_SLICES, VERTICAL_SLICES, drawingVerts, 0, null, 0, paint); }
Example 14
Source File: Smoke.java From Depth with MIT License | 3 votes |
@Override public void draw(Canvas canvas) { // alphaCanvas.drawPath(smokePath, paint); canvas.drawBitmapMesh(bitmap, HORIZONTAL_SLICES, VERTICAL_SLICES, drawingVerts, 0, null, 0, paint); }