我有兩張圖片? 如何在Android中的第一個圖像的頂部顯示第二個圖像(第二個圖像的背景必須可見,並且第一個圖像的文本應該模糊)在Android中合併兩張圖片(第一張圖片的背景和第二張圖片的文字帶有模糊效果)
換句話說,我想使用第一個圖像和文本的背景用模糊效果第二圖像
我還連接有兩個樣本圖像 的我使用Android Studio中1.3.2
我有兩張圖片? 如何在Android中的第一個圖像的頂部顯示第二個圖像(第二個圖像的背景必須可見,並且第一個圖像的文本應該模糊)在Android中合併兩張圖片(第一張圖片的背景和第二張圖片的文字帶有模糊效果)
換句話說,我想使用第一個圖像和文本的背景用模糊效果第二圖像
我還連接有兩個樣本圖像 的我使用Android Studio中1.3.2
使用容器的FrameLayout
。現在,將ImageView
放入此FrameLayout
並調整其alpha值。所以,你的佈局結構看起來就像這樣
FrameLayout (Container)
|__ImageView1 (Background)
|__ImageView2 (Text)
對於模糊效果,你可以使用任何在互聯網上的Android圖像處理庫。
創建兩個圖像的位圖,並使用Canvas
ImageView image = (ImageView) findViewById(R.id.imageView1);
Drawable drawableFore = getResources().getDrawable(R.drawable.foreg);
Drawable drawableBack = getResources().getDrawable(R.drawable.backg);
Bitmap bitmapFore = ((BitmapDrawable) drawableFore).getBitmap();
Bitmap bitmapBack = ((BitmapDrawable) drawableBack).getBitmap();
Bitmap scaledBitmapFore = Bitmap.createScaledBitmap(bitmapFore, 35, 35, true);
Bitmap scaledBitmapBack = Bitmap.createScaledBitmap(bitmapBack, 45, 45, true);
Bitmap combineImages = overlay(scaledBitmapBack, scaledBitmapFore);
image.setImageBitmap(combineImages);
覆蓋方法是在這裏mearge它..
public static Bitmap overlay(Bitmap bmp1, Bitmap bmp2)
{
try
{
Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig());
Canvas canvas = new Canvas(bmOverlay);
canvas.drawBitmap(bmp1, new Matrix(), null);
canvas.drawBitmap(bmp2, 0, 0, null);
return bmOverlay;
} catch (Exception e)
{
// TODO: handle exception
e.printStackTrace();
return null;
}
}
要麼設置的幀佈局的背景爲第一圖像,或只加對於高度和寬度都使用匹配父級的imageview。我認爲將父框架佈局的背景設置爲您的第一個圖像更有意義 –