0
我一直在試圖創建像這張照片一樣的3d文本如何在android中創建3D文本
爲此,我編寫了下面的代碼。它幾乎是從前面看到的3d,但如果在x軸上旋轉,它有一個點在90度處消失。 對於三維文字,商店中也很少有應用程序。 我首先將文本轉換爲位圖,然後應用疊加以提供3D效果。
img= (ImageView) findViewById(R.id.imageView);
skBar= (SeekBar) findViewById(R.id.seekBar);
Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.img);
bm = textAsBitmap("TEXT CHECK", 140.0f, Color.BLUE);
img.setImageBitmap(overlay(bm,bm));
skBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
img.setRotationY(Float.parseFloat(String.valueOf(progress)));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
public static Bitmap overlay(Bitmap bmp1, Bitmap bmp2) {
Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig());
Canvas canvas = new Canvas(bmOverlay);
canvas.drawBitmap(bmp1, new Matrix(), null);
for (float i = 20; i > 0; i-=0.5f) {
canvas.drawBitmap(bmp2, i, i, null);
}
for (float i = 1; i <= 20; i+=0.5f) {
canvas.drawBitmap(bmp2, i, i, null);
}
return bmOverlay;
}
public Bitmap textAsBitmap(String text, float textSize, int textColor) {
Paint paint = new Paint();
paint.setTextSize(textSize);
paint.setColor(textColor);
paint.setTextAlign(Paint.Align.LEFT);
paint.setTextScaleX(1.5f);
// paint.setTexth(5.0f);
float baseline = -paint.ascent(); // ascent() is negative
int width = (int) (paint.measureText(text) + 0.5f); // round
int height = (int) (baseline + paint.descent() + 0.5f);
Bitmap image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(image);
canvas.drawText(text, 0, baseline, paint);
return image;
}
感謝您的鏈接,但我已經檢查了這些。 – farhan678