그림자 효과 이미지 비트맵의 함수
view sourceprint?
01 package com.util;
02
03 import android.graphics.Bitmap;
04 import android.graphics.Bitmap.Config;
05 import android.graphics.Canvas;
06 import android.graphics.Color;
07 import android.graphics.LinearGradient;
08 import android.graphics.Matrix;
09 import android.graphics.Paint;
10 import android.graphics.PorterDuff.Mode;
11 import android.graphics.PorterDuffXfermode;
12 import android.graphics.Shader.TileMode;
13
14 public class BitmapUtil {
15
16 public static Bitmap createTxtImage(String txt, int txtSize) {
17 Bitmap mbmpTest = Bitmap.createBitmap(txt.length() * txtSize + 4,
18 txtSize + 4, Config.ARGB_8888);
19 Canvas canvasTemp = new Canvas(mbmpTest);
20 Paint p = new Paint();
21 p.setAntiAlias(true);
22 p.setColor(Color.WHITE);
23 p.setTextSize(txtSize);
24 canvasTemp.drawText(txt, 2, txtSize - 2, p);
25 return mbmpTest;
26 }
27
28 public static Bitmap createReflectedImage(Bitmap originalImage) {
29 // The gap we want between the reflection and the original image
30 final int reflectionGap = 0;
31
32 int width = originalImage.getWidth();
33 int height = originalImage.getHeight();
34
35 // This will not scale but will flip on the Y axis
36 Matrix matrix = new Matrix();
37 matrix.preScale(1, -1);
38
39 // Create a Bitmap with the flip matrix applied to it.
40 // We only want the bottom half of the image
41 Bitmap reflectionImage = Bitmap.createBitmap(originalImage, 0,
42 height / 2, width, height / 2, matrix, false);
43
44 // Create a new bitmap with same width but taller to fit reflection
45 Bitmap bitmapWithReflection = Bitmap.createBitmap(width,
46 (height + height / 2), Config.ARGB_8888);
47
48 // Create a new Canvas with the bitmap that's big enough for
49 // the image plus gap plus reflection
50 Canvas canvas = new Canvas(bitmapWithReflection);
51 // Draw in the original image
52 canvas.drawBitmap(originalImage, 0, 0, null);
53 // Draw in the gap
54 Paint defaultPaint = new Paint();
55 canvas.drawRect(0, height, width, height + reflectionGap, defaultPaint);
56 // Draw in the reflection
57 canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null);
58
59 // Create a shader that is a linear gradient that covers the reflection
60 Paint paint = new Paint();
61 LinearGradient shader = new LinearGradient(0,
62 originalImage.getHeight(), 0, bitmapWithReflection.getHeight()
63 + reflectionGap, 0x70ffffff, 0x00ffffff, TileMode.CLAMP);
64 // Set the paint to use this shader (linear gradient)
65 paint.setShader(shader);
66 // Set the Transfer mode to be porter duff and destination in
67 paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
68 // Draw a rectangle using the paint with our linear gradient
69 canvas.drawRect(0, height, width, bitmapWithReflection.getHeight()
70 + reflectionGap, paint);
71
72 return bitmapWithReflection;
73 }
74 }
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.