彻底解决Android因加载多个大图引起的OutOfMemoryError,内存溢出的问题

通过CN3口直接控制台达伺服电机A2-M(二) 既然可以通过RS485与伺服驱动器进行通讯,那么就肯定可以控制转速 首先,需要了解下 ‘控制模式及控制命令输入源设定’ 依据以上资料,速度控制模式有两种,S和SZ模式,分别对应模式选择中的02和04,对P1-01的地址0102进行写地址操作即可实现,一开始我使用了S模式,但是这个模式在寸动模式下会自动运转,不符合我控制的要求,后面改用SZ模式,就可以实现零速度。 使用串口工具发送命令:“01 06 01 02 00 04 28 35”即可以实现设置,设置完成后可以手动在伺服驱动器的按键面板上进行确 阅读详情

最近因为项目里需求是选择或者拍摄多张照片后,提供滑动预览和上传,很多照片是好几MB一张,因为目前的Android系统对运行的程序都有一定的内存限制,一般是16MB或24MB(视平台而定),不做处理直接加载的话必然会报OOM (Out Of Memmory)。网上有很多解决android加载bitmap内存溢出的方法,我总结了一个通用的方法,下面是我从的开发案例抽取出来的代码:


我在项目中建了个Util.java工具类,里面写了个方法,根据图片的路径返回一个字节流数组对象:


[java]  view plain copy
  1. public static byte[] decodeBitmap(String path) {  
  2.         BitmapFactory.Options opts = new BitmapFactory.Options();  
  3.         opts.inJustDecodeBounds = true;// 设置成了true,不占用内存,只获取bitmap宽高  
  4.         BitmapFactory.decodeFile(path, opts);  
  5.         opts.inSampleSize = computeSampleSize(opts, -1, 1024 * 800);  
  6.         opts.inJustDecodeBounds = false;// 这里一定要将其设置回false,因为之前我们将其设置成了true  
  7.         opts.inPurgeable = true;  
  8.         opts.inInputShareable = true;  
  9.         opts.inDither = false;  
  10.         opts.inPurgeable = true;  
  11.         opts.inTempStorage = new byte[16 * 1024];  
  12.         FileInputStream is = null;  
  13.         Bitmap bmp = null;  
  14.         ByteArrayOutputStream baos = null;  
  15.         try {  
  16.             is = new FileInputStream(path);  
  17.             bmp = BitmapFactory.decodeFileDescriptor(is.getFD(), null, opts);  
  18.             double scale = getScaling(opts.outWidth * opts.outHeight,  
  19.                     1024 * 600);  
  20.             Bitmap bmp2 = Bitmap.createScaledBitmap(bmp,  
  21.                     (int) (opts.outWidth * scale),  
  22.                     (int) (opts.outHeight * scale), true);  
  23.             bmp.recycle();  
  24.             baos = new ByteArrayOutputStream();  
  25.             bmp2.compress(Bitmap.CompressFormat.JPEG, 100, baos);  
  26.             bmp2.recycle();  
  27.             return baos.toByteArray();  
  28.         } catch (FileNotFoundException e) {  
  29.             e.printStackTrace();  
  30.         } catch (IOException e) {  
  31.             e.printStackTrace();  
  32.         } finally {  
  33.             try {  
  34.                 is.close();  
  35.                 baos.close();  
  36.             } catch (IOException e) {  
  37.                 e.printStackTrace();  
  38.             }  
  39.             System.gc();  
  40.         }  
  41.         return baos.toByteArray();  
  42.     }  
  43.   
  44.     private static double getScaling(int src, int des) {  
  45.         /** 
  46.          * 48 目标尺寸÷原尺寸 sqrt开方,得出宽高百分比 49 
  47.          */  
  48.         double scale = Math.sqrt((double) des / (double) src);  
  49.         return scale;  
  50.     }  
  51.   
  52.     public static int computeSampleSize(BitmapFactory.Options options,  
  53.             int minSideLength, int maxNumOfPixels) {  
  54.         int initialSize = computeInitialSampleSize(options, minSideLength,  
  55.                 maxNumOfPixels);  
  56.   
  57.         int roundedSize;  
  58.         if (initialSize <= 8) {  
  59.             roundedSize = 1;  
  60.             while (roundedSize < initialSize) {  
  61.                 roundedSize <<= 1;  
  62.             }  
  63.         } else {  
  64.             roundedSize = (initialSize + 7) / 8 * 8;  
  65.         }  
  66.   
  67.         return roundedSize;  
  68.     }  
  69.   
  70.     private static int computeInitialSampleSize(BitmapFactory.Options options,  
  71.             int minSideLength, int maxNumOfPixels) {  
  72.         double w = options.outWidth;  
  73.         double h = options.outHeight;  
  74.   
  75.         int lowerBound = (maxNumOfPixels == -1) ? 1 : (int) Math.ceil(Math  
  76.                 .sqrt(w * h / maxNumOfPixels));  
  77.         int upperBound = (minSideLength == -1) ? 128 : (int) Math.min(  
  78.                 Math.floor(w / minSideLength), Math.floor(h / minSideLength));  
  79.   
  80.         if (upperBound < lowerBound) {  
  81.             return lowerBound;  
  82.         }  
  83.   
  84.         if ((maxNumOfPixels == -1) && (minSideLength == -1)) {  
  85.             return 1;  
  86.         } else if (minSideLength == -1) {  
  87.             return lowerBound;  
  88.         } else {  
  89.             return upperBound;  
  90.         }  
  91.     }  


