{"id":507,"date":"2016-11-23T14:13:18","date_gmt":"2016-11-23T05:13:18","guid":{"rendered":"http:\/\/blue-bear.jp\/kb\/?p=507"},"modified":"2016-11-23T14:13:18","modified_gmt":"2016-11-23T05:13:18","slug":"android-bitmap%e7%94%bb%e5%83%8f%e3%82%92%e7%b8%b1%e6%a9%ab%e6%af%94%e5%9b%ba%e5%ae%9a%e3%81%a7%e3%83%aa%e3%82%b5%e3%82%a4%e3%82%ba","status":"publish","type":"post","link":"https:\/\/blue-bear.jp\/kb\/android-bitmap%e7%94%bb%e5%83%8f%e3%82%92%e7%b8%b1%e6%a9%ab%e6%af%94%e5%9b%ba%e5%ae%9a%e3%81%a7%e3%83%aa%e3%82%b5%e3%82%a4%e3%82%ba\/","title":{"rendered":"[android] bitmap\u753b\u50cf\u3092\u7e31\u6a6b\u6bd4\u56fa\u5b9a\u3067\u30ea\u30b5\u30a4\u30ba"},"content":{"rendered":"<h2>bitmap\u753b\u50cf\u3092\u7e31\u6a6b\u6bd4\u56fa\u5b9a\u3067\u30ea\u30b5\u30a4\u30ba<\/h2>\n<p>bitmap\u753b\u50cf\u3092\u7e31\u6a6b\u6bd4\u56fa\u5b9a\u3067\u30ea\u30b5\u30a4\u30ba\u3059\u308b\u95a2\u6570\u3092\u4f5c\u6210\u3057\u3066\u307f\u305f\u3002<\/p>\n<h3>\u7e26\u6a2a\u9577\u3044\u65b9\u3092\u6307\u5b9a\u30b5\u30a4\u30ba\u306b\u5408\u308f\u305b\u308b\u95a2\u6570<\/h3>\n<pre>\r\nprivate static Bitmap resize(Bitmap image, int maxWidth, int maxHeight) {\r\n    if (maxHeight > 0 && maxWidth > 0) {\r\n        int width = image.getWidth();\r\n        int height = image.getHeight();\r\n        float ratioBitmap = (float) width \/ (float) height;\r\n        float ratioMax = (float) maxWidth \/ (float) maxHeight;\r\n\r\n        int finalWidth = maxWidth;\r\n        int finalHeight = maxHeight;\r\n        if (ratioMax > 1) {\r\n            finalWidth = (int) ((float)maxHeight * ratioBitmap);\r\n        } else {\r\n            finalHeight = (int) ((float)maxWidth \/ ratioBitmap);\r\n        }\r\n        image = Bitmap.createScaledBitmap(image, finalWidth, finalHeight, true);\r\n        return image;\r\n    } else {\r\n        return image;\r\n    }\r\n}\r\n<\/pre>\n<h3>\u7e26\u6a2a\u77ed\u3044\u65b9\u3092\u6307\u5b9a\u30b5\u30a4\u30ba\u306b\u5408\u308f\u305b\u308b\u95a2\u6570<\/h3>\n<pre>\r\nprivate static Bitmap resize(Bitmap image, int maxWidth, int maxHeight) {\r\n        if (maxHeight > 0 && maxWidth > 0) {\r\n            int width = image.getWidth();\r\n            int height = image.getHeight();\r\n            float ratioBitmap = (float) width \/ (float) height;\r\n\r\n            int finalWidth = maxWidth;\r\n            int finalHeight = maxHeight;\r\n            if (ratioBitmap > 1) {\r\n                finalWidth = (int) ((float)maxHeight * ratioBitmap);\r\n            } else {\r\n                finalHeight = (int) ((float)maxWidth \/ ratioBitmap);\r\n            }\r\n\r\n            \/\/\u30c8\u30ea\u30df\u30f3\u30b0\u3059\u308b\u5e45\u3001\u9ad8\u3055\u3001\u5ea7\u6a19\u306e\u8a2d\u5b9a\r\n            int startX = (finalWidth - maxWidth) \/2;\r\n            int startY = (finalHeight - maxHeight)\/2;\r\n\r\n            image = Bitmap.createScaledBitmap(image, finalWidth, finalHeight, true);\r\n\r\n            return mSourceBitmap;\r\n        } else {\r\n            return image;\r\n        }\r\n    }\r\n<\/pre>\n<h3>\u4f7f\u3044\u65b9<\/h3>\n<pre>\r\nBitmap original = BitmapFactory.decodeResource(getResources(),R.drawable.testImage);\r\nBitmap resizedBMP = resize(original, 100,100);\r\n<\/pre>\n<p>*drawable\u306btestImage\u3068\u3044\u3046\u753b\u50cf\u30d5\u30a1\u30a4\u30eb\u3092\u914d\u7f6e\u3057\u3066\u304a\u304f\u3053\u3068<\/p>\n","protected":false},"excerpt":{"rendered":"<p>bitmap\u753b\u50cf\u3092\u7e31\u6a6b\u6bd4\u56fa\u5b9a\u3067\u30ea\u30b5\u30a4\u30ba <\/p>\n","protected":false},"author":1,"featured_media":383,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts\/507"}],"collection":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/comments?post=507"}],"version-history":[{"count":1,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts\/507\/revisions"}],"predecessor-version":[{"id":508,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts\/507\/revisions\/508"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/media\/383"}],"wp:attachment":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/media?parent=507"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/categories?post=507"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/tags?post=507"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}