【发布时间】:2014-01-03 02:25:32
【问题描述】:
我想提前谢谢你。我是制作 Android 应用程序的新手(实际上这是我的第一个 Android 应用程序)。在应用程序中,我让用户选择他/她的一张照片并将其作为背景放置。我收集图像并使用 putExtra 方法将其发送到正确的 Activity。
这就是我处理图像的方式:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 0){
Uri selectedImage = data.getData();
InputStream is;
try {
is = getContentResolver().openInputStream(selectedImage);
BufferedInputStream bis = new BufferedInputStream(is);
Bitmap imagen = BitmapFactory.decodeStream(bis);
final float densityMultiplier = getResources().getDisplayMetrics().density;
int h= (int) (100*densityMultiplier);
int w= (int) (h * imagen.getWidth()/((double) imagen.getHeight()));
imagen=Bitmap.createScaledBitmap(imagen, w, h, true);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
imagen.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] b = baos.toByteArray();
imagenCodificada = Base64.encodeToString(b, Base64.DEFAULT);
}
catch (FileNotFoundException e) {}
}
}
这就是我发送它的方式:
i.putExtra("Preferencia5", imagenCodificada)
在活动中,我将图像解码为位图,但我不知道如何将其作为背景放入我的 FrameLayout。
在活动中:
byte[] b = Base64.decode(imagen, Base64.DEFAULT);
Bitmap imDecodificada = BitmapFactory.decodeByteArray(b, 0, b.length);
这是我布局的 .xml 的开始:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/framelayout">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
非常感谢。
【问题讨论】:
标签: android image layout dynamic background