然后在我需要加载图片BitMap的地方来调用Util.decodeBitmap():

[java]  view plain copy
  1. Bitmap bitmap = BitmapFactory.decodeByteArray(Util.decodeBitmap(imagePath), 0, Util.decodeBitmap(imagePath).length);  
  2.                 imageCache.put(imagePath, new SoftReference<Bitmap>(bitmap));  



上面这两行是我的AsyncImageLoaderByPath类中的代码,用来加载SD卡里面的图片,该类完整代码是:

[java]  view plain copy
  1. package com.pioneer.travel.util;  
  2.   
  3. import java.io.IOException;  
  4. import java.io.InputStream;  
  5. import java.lang.ref.SoftReference;  
  6. import java.net.MalformedURLException;  
  7. import java.net.URL;  
  8. import java.util.HashMap;  
  9.   
  10. import android.content.Context;  
  11. import android.graphics.Bitmap;  
  12. import android.graphics.BitmapFactory;  
  13. import android.graphics.BitmapFactory.Options;  
  14. import android.graphics.drawable.Drawable;  
  15. import android.os.Handler;  
  16. import android.os.Message;  
  17. import android.provider.MediaStore;  
  18. import android.util.Log;  
  19. import android.widget.ImageView;  
  20.   
  21. public class AsyncImageLoaderByPath {  
  22.     //SoftReference是软引用,是为了更好的为了系统回收变量  
  23.     private HashMap<String, SoftReference<Bitmap>> imageCache;  
  24.     private Context context;  
  25.       
  26.     public AsyncImageLoaderByPath(Context context) {  
  27.         this.imageCache = new HashMap<String, SoftReference<Bitmap>>();  
  28.         this.context = context;  
  29.     }  
  30.     public Bitmap loadBitmapByPath(final String imagePath, final ImageView imageView, final ImageCallback imageCallback){  
  31.         if (imageCache.containsKey(imagePath)) {  
  32.             //从缓存中获取  
  33.             SoftReference<Bitmap> softReference = imageCache.get(imagePath);  
  34.             Bitmap bitmap = softReference.get();  
  35.             if (bitmap != null) {  
  36.                 return bitmap;  
  37.             }  
  38.         }  
  39.         final Handler handler = new Handler() {  
  40.             public void handleMessage(Message message) {  
  41.                 imageCallback.imageLoaded((Bitmap) message.obj, imageView, imagePath);  
  42.             }  
  43.         };  
  44.         //建立新一个获取SD卡的图片  
  45.         new Thread() {  
  46.             @Override  
  47.             public void run() {  
  48.                 Bitmap bitmap = BitmapFactory.decodeByteArray(Util.decodeBitmap(imagePath), 0, Util.decodeBitmap(imagePath).length);  
  49.                 imageCache.put(imagePath, new SoftReference<Bitmap>(bitmap));  
  50.                 Message message = handler.obtainMessage(0, bitmap);  
  51.                 handler.sendMessage(message);  
  52.             }  
  53.         }.start();  
  54.         return null;  
  55.     }  
  56.     //回调接口  
  57.     public interface ImageCallback {  
  58.         public void imageLoaded(Bitmap imageBitmap,ImageView imageView, String imagePath);  
  59.     }  
  60. }  


通过这个实例,我验证了一下,一次性获取20张5MB的照片,都可以加载的很流畅,完全没有再出现报OOM的错误了

以下是运行效果

SD卡中的图片:



进入应用,选择11张照片进行滑动预览:






希望以上所写对大家有帮助,谢谢!


转载自:http://blog.youkuaiyun.com/wulianghuan/article/details/11548373

基于单片机的宠物狗智能项圈设计 GPS定位功能:利用GPS模块实时获取宠物的位置,帮助主人追踪宠物的活动轨迹。活动监测:使用加速度传感器监测宠物的活动情况,如运动、休息等,并进行分析。健康监测:集成心率传感器,实时监控宠物的心率,以确保其健康。声音识别功能:通过麦克风捕捉宠物的叫声,检测宠物的状态(如饥饿、疼痛等)。蓝牙/Wi-Fi通信:通过蓝牙或Wi-Fi模块与手机APP或云端平台进行数据交互,实时反馈宠物的状态信息。电池管理:实现低功耗设计,确保设备的续航能力。 阅读详情

