gpt4 book ai didi

android - 如何在 ImageView 中设置大图像

转载 作者:行者123 更新时间:2023-11-30 04:00:15 24 4
gpt4 key购买 nike

我有一个 ImageView ,我想在上面设置图像。图像的大小为 7,707,446 字节。每当我尝试设置布局时,应用程序都会崩溃,错误是内存不足错误。任何人都可以建议我如何解决它。xml 是:-

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="none">

<RelativeLayout

android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/image" >
</RelativeLayout>
</ScrollView>

最佳答案

Bitmap picture=BitmapFactory.decodeFile("/sdcard...");
int width = picture.getWidth();
int height = picture.getWidth();
float aspectRatio = (float) width / (float) height;
int newWidth = 70;
int newHeight = (int) (70 / aspectRatio);
picture= Bitmap.createScaledBitmap(picture, newWidth, newHeight, true);


public static Bitmap decodeImage(String arrayList_image) {

URL aURL;

try {

aURL = new URL(arrayList_image);

URLConnection conn = aURL.openConnection();

conn.connect();

InputStream is = conn.getInputStream();

BufferedInputStream bis = new BufferedInputStream(is);

bm = BitmapFactory.decodeStream(bis);

bis.close();

is.close();

return bm;

} catch (MalformedURLException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();
}
return null;
}

关于android - 如何在 ImageView 中设置大图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12614240/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com