我想将公司的商业徽标添加到Android中的jpeg文件[照片]。 我尝试了几次将照片转换为位图并添加然后添加徽标,结果是OutOfMemoryError。
修改 它现在有效,但需要花费很多时间和记忆...... 我的代码就是:
Bitmap logo = BitmapFactory.decodeResource(
mainActivity.getResources(), R.drawable.logo);
Bitmap photo =BitmapFactory.decodeByteArray(jpeg[0], 0, jpeg[0].length);
Bitmap combination = Bitmap.createBitmap(photo.getWidth(), photo.getHeight(), Bitmap.Config.RGB_565);
Canvas comboImage = new Canvas(combination);
comboImage.drawBitmap(photo, 0f, 0f, null);
comboImage.drawBitmap(logo, 0f, 200, null);
try {
FileOutputStream out = new FileOutputStream(mediaFile);
combination.compress(Bitmap.CompressFormat.PNG, 100, out);
out.close();
} catch (Exception e) {
e.printStackTrace();
}
Logcat的输出:
01-29 15:40:44.154: I/dalvikvm-heap(5065): Grow heap (frag case) to 109.067MB for 25560592-byte allocation
01-29 15:40:44.184: I/Choreographer(5065): Skipped 36 frames! The application may be doing too much work on its main thread.
你有什么建议?
非常感谢。卢卡斯
答案 0 :(得分:1)
如果有人遇到同样的问题,我建议您阅读五个课程 Displaying Bitmaps Efficiently - Android Developers
谢谢大家的帮助!