相关推荐

GIS常用坐标系简介

EPSG:4326是基于WGS 84的地理坐标系,使用经纬度表示,适用于全局定位和地理数据表示。它的缺点是在进行距离、面积计算等地理分析时不够准确。EPSG:3857是投影坐标系,使用平面米坐标表示,适用于在线地图展示,特别适合 Web 地图应用。虽然它在地图展示中很高效,但由于投影引起的变形问题,它不适合高精度地理测量和计算。

weixin_59096287的博客 1978

Android中解决加载过多图片出现的OutOfMemoryOutOfMemory问题 .

首先呢,解决办法有好几种,降低图片的分辨率也不失一种办法,当然这里肯定不是这么用,也有直接更改虚拟机的内存的办法, 1. private final static floatTARGET_HEAP_UTILIZATION = 0.75f; 2. 在程序onCreate时就可以调用 3. VMRuntime.getRuntime().setTargetHeapUtilization(TAR

kdsde的专栏 1164

本地化部署dify,使用Database插件实现dify直连数据库报错No module named ‘MySQLdb‘解决方案

网上查阅各种资料,有说修改/dify-main/docker/volumes/sandbox/dependencies目录下的python-requirements.txt文件,添加了如下两行,试验后无效。,看到有人是其他报错,但是URI配置如下(在mysql后面加了pymysql),尝试后果真成功了。按照系统提示设置完数据库URI后保存出现错误。在工具市场查询Database,点击后进行授权。最后在该插件的项目地址获得灵感。

qiaoxu1989的博客 4334

android中ImageView的内存问题

大家都知道Bitmap的内存问题往往是一个安卓应用的最大OOM问题。好多同学也知道可以通过bitmap.recycle();方法回收图片的内存。可是往往会在回收后出现try to use recyled bitmap的BUG。这个是因为我们回收了的Bitmap还有其他地方在使用的原因.这里给出一个解决方案。(没有通过大量的测试,不过稍微测试了一下并没有出现这个BUG,同时我也了解这个BUG出现的原

1140

计算机模拟爆破过程,基于LSDYNA岩石爆破模拟建模分析

原标题:基于LSDYNA岩石爆破模拟建模分析 Ls Dyna岩石爆破模拟仿真作者:dyna_focus擅长领域:dyna/abaqus/hypermesh一、 数值模型的建立1.1 单元及算法的选择岩石,炸药,空气都采用solid164实体单元。岩石采用常应力实体单元,该种单元属于纯粹的lagrange算法,该种算法单元网格附着在材料上,随着材料的流动而产生单元网格的变形,但是在结构变形巨大时,有...

weixin_29494379的博客 7317

vivado安装空间与依赖要求:入门须知要点

准备安装Vivado时,需重点关注系统空间和依赖环境的配置。结合vivado安装教程,详细说明最低磁盘要求、内存配置及操作系统兼容性,帮助新手快速搭建开发环境,避免常见安装失败问题。

weixin_34725745的博客 1580

android 加载大图处理,Android开发中如何解决加载大图片时内存溢出的问题

尽量不要使用setImageBitmap或setImageResource或BitmapFactory.decodeResource来设置一张大图,因为这些函数在完成decode后,最终都是通过java层的createBitmap来完成的,需要消耗更多内存。因此,改用先通过BitmapFactory.decodeStream方法,创建出一个bitmap,再将其设为ImageView的 sourc...

weixin_42512798的博客 335

ADSP-21565的SigmaStudio图形化编程实战:从FW工程改造到音频通道打通

本文详细介绍了如何将ADSP-21569的SigmaStudio图形化编程固件工程改造,以适配ADSP-21565的纯片内SRAM内存架构。通过修改内存映射和链接文件,打通了音频输出通道,并成功利用SigmaStudio进行图形化编程,实现了从白噪声生成到音频输出的完整验证流程。

weixin_29169505的博客 381

android加载大图崩溃,当滚动RecyclerView时,Android Picasso图像加载应用程序崩溃

我正在使用改装访问此Web服务链接:在recyclerview中加载项目而不加载图像时,应用程序工作正常。但是,如果我添加毕加索代码来加载图像,应用程序在滚动2或3次后就会崩溃。我得到以下错误:A/Looper: Could not make wake event fd: Too many open files或者这些错误加在一起:E/Parcel: fcntl(F_DUPFD_CLOEXEC) ...

weixin_36207483的博客 625

汽车LED驱动芯片TPS92682-Q1 SPI接口配置与调试实战指南

SPI(串行外设接口)作为一种高速、全双工的同步串行通信总线,广泛应用于微控制器与外围设备之间的数据交换。其工作原理基于主从架构,通过时钟、数据线和片选信号实现设备间的精准时序控制。在汽车电子和工业控制领域,SPI因其简单高效、易于扩展的特性,成为配置复杂电源管理芯片、传感器和存储器的关键技术。通过SPI接口,工程师能够动态调整设备参数、实时读取状态信息,并实现复杂的故障诊断与保护策略,极大地提升了系统的灵活性与可靠性。本文以汽车级双通道LED恒流驱动器TPS92682-Q1为例,深入解析如何通过SPI接口

weixin_29185493的博客 289

PostgreSQL核心原理:数据库崩溃恢复的唯一真相详解

PostgreSQL崩溃恢复机制通过WAL日志确保数据一致性和持久性。核心流程包括:触发恢复(非正常关闭时)、读取控制文件获取检查点LSN、顺序扫描WAL日志进行Redo阶段重做已提交事务、利用MVCC标记未提交事务为ABORTED实现逻辑撤销,最后执行检查点完成恢复。该机制依赖WAL原子性、检查点锚点和无Undo的可见性模型三大支柱,保证即使系统崩溃也能恢复到逻辑一致状态。关键设计包括延迟写入、LSN顺序控制和FPW防部分写,最终通过确定性重放实现ACID特性。

数据知道的博客 2666

彻底解决Android因加载多个大图引起的OutOfMemoryError,内存溢出的有关问题

www.MyException.Cn   发布于:2013-10-08 16:46:23   浏览:62次 0 彻底解决Android因加载多个大图引起的OutOfMemoryError,内存溢出的问题 最近因为项目里需求是选择或者拍摄多张照片后,提供滑动预览和上传,很多照片是好几MB一张,因为目前的Android系统对运行的程序都有一定的内存限制,一般是16

ccchp的专栏 935

GaussDB本地安装手册(主备模式)

如果实例状态是Normal,则安装成功。三节点集中式配置文件。

Sebastien23的博客 2638

Android out of memory 彻底解决Android因加载多个大图引起的OutOfMemoryError,内存溢出的问题

最近因为项目里需求是选择或者拍摄多张照片后,提供滑动预览和上传,很多照片是好几MB一张,因为目前的Android系统对运行的程序都有一定的内存限制,一般是16MB或24MB(视平台而定),不做处理直接加载的话必然会报OOM (Out Of Memmory)。网上有很多解决android加载bitmap内存溢出的方法,我总结了一个通用的方法,下面是我从的开发案例抽取出来的代码: 我在项目中

WILLIAM-HUAN 个人技术博客 4万+

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

android decodebytearray 内存溢出,彻底解决Android因加载多个大图引起的OutOfMemoryError,内存溢出的问题...

publicstaticbyte[]decodeBitmap(Stringpath){BitmapFactory.Optionsopts=newBitmapFactory.Options();opts.inJustDecodeBounds=true;//设置成了true,不占用内存,只获取bitmap宽高BitmapFactory.decodeFile(path,opts...

weixin_42358733的博客 721

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

Android out of memory 彻底解决Android因加载多个大图引起的OutOfMemoryError,内存溢出的问题 .

最近因为项目里需求是选择或者拍摄多张照片后,提供滑动预览和上传,很多照片是好几MB一张,因为目前的Android系统对运行的程序都有一定的内存限制,一般是16MB或24MB(视平台而定),不做处理直接加载的话必然会报OOM (Out Of Memmory)。网上有很多解决android加载bitmap内存溢出的方法,我总结了一个通用的方法,下面是我从的开发案例抽取出来的代码: 我在项目中

qq_30427341的博客 579

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

(转)彻底解决Android因加载多个大图引起的OutOfMemoryError,内存溢出的问题

2019独角兽企业重金招聘Python工程师标准>>> ...

weixin_33860147的博客 112

Android有效解决加载大图片时内存溢出的问题

一   不应该做的事尽量不要使用setImageBitmap或setImageResource或BitmapFactory.decodeResource来设置一张大图,因为这些函数在完成decode后,最终都是通过java层的createBitmap来完成的,需要消耗更多内存。二   只要求得到宽和高BitmapFactory.Options这个类,有一个字段叫做 inJustDecodeBoun

fishmai的专栏 5651

android 加载大图片防止内存溢出

尽量不要使用setImageBitmap或setImageResource或BitmapFactory.decodeResource来设置一张大图,  因为这些函数在完成decode后,最终都是通过java层的createBitmap来完成的,需要消耗更多内存。  因此,

zjl5211314的专栏 7416
上一篇: 主动通知Android系统图库进行更新
下一篇: Eclipse与Android源码中ProGuard工具的使用--代码混淆
King·Forward
博客等级 码龄14年 117粉丝 218原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值