相关疑难解决方法(0)

图像出现内存错误

我在列表视图中显示图像并出现内存错误任何人都指导我这个问题的解决方案是我的代码

logcat的

ERROR/AndroidRuntime(1010): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
ERROR/AndroidRuntime(1010):     at android.graphics.BitmapFactory.nativeDecodeByteArray(Native Method)
ERROR/AndroidRuntime(1010):     at android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:405)
ERROR/AndroidRuntime(1010):     at android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:418)
ERROR/AndroidRuntime(1010):     at com.Adapters.AdapterTours.getView(AdapterTours.java:73)
ERROR/AndroidRuntime(1010):     at android.widget.AbsListView.obtainView(AbsListView.java:1409)
ERROR/AndroidRuntime(1010):     at android.widget.ListView.makeAndAddView(ListView.java:1745)
ERROR/AndroidRuntime(1010):     at android.widget.ListView.fillUp(ListView.java:700)
ERROR/AndroidRuntime(1010):     at android.widget.ListView.fillGap(ListView.java:646)
ERROR/AndroidRuntime(1010):     at android.widget.AbsListView.trackMotionScroll(AbsListView.java:3399)
ERROR/AndroidRuntime(1010):     at android.widget.AbsListView.onTouchEvent(AbsListView.java:2233)
ERROR/AndroidRuntime(1010):     at android.widget.ListView.onTouchEvent(ListView.java:3446)
ERROR/AndroidRuntime(1010):     at android.view.View.dispatchTouchEvent(View.java:3885)
ERROR/AndroidRuntime(1010):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:903)
ERROR/AndroidRuntime(1010):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
ERROR/AndroidRuntime(1010):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
ERROR/AndroidRuntime(1010):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
ERROR/AndroidRuntime(1010):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
ERROR/AndroidRuntime(1010):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1691)
ERROR/AndroidRuntime(1010):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1125)
ERROR/AndroidRuntime(1010):     at android.app.Activity.dispatchTouchEvent(Activity.java:2096)
ERROR/AndroidRuntime(1010):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1675)
ERROR/AndroidRuntime(1010):     at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2194)
ERROR/AndroidRuntime(1010):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1878)
ERROR/AndroidRuntime(1010): …
Run Code Online (Sandbox Code Playgroud)

android listview image-processing

10
推荐指数
2
解决办法
2万
查看次数

毕加索无法加载大图像(来自Camera和本地Uri)

我有一个问题,使用Picasso尝试从Gallery和Camera Intent 的本地Uri格式内容加载大图像://com.android.providers.media.documents/document/imageXXYYZZ.

我正在使用标准调用加载图像:

Picasso.load(image_url)
        .resize(600, 240)
        .centerCrop()
        .into(imageTarget);
Run Code Online (Sandbox Code Playgroud)

我附在这里Target,当我得到onBitmapFailed(Drawable errorDrawable)错误触发时.另外,当我登录毕加索时,我得到:

06-23 12:13:54.267  22393-22393/it.b3lab.friendipity D/Picasso? Main        created      [R100] Request{content://com.android.providers.media.documents/document/image%3A13345 resize(600,240) centerCrop}
06-23 12:13:54.277  22393-23010/it.b3lab.friendipity D/Picasso? Dispatcher  enqueued     [R100]+9ms
06-23 12:13:54.285  22393-23038/it.b3lab.friendipity D/Picasso? Hunter      executing    [R100]+15ms
06-23 12:13:54.813  22393-23010/it.b3lab.friendipity D/Picasso? Dispatcher  batched      [R100]+546ms for error
06-23 12:13:55.014  22393-23010/it.b3lab.friendipity D/Picasso? Dispatcher  delivered    [R100]+746ms
06-23 12:13:55.024  22393-22393/it.b3lab.friendipity I/picasso? failed to load bitmap
06-23 12:13:55.024  22393-22393/it.b3lab.friendipity D/Picasso? Main        errored      [R100]+756ms
Run Code Online (Sandbox Code Playgroud)

这只发生在我上面说的当我尝试从图库中加载大图像(大约1 MB以上)和使用高分辨率相机智能手机时的相机意图(在我的情况下,它是在Android 5.0.1上运行的Moto G) ).我没有在Android 4.4上使用Samsung …

