{"id":372,"date":"2013-05-28T17:33:22","date_gmt":"2013-05-28T08:33:22","guid":{"rendered":"https:\/\/www.united-bears.co.jp\/blog\/?p=372"},"modified":"2013-05-28T17:50:19","modified_gmt":"2013-05-28T08:50:19","slug":"imageview-%e3%81%ab%e3%82%bb%e3%83%83%e3%83%88%e3%81%97%e3%81%9f-bitmap-%e3%81%af%e3%81%a9%e3%81%86%e3%81%aa%e3%82%8b%e3%81%ae%e3%81%8b2","status":"publish","type":"post","link":"https:\/\/www.united-bears.co.jp\/blog\/archives\/372","title":{"rendered":"ImageView \u306b\u30bb\u30c3\u30c8\u3057\u305f Bitmap \u306f\u3069\u3046\u306a\u308b\u306e\u304b(2)"},"content":{"rendered":"<p><a href=\"https:\/\/www.united-bears.co.jp\/blog\/archives\/357\" target=\"_blank\">\u524d\u56de<\/a>\u306f\u3001ImageView \u306e\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3092\u8efd\u304f\u89e3\u6790\u3057\u3066\u7d42\u308f\u3063\u305f\u3002\u4eca\u56de\u306f\u5b9f\u969b\u306b\u3001\u30a8\u30df\u30e5\u30ec\u30fc\u30bf\u30fc\u3092\u5229\u7528\u3057\u3066 ImageView \u306b Bitmap \u3092\u30bb\u30c3\u30c8\u3057\u3066\u307f\u308b\u3002\u5229\u7528\u3057\u305f\u306e\u306f\u3001Android 2.3(API 8)\u3060\u3002<br \/>\n\u4eca\u56de\u306f\u3001\u6700\u521d\u306b Activity \u304c\u7d42\u4e86\u3059\u308b\u969b\u306b ImageView \u306b\u8cbc\u308a\u4ed8\u3051\u305f Bitmap \u306b recycle() \u30e1\u30bd\u30c3\u30c9\u547c\u3073\u51fa\u3057\u3092\u884c\u308f\u306a\u3044\u3068\u3069\u3046\u306a\u308b\u306e\u304b\u8abf\u3079\u3066\u307f\u305f\u3002DialogFragment \u306b ImageView \u3092\u7528\u610f\u3057\u3066\u3001\u5927\u304d\u306a\u753b\u50cf\u3092\u8aad\u307f\u8fbc\u3093\u3067\u8868\u793a\u30fb\u975e\u8868\u793a\u3092\u7e70\u308a\u8fd4\u3057\u305f\u304c\u3001OutOfMemoryError \u306f\u767a\u751f\u3057\u306a\u304b\u3063\u305f\u3002\u7279\u306b\u624b\u5f53\u3066\u3059\u308b\u5fc5\u8981\u306a\u3055\u305d\u3046\u306a\u30fb\u30fb\u30fb<\/p>\n<p>\u6b21\u306b\u3001ImageView \u306b\u753b\u50cf\u3092\u4f55\u56de\u3082\u8cbc\u308a\u4ed8\u3051\u3066\u307f\u308b\u3053\u3068\u306b\u3057\u305f\u3002ImageView \u306e\u4e2d\u306e\u753b\u50cf\u3060\u3051\u5909\u66f4\u3059\u308b\u3068\u3044\u3046\u306e\u306f\u3001\u5b9f\u969b\u306b\u3042\u308a\u305d\u3046\u306a\u30b3\u30fc\u30c9\u3060\u3002\u30c6\u30b9\u30c8\u306a\u306e\u3067\u3001\u5358\u7d14\u306b\u30eb\u30fc\u30d7\u3067\u56de\u3059\u3053\u3068\u306b\u3057\u305f\u3002<\/p>\n<pre>\r\nfor (int i = 0; i < 1000; i++) {\r\n    Drawable d = detailPicture.getDrawable();\r\n    Bitmap b = null;\r\n    if (null != d) {\r\n        BitmapDrawable bd = (BitmapDrawable) d;\r\n        b = bd.getBitmap();\r\n    }\r\n\r\n    Bitmap bitmap = ...\/* \u30d5\u30a1\u30a4\u30eb\u304b\u3089\u8aad\u307f\u8fbc\u3080 *\/\r\n    imageView.setImageBitmap(bitmap);\r\n}\r\n<\/pre>\n<p>\u3053\u306e\u30b3\u30fc\u30c9\u3092\u5b9f\u884c\u3057\u3066\u3082\u3001OutOfMemoryError \u306f\u767a\u751f\u3057\u306a\u3044\u3002\u3044\u3064\u3082\u306f\u3088\u304f\u4f1a\u3046\u304a\u53cb\u9054\u306a\u306e\u3060\u304c\u30fb\u30fb\u30fbBitmapDrawable \u304b\u3089\u53d6\u5f97\u3057\u305f b \u3068\u3044\u3046 Bitmap \u3067 isRecycled() \u3092\u547c\u3073\u51fa\u3059\u3068\u3001imageView \u306b setImageBitmap \u3059\u308b\u524d\u3082\u5f8c\u3082 false \u3060\u3063\u305f\u3002\u307e\u305f\u3001\u983b\u7e41\u306b GC \u304c\u767a\u751f\u3059\u308b\u3002\u5927\u304d\u306a\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u3080\u30011\uff5e2\u56de\u306b\u4e00\u5ea6 GC \u304c\u3001\u5c0f\u3055\u306a\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u3080\u3068 5\uff5e6\u56de\u306b\u4e00\u5ea6 GC \u304c\u767a\u751f\u3057\u305f\u3002<\/p>\n<p>\u6700\u521d\u306b\u623b\u3063\u3066\u3001<a href=\"http:\/\/developer.android.com\/reference\/android\/graphics\/Bitmap.html#recycle()\" target=\"blank\">Bitmap.recycled() \u30e1\u30bd\u30c3\u30c9\u306e\u8aac\u660e<\/a>\u3092\u8aad\u3080\u3068\u3001\u6700\u5f8c\u306e\u65b9\u306b\u5c0f\u3055\u304f(\u3044\u3084\u3001\u5c0f\u3055\u3044\u3068\u3044\u3046\u306e\u306f\u5618\u3067\u3059\u304c)\u3001<\/p>\n<blockquote><p>\nThis is an advanced call, and normally need not be called, since the normal GC process will free up this memory when there are no more references to this bitmap.\n<\/p><\/blockquote>\n<p>Bitmap \u3078\u306e\u53c2\u7167\u304c\u306a\u304f\u306a\u308c\u3070\u3001\u81ea\u7136\u306b\u30e1\u30e2\u30ea\u30fc\u306f\u89e3\u653e\u3055\u308c\u307e\u3059\u3088\u3068\u3044\u3046\u3053\u3068\u306e\u3088\u3046\u3060\u3002\u4eca\u56de\u306e\u73fe\u8c61\u3068\u4e00\u81f4\u3057\u3066\u3044\u308b\u306e\u3067\u3001\u53c2\u7167\u304c\u5916\u3055\u308c\u305f\u30bf\u30a4\u30df\u30f3\u30b0\u3092\u8abf\u3079\u3066\u307f\u305f\u3002<\/p>\n<p>ImageView \u306f\u3001setImageBitmap \u3059\u308b\u3068\u3001BitmapDrawable \u3092\u751f\u6210\u3057\u3066\u30bb\u30c3\u30c8\u3057\u3066\u3044\u308b\u3002\u4ee5\u524d\u306b Drawable \u304c\u30bb\u30c3\u30c8\u3055\u308c\u3066\u3044\u305f\u3068\u304d\u306b\u3001\u4f55\u3092\u884c\u3046\u306e\u304b\u8abf\u3079\u3066\u307f\u305f\u3002\u4ee5\u4e0b\u306e\u9806\u306b\u30e1\u30bd\u30c3\u30c9\u304c\u547c\u3070\u308c\u3066\u3044\u304f(\u5fc5\u8981\u3068\u601d\u308f\u308c\u308b\u7b87\u6240\u306e\u307f)\u3002<\/p>\n<p>ImageView.setImageBitmap(Bitmap)<br \/>\nImageView.setImageDrawable(Drawable)<br \/>\nImageView.updateDrawable(Drawable)<br \/>\nView.unscheduleDrawable(Drawable)<br \/>\nChoreographer.removeCallbacks(int, Runnable, Object)<\/p>\n<p>removeCallbacks() \u30e1\u30bd\u30c3\u30c9\u5185\u3067\u3001\u4ee5\u524d\u306b\u30bb\u30c3\u30c8\u3055\u308c\u305f Drawable \u306f null \u306b\u306a\u308a\u3001\u53c2\u7167\u304c\u5916\u308c\u305f\u72b6\u614b\u306b\u306a\u3063\u3066\u3044\u308b\u306e\u3060\u308d\u3046\u3002<\/p>\n<p>\u3058\u3083\u3041\u3001\u3044\u3064 recycle() \u3059\u308b\u306e\uff1f\u3068\u3044\u3046\u306e\u306f\u6b21\u56de\u307e\u3067\u306b\u8abf\u3079\u3066\u304a\u3053\u3046\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u56de\u306f\u3001ImageView \u306e\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3092\u8efd\u304f\u89e3\u6790\u3057\u3066\u7d42\u308f\u3063\u305f\u3002\u4eca\u56de\u306f\u5b9f\u969b\u306b\u3001\u30a8\u30df\u30e5\u30ec\u30fc\u30bf\u30fc\u3092\u5229\u7528\u3057\u3066 ImageView \u306b Bitmap \u3092\u30bb\u30c3\u30c8\u3057\u3066\u307f\u308b\u3002\u5229\u7528\u3057\u305f\u306e\u306f\u3001Android 2.3(API 8)\u3060\u3002 \u4eca [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,3],"tags":[],"class_list":["post-372","post","type-post","status-publish","format-standard","hentry","category-android","category-android-develop"],"_links":{"self":[{"href":"https:\/\/www.united-bears.co.jp\/blog\/wp-json\/wp\/v2\/posts\/372","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.united-bears.co.jp\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.united-bears.co.jp\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.united-bears.co.jp\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.united-bears.co.jp\/blog\/wp-json\/wp\/v2\/comments?post=372"}],"version-history":[{"count":8,"href":"https:\/\/www.united-bears.co.jp\/blog\/wp-json\/wp\/v2\/posts\/372\/revisions"}],"predecessor-version":[{"id":380,"href":"https:\/\/www.united-bears.co.jp\/blog\/wp-json\/wp\/v2\/posts\/372\/revisions\/380"}],"wp:attachment":[{"href":"https:\/\/www.united-bears.co.jp\/blog\/wp-json\/wp\/v2\/media?parent=372"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.united-bears.co.jp\/blog\/wp-json\/wp\/v2\/categories?post=372"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.united-bears.co.jp\/blog\/wp-json\/wp\/v2\/tags?post=372"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}