gpt4 book ai didi

android - 即使压缩图像后内存不足错误

转载 作者:太空狗 更新时间:2023-10-29 15:05:01 26 4
gpt4 key购买 nike

这是我的代码,请检查并解决我的问题。在这里,我通过图像路径获取图像,即我在 selectimage1 中获取图像,selectimage2...继续,然后我在位图中获取图像,然后解码并减小其大小 den 也出现内存不足错误。

所以请帮我摆脱它。

谢谢

    location=(TextView) findViewById(R.id.location);
category=(TextView) findViewById(R.id.category);
subcategory=(TextView) findViewById(R.id.subcategory);
title=(EditText) findViewById(R.id.title);
description=(EditText) findViewById(R.id.description);
phonenumber=(EditText) findViewById(R.id.phonenumber);
email=(EditText) findViewById(R.id.email);
price=(EditText) findViewById(R.id.price);
postadd=(Button) findViewById(R.id.button_post);


SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
locationname = preferences.getString("Location", "Location");

SharedPreferences preferences1 = PreferenceManager.getDefaultSharedPreferences(this);
categoryname = preferences1.getString("categoryname", "categoryname");

SharedPreferences imagepath1 = PreferenceManager.getDefaultSharedPreferences(this);
selectedImagePath1 = imagepath1.getString("picturePath1", "picturePath1");


SharedPreferences imagepath2 = PreferenceManager.getDefaultSharedPreferences(this);
selectedImagePath2 = imagepath2.getString("picturePath2", "picturePath2");

SharedPreferences imagepath3 = PreferenceManager.getDefaultSharedPreferences(this);
selectedImagePath3 = imagepath3.getString("picturePath3", "picturePath3");

SharedPreferences imagepath4 = PreferenceManager.getDefaultSharedPreferences(this);
selectedImagePath4 = imagepath4.getString("picturePath4", "picturePath4");


Bitmap thumbnail1 = (BitmapFactory.decodeFile(selectedImagePath1));
ByteArrayOutputStream stream = new ByteArrayOutputStream();
thumbnail1.compress(Bitmap.CompressFormat.JPEG, 30, stream);

Bitmap thumbnail2 = (BitmapFactory.decodeFile(selectedImagePath2));
ByteArrayOutputStream stream1 = new ByteArrayOutputStream();
thumbnail2.compress(Bitmap.CompressFormat.JPEG, 30, stream1);

Bitmap thumbnail3 = (BitmapFactory.decodeFile(selectedImagePath3));
int size3 = 10;
Bitmap bitmapsimplesize3 = Bitmap.createScaledBitmap(thumbnail3 ,thumbnail3.getWidth() / size3, thumbnail3.getHeight() / size3, true);

Bitmap thumbnail4 = (BitmapFactory.decodeFile(selectedImagePath4));
int size4 = 10;
Bitmap bitmapsimplesize4 = Bitmap.createScaledBitmap(thumbnail4 ,thumbnail4.getWidth() / size4, thumbnail4.getHeight() / size4, true);

imageview1.setImageBitmap(thumbnail1);
imageview2.setImageBitmap(thumbnail2);
imageview3.setImageBitmap(bitmapsimplesize3);
imageview4.setImageBitmap(bitmapsimplesize4);

location.setText(locationname);
category.setText(categoryname);
subcategory.setText(subcategoryname);
subcategory.setVisibility(View.VISIBLE);

最佳答案

你只需要将这一行添加到你的 list 文件....它会为你的应用程序分配大内存..

android:largeHeap="true"

关于android - 即使压缩图像后内存不足错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22837320/

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