我正在编写一个具有简单摄像头功能的应用程序。我在主要活动中拍照,然后启动一个新线程以旋转图像,添加透明水印并将其另存为.PNG。
这个程序在运行自定义rom的三星银河S3上运行良好:AOKP,Android 4.4.2。下面给出的代码执行总时间约为2秒。根据任务管理器,我的应用程序使用了大约9 Mb的内存。
当我在运行有库存(有根)的Android 4.4.2的银河S4上运行该应用程序时,执行时间超过了27秒。该应用程序根据任务管理器使用大约124 Mb的内存(太多)。有时,应用程序崩溃并抛出OutOfMemory错误,这在S3上不会发生。
这是负责将图像保存到我的SaveThread中的代码:
TimingLogger tl = new TimingLogger("MyTag", "Saving");
String name = new SimpleDateFormat("dd-MM-yyyy_HH-mm-ss")
.format(new Date());
File myNewFolder = new File(path);
myNewFolder.mkdir();
File file = new File(path, name + ".JPEG");
OutputStream imageFileOS;
// Get EXIF rotation from byte array
int rotation = getOrientation(data);
tl.addSplit("Rotation calculated");
// Convert byte array to bitmap, and watermark bitmap
Bitmap pictureObject = BitmapFactory.decodeByteArray(data, 0,
data.length);
tl.addSplit("Decoded ByteArray to Bitmap");
// Rotate bitmap image according to EXIF data
pictureObject = rotateBitmap(rotation, …Run Code Online (Sandbox Code Playgroud)