内存不足的错误即使COM

内存不足的错误即使COM

本文介绍了内存不足的错误即使COM pressing图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的code请检查并解决我的问题。
在此IM通过图像路径获得的图像也就是我正在以 selectimage1 selectimage2 ...的推移和从那以后,我已经拍摄的图像中的位图,然后去code和减小其尺寸巢穴也越来越内存不足的错误。

所以,请帮我把它弄出来。

感谢

 位置=(的TextView)findViewById(R.id.location);
    类别=(的TextView)findViewById(R.id.category);
    子类=(的TextView)findViewById(R.id.subcategory);
    标题=(EditText上)findViewById(R.id.title);
    说明=(EditText上)findViewById(R.id.description);
    PHONENUMBER =(EditText上)findViewById(R.id.phonenumber);
    电子邮件=(EditText上)findViewById(R.id.email);
    价格=(EditText上)findViewById(R.id.price);
    postadd =(按钮)findViewById(R.id.button_post);
    共享preferences preferences = preferenceManager.getDefaultShared preferences(本);
    LOCATIONNAME = preferences.getString(位置,位置);    共享preferences preferences1 = preferenceManager.getDefaultShared preferences(本);
    类别名称= preferences1.getString(类别名称,类别名称);    共享preferences imagepath1 = preferenceManager.getDefaultShared preferences(本);
    selectedImagePath1 = imagepath1.getString(picturePath1,picturePath1);
    共享preferences imagepath2 = preferenceManager.getDefaultShared preferences(本);
    selectedImagePath2 = imagepath2.getString(picturePath2,picturePath2);    共享preferences imagepath3 = preferenceManager.getDefaultShared preferences(本);
    selectedImagePath3 = imagepath3.getString(picturePath3,picturePath3);    共享preferences imagepath4 = preferenceManager.getDefaultShared preferences(本);
    selectedImagePath4 = imagepath4.getString(picturePath4,picturePath4);
    位图thumbnail1 =(BitmapFactory.de codeFILE(selectedImagePath1));
    ByteArrayOutputStream流=新ByteArrayOutputStream();
    thumbnail1.com preSS(Bitmap.Com pressFormat.JPEG,30,流);    位图thumbnail2 =(BitmapFactory.de codeFILE(selectedImagePath2));
    ByteArrayOutputStream流1 =新ByteArrayOutputStream();
    thumbnail2.com preSS(Bitmap.Com pressFormat.JPEG,30,流1);    位图thumbnail3 =(BitmapFactory.de codeFILE(selectedImagePath3));
    INT size3 = 10;
    位图bitmapsimplesize3 = Bitmap.createScaledBitmap(thumbnail3,thumbnail3.getWidth()/ size3,thumbnail3.getHeight()/ size3,真正的);    位图thumbnail4 =(BitmapFactory.de codeFILE(selectedImagePath4));
    INT尺寸4 = 10;
    位图bitmapsimplesize4 = Bitmap.createScaledBitmap(thumbnail4,thumbnail4.getWidth()/尺寸4,thumbnail4.getHeight()/尺寸4,真正的);    imageview1.setImageBitmap(thumbnail1);
    imageview2.setImageBitmap(thumbnail2);
    imageview3.setImageBitmap(bitmapsimplesize3);
    imageview4.setImageBitmap(bitmapsimplesize4);    location.setText(LOCATIONNAME);
    category.setText(类别名);
    subcategory.setText(subcategoryname);
    subcategory.setVisibility(View.VISIBLE);


解决方案

尝试缩小位图,而不是COM $ P $的pssing它。 Android官方网站有这样一个非常详细的指导:

Here is my code please check and resolve my problem .In this i m getting image through image path i.e. i'm taking that in selectimage1, selectimage2...goes on and after that i have taken the image in Bitmap and then decode and reduce its size den also getting out of memory error .

so please help me to get out of it.

thanks

    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);
解决方案

Try scaling down the Bitmap instead of compressing it. The official Android website has a very detailed guide for this: http://developer.android.com/training/displaying-bitmaps/

这篇关于内存不足的错误即使COM pressing图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 18:49