【发布时间】:2016-01-01 03:01:11
【问题描述】:
我是 android 新手,遵循 this 在 android 中创建 MEME 应用程序的教程一切正常,直到我将图像添加到片段的 RelativeLayout 背景。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:background="@drawable/dp"
android:id="@+id/imageOut">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/topText"
android:id="@+id/topMemeText"
android:layout_marginTop="32dp"
android:textColor="#FFF"
android:gravity="center_horizontal"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/bottomText"
android:id="@+id/bottomMemeText"
android:layout_marginBottom="69dp"
android:textColor="#FFF"
android:gravity="center_horizontal"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
错误是
Caused by: java.lang.OutOfMemoryError: Failed to allocate a 86687164 byte allocation with 1048576 free bytes and 63MB until OOM
我知道这个问题是由于图像大小造成的,我必须对其进行解码,因为我在网上搜索了很多案例,在这里http://developer.android.com/training/displaying-bitmaps/load-bitmap.html。但是我遇到的每个案例都使用 ImageView,但我有一个背景图像布局而不是 ImageView 所以我如何从布局中获取 ImageView 对象以便我可以使用。
mImageView.setImageBitmap(
decodeSampledBitmapFromResource(getResources(), R.id.myimage, 100, 100));
谢谢
【问题讨论】:
-
您使用的图片的像素大小是多少?
-
尺寸为
262kb我知道如果我使用小尺寸图片,问题可能会解决,但我如何使用像素代码处理它1790 x 1757 -
但是像素大小(图像的尺寸)是多少?
-
@UdiI 它的
1790 x 1757 -
图片位于哪个 Drawable 中,您在哪个设备上尝试过?
标签: java android image memory bitmap