camera android picasso

10
推荐指数
1
解决办法
5614
查看次数

尝试将带有图像的表单发送到PHP服务器时Android中的内存泄漏

我在这个文件中有内存泄漏,我找不到确切的位置,但我认为是周围的图像 - > (Bitmap bm = BitmapFactory.decodeFile(filename)),我尝试了很多不同的方法,但我无法让它工作.

package prod.vegs;

//All imports here but not need to write them all now :-)


public class ProductForm extends Activity {

private static int TAKE_PICTURE = 1;
private static int SELECT_PICTURE = 2;

//JSON Response node names
private static String KEY_SUCCESS = "success";
private static String ERROR_MSG = "error_msg";
private static String KEY_TYPES = "subtypes";
private static String TYPE_NAME = "name";
private static String TYPE_ID = "id_type";
private static String PRODUCT_ID = "id_product"; …
Run Code Online (Sandbox Code Playgroud)

android memory-leaks bitmap android-asynctask

8
推荐指数
1
解决办法
1385
查看次数

如何在Android中创建可调整大小的ImageView

我希望我的应用程序的用户能够在运行时修改图像.用户应该能够通过点击图像视图的角落并拖动它来修改图像的高度和宽度,如下图所示:

在此输入图像描述

我花了很多时间研究这个,我发现 了多点触控的感觉,并将一个大的位图文件调整为缩放输出文件,如Pinch Zoom,但这些都不符合我的要求.

目前我正在调整位图使用下面的结果和改变宽度的onprogress改变方法的搜索栏而不是帧.通过使用此功能,更改图像大小不能正常工作.

public static Bitmap decodeFile(File f,int WIDTH,int HIGHT){

    try {
        //Decode image size
        BitmapFactory.Options o = new BitmapFactory.Options();
        o.inJustDecodeBounds = true;
        BitmapFactory.decodeStream(new FileInputStream(f),null,o);

        //The new size we want to scale to
        final int REQUIRED_WIDTH=WIDTH;
        final int REQUIRED_HIGHT=HIGHT;

        //Find the correct scale value. It should be the power of 2.
        int scale=1;
        while(o.outWidth/scale/2>=REQUIRED_WIDTH && o.outHeight/scale/2>=REQUIRED_HIGHT)
            scale*=2;

        //Decode with inSampleSize
        BitmapFactory.Options o2 = new BitmapFactory.Options();
        o2.inSampleSize=scale;
        return BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
    }
        catch (FileNotFoundException e) …
Run Code Online (Sandbox Code Playgroud)

android bitmap image-resizing

8
推荐指数
1
解决办法
1458
查看次数

裁剪图像没有OutOfMemory - Android

我想裁剪图像而不会出现OutOfMemory异常.
这意味着我有裁剪图像的x,y,宽度和高度,并希望裁剪原始图像而不将其带入内存.
是的,我知道这BitmapRegionDecoder是个好主意,但也许裁剪的图像太大,无法将其带入记忆中.

实际上我不想要拼写位图,只想将裁剪后的图像从源文件写入目标文件.


编辑:我想保存裁剪的图像,而不仅仅是显示它ImageView 我希望将其保存在新文件中而不会丢失尺寸

这是一个例子
在此输入图像描述

在这种情况下,裁剪的图像分辨率为20000x20000,下面的代码不能用于OOM:

BitmapRegionDecoder bitmapRegionDecoder = BitmapRegionDecoder.newInstance(inputStream, false);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.RGB_565;
Bitmap bitmap = bitmapRegionDecoder.decodeRegion(new Rect(width / 2 - 100, height / 2 - 100, width / 2 + 100, height / 2 + 100), options);
mImageView.setImageBitmap(bitmap);
Run Code Online (Sandbox Code Playgroud)

使用inSampleSize减少原始图片大小是好的,但我保存的结果不再是20000x20000.

如何裁剪25000x25000并将20000x20000部分图像保存在文件中?

android image crop

8
推荐指数
1
解决办法
1585
查看次数

堆不在Genymotion模拟器上扩展

在调整大位图的大小以便更快地将图像上传到服务器时,我偶尔会遇到OutOfMemoryErrors.为了防止这种情况,我计算了所需的内存量,并在尝试缩放图像之前检查它是否超过Runtime.getRuntime().maxMemory().

但是,即使图像应该很容易放在堆上,我仍会遇到OOM错误.

仿真设备(Galaxy SII API 16)使用上述方法为我提供了67108864字节的最大内存.

在下面的代码片段中,堆大小为43975K,并且仅使用该内存的<15K.对于我的~31K分配,堆应该自动增长到大约45K,这仍然不接近64 MiB的最大大小.但正如您所看到的,dalvik vm不会扩展堆,而是耗尽内存.

10-13 20:35:57.223: D/dalvikvm(1201): GC_FOR_ALLOC freed 505K, 67% free 14692K/43975K, paused 31ms, total 31ms
10-13 20:35:57.223: I/dalvikvm-heap(1201): Forcing collection of SoftReferences for 31961100-byte allocation
10-13 20:35:57.251: D/dalvikvm(1201): GC_BEFORE_OOM freed 2K, 67% free 14689K/43975K, paused 29ms, total 29ms
10-13 20:35:57.251: E/dalvikvm-heap(1201): Out of memory on a 31961100-byte allocation.
Run Code Online (Sandbox Code Playgroud)

我想知道这是否会在真实设备上发生,或者这可能是一个genymotion错误.

堆保证扩展到maxMemory()吗?JavaDoc for Runtime.getRuntime().freeMemory()表示它"可能"扩展,无论这意味着什么.

我只需要一种可靠的方法来计算我可以使用的内存量,这就是我的方法,如果我错了请纠正我:

long maxMemory = Runtime.getRuntime().maxMemory();
long usedMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
long availableMemory = maxMemory - usedMemory;
Run Code Online (Sandbox Code Playgroud)

此调用导致OutOfMemoryError:

// outOptions has …
Run Code Online (Sandbox Code Playgroud)

android genymotion

6
推荐指数
1
解决办法
3498
查看次数

如何在热敏打印机(EPSON)中以完整纸张尺寸(80MM)打印图像

我跟着爱普生SDK for android到热敏打印收据......

因此,在Logoimage(商店)的部分,我给了一些包含整个图像的图像而不是文本.这就像下面的

在此输入图像描述

这里的商店是Logoimage Insted,我给了我的Recipt(图片)所以我变得像上面那样..它不是全尺寸打印......

这是我的代码

public class MainActivity extends Activity implements View.OnClickListener, ReceiveListener {

private Context mContext = null;
private EditText mEditTarget = null;
private Spinner mSpnSeries = null;
private Spinner mSpnLang = null;
private Printer  mPrinter = null;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mContext = this;

    int[] target = {
        R.id.btnDiscovery,
        R.id.btnSampleReceipt,
   };

    for (int i = 0; i < target.length; i++) {
        Button button = (Button)findViewById(target[i]);
        button.setOnClickListener(this);
    }

    mSpnSeries = (Spinner)findViewById(R.id.spnModel);
    ArrayAdapter<SpnModelsItem> …
Run Code Online (Sandbox Code Playgroud)

printing android bitmap thermal-printer

6
推荐指数
1
解决办法
3130
查看次数

从InputStream调整位图大小

我试图从InputStream调整一个图像的大小,所以我在将图像加载到Bitmap对象时使用Strange内存中的代码问题,但我不知道为什么这个代码总是返回没有图像的Drawable.

这个很好用:

private Drawable decodeFile(InputStream f){
    try {
        InputStream in2 = new BufferedInputStream(f);
        BitmapFactory.Options o2 = new BitmapFactory.Options();
        o2.inSampleSize=2;
        return new BitmapDrawable(BitmapFactory.decodeStream(in2, null, o2));
    } catch (Exception e) {
        return null;
    }
}
Run Code Online (Sandbox Code Playgroud)

这个不起作用:

private Drawable decodeFile(InputStream f){
    try {
        InputStream in1 = new BufferedInputStream(f);
        InputStream in2 = new BufferedInputStream(f);
        //Decode image size
        BitmapFactory.Options o = new BitmapFactory.Options();
        o.inJustDecodeBounds = true;
        BitmapFactory.decodeStream(in1,null,o);

        //The new size we want to scale to
        final int IMAGE_MAX_SIZE=90;

        //Find …
Run Code Online (Sandbox Code Playgroud)

android bitmap resize-image

5
推荐指数
1
解决办法
6967
查看次数

分配变量时Android内存不足

所以我明白了:

'01-01 20:37:34.859: E/dalvikvm-heap(19921): Out of memory on a 6471856-byte allocation.'
Run Code Online (Sandbox Code Playgroud)

尝试将一堆变量分配给内存时.我正在分配24个这样的变量:

mElements.add(new ShopElement(getResources(),R.drawable.shop_starter, b1X , b1Y,true,1,"red",true,5,checkLocked(0)));
Run Code Online (Sandbox Code Playgroud)

其中一个:

bNumbers = new Bitmap[] {Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.h0)
        , 65,65, true),
        Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.h1)
        , 65,65, true),
        Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.h2)
        , 65,65, true),
        Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.h3)
        , 65,65, true),
        Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.h4)
        ,65,65,true),
        Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.h5)
        , 65,65, true),
        Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.h6)
        , 65,65, true),
        Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.h7)
        , 65,65, true),
        Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.h8)
        , 65,65, true),
        Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.h9)
        , 65,65, true),
        Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.time)
                , 50,50, true)};
