与大位图处理(平铺一个小位图创建壁纸) [英] Dealing with Large Bitmaps (tiling a small bitmap to create wallpaper)
问题描述
我有记忆问题,并认为这可能都与创建大位图。
I'm having memory problems and think it might have to do with creating large bitmaps.
眼下的任务是让一个相当小的平铺图像,并创建一个更大的平铺图像并将其设置为手机壁纸。我这样做的方法是:
The task at hand is to get a fairly small tile image and create a larger tiled image and set this as the phone wallpaper. The way I'm doing this is:
1)创建一个视图是2 *屏幕宽度,1 *屏幕高度
1) Create a view that is 2 * screen width, 1 * screen height
2)设置视图背景到BitmapDrawable与平铺模式设置为重复
2) Set the view background to a BitmapDrawable with the tile mode set to repeat
3)其观点尺寸创建位图
3) Create a bitmap with the views dimensions
4)绘制以位图方式:view.draw(新的Canvas(位图))
4) draw the view to the bitmap by: view.draw(new Canvas(bitmap))
5)设置wallpper:getApplicationContext()setWallpaper(位图)
5) set wallpper: getApplicationContext().setWallpaper(bitmap)
这工作正常我的手机(宏达魔术)和我已经尝试过其他手机。但我得到有关这个问题的错误报告。我试图通过加倍需要的尺寸来重现问题,问题似乎是发生在第4步时,认为被绘制到位图:
This works fine on my phone (HTC Magic) and other phones that I have tried. But I am getting bug reports relating to this issue. I tried to recreate the problem by doubling the required dimensions and the problem seems to be happening in the 4th step when the view is being drawn to the bitmap:
ERROR / dalvikvm堆(124):堆按摩需要(7372800字节的外部分配过大)
ERROR/dalvikvm-heap(124): Heap Massage needed (7372800-byte external allocation too big)
我不知道如何去解决这一点。请帮忙! 谢谢
I'm not sure how to go about solving this. Please help! Thanks
推荐答案
不完全相信,如果这是你的解决方案,但你看? <一href="http://developer.android.com/reference/android/graphics/BitmapFactory.Options.html#inTempStorage"相对=nofollow> BitmapFactory.Options.inTempStorage
Not exactly sure if this is your solution, but have you looked at ? BitmapFactory.Options.inTempStorage
您使用它的方式是:
BitmapFactory.Options options = new BitmapFactory.Options();
options.inTempStorage = new byte[16*1024];
Bitmap bitmap_origin = BitmapFactory.decodeFile(path, options);
这篇关于与大位图处理(平铺一个小位图创建壁纸)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!