Run Code Online (Sandbox Code Playgroud)

但在我能够通过我创建的24个元素中的第16个之前,它会在某些手机上崩溃.

我有一个Galaxy S2,它运行良好,但在 …

memory android bitmap

5
推荐指数
1
解决办法
1170
查看次数

使面部检测器适用于任何文件格式

由于面部检测器仅适用于jpg文件,如何使其适用于所有格式?我让用户从SD卡中选择任何图像,因此图像可以是任何格式.比我在本文中提到的使用decodefile方法缩小图像: Android:将大型位图文件调整为缩放输出文件

我的问题是:
我们可以在decodefile方法中添加一些方法来首先将图像转换为jpg吗?
将图像转换为jpg的最佳和最有效的方法是什么,以便面部检测器类检测面部?

我的代码到目前为止:

public FaceView(Context context) {
            super(context);                         
            File photo = new File(selectedImagePath);                       
            sourceImage = decodeFile(photo);

            picWidth = sourceImage.getWidth();
            picHeight = sourceImage.getHeight(); 

            sourceImage = Bitmap.createScaledBitmap (sourceImage, picWidth, picHeight, false);                                      

            arrayFaces = new FaceDetector( picWidth, picHeight, NUM_FACES );
            arrayFaces.findFaces(sourceImage, getAllFaces);

            for (int i = 0; i < getAllFaces.length; i++)
            {
                getFace = getAllFaces[i];
                try {
                    PointF eyesMP = new PointF();
                    getFace.getMidPoint(eyesMP);
                    eyesDistance[i] = getFace.eyesDistance();
                    Log.d("1st eye distance", "" + getFace.eyesDistance());
                    eyesMidPts[i] = eyesMP;                 
                }
                catch (Exception e)
                { …
Run Code Online (Sandbox Code Playgroud)

java android bitmap

2
推荐指数
1
解决办法
321
查看次数