{"id":8546,"date":"2020-03-25T10:00:35","date_gmt":"2020-03-25T01:00:35","guid":{"rendered":"https:\/\/www.gigas-jp.com\/appnews\/?p=8546"},"modified":"2020-03-24T19:19:05","modified_gmt":"2020-03-24T10:19:05","slug":"android%e3%81%ab%e8%a1%a8%e7%a4%ba%e3%81%99%e3%82%8b%e7%94%bb%e5%83%8f%e3%82%92%e5%8b%95%e7%9a%84%e3%81%ab%e5%9b%9e%e8%bb%a2%e3%81%95%e3%81%9b%e3%82%8b","status":"publish","type":"post","link":"https:\/\/www.gigas-jp.com\/appnews\/archives\/8546","title":{"rendered":"Android\u306b\u8868\u793a\u3059\u308b\u753b\u50cf\u3092\u52d5\u7684\u306b\u56de\u8ee2\u3055\u305b\u308b"},"content":{"rendered":"\n<p>ImageView\u306b\u8868\u793a\u3057\u3066\u3044\u308b\u753b\u50cf\u3092<br>\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u4e0a\u3067\u52d5\u7684\u306b\u56de\u8ee2\u3084\u62e1\u5927\u3092\u884c\u3046\u30b3\u30fc\u30c9\u306e\u3054\u7d39\u4ecb\u3067\u3059\u3002<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>ImageView\u306eScaleType\u3092Matrix\u306b\u8a2d\u5b9a\u3057\u3001<br>ImageMatrix\u306b\u5bfe\u3057\u3066\u884c\u5217\u6f14\u7b97\u3092\u884c\u3046\u3053\u3068\u3067<br>\u52d5\u7684\u306b\u753b\u50cf\u3092\u56de\u8ee2\u3055\u305b\u305f\u308a\u3001<br>\u62e1\u5927\u3057\u305f\u308a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002 <br><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" width=\"514\" height=\"1024\" src=\"\/appnews\/wp-content\/uploads\/sites\/4\/2020\/03\/Screenshot_20200324-190511-2-514x1024.png\" alt=\"\" class=\"wp-image-8559\" srcset=\"https:\/\/www.gigas-jp.com\/appnews\/wp-content\/uploads\/sites\/4\/2020\/03\/Screenshot_20200324-190511-2-514x1024.png 514w, https:\/\/www.gigas-jp.com\/appnews\/wp-content\/uploads\/sites\/4\/2020\/03\/Screenshot_20200324-190511-2.png 1072w\" sizes=\"(max-width: 514px) 100vw, 514px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u89d2\u5ea6\u4fdd\u5b58\u7528\u306e\u30e1\u30f3\u30d0\u5909\u6570\nvar rot = 0.0f\n\noverride fun onCreate (savedInstanceState: Bundle?) {\n    super.onCreate (savedInstanceState)\n    setContentView (R.layout.activity_main)\n\n    button.setOnClickListener (object: View.OnClickListener {\n        override fun onClick (v: View?) {\n            \/\/ \u52a0\u5de5\u7528\u306b\u884c\u5217\u3092\u30b3\u30d4\u30fc\n            val tmpMatrix = imageView.imageMatrix\n            \/\/ \u4fdd\u5b58\u3057\u3066\u3044\u308b\u89d2\u5ea6\u3092\u623b\u3059(ImageView\u306e\u4e2d\u5fc3\u3067\u56de\u8ee2)\n            tmpMatrix.postRotate (-rot, imageView.width * 0.5f, imageView.height * 0.5f)\n            \/\/ \u30a8\u30c7\u30a3\u30c3\u30c8\u30c6\u30ad\u30b9\u30c8\u304b\u3089\u89d2\u5ea6\u6570\u5024\u3092\u53d6\u5f97\n            rot = editText.text.toString ().toFloat ()\n            textView.setText (\"\u73fe\u5728\u306e\u89d2\u5ea6\uff1a\" + rot.toString ())\n            \/\/ \u89d2\u5ea6\u5206\u56de\u8ee2\u3055\u305b\u308b(ImageView\u306e\u4e2d\u5fc3\u3067\u56de\u8ee2)\n            tmpMatrix.postRotate (rot, imageView.width * 0.5f, imageView.height * 0.5f)\n            \/\/ \u884c\u5217\u3092\u9069\u7528\n            imageView.imageMatrix = tmpMatrix\n            imageView.invalidate ()\n        }\n    })\n\n    imageView.post (object: Runnable {\n        override fun run () {\n            imageView.scaleType = ImageView.ScaleType.MATRIX\n            fitImageSize (imageView)\n        }\n    })\n\n    textView.setText (\"\u73fe\u5728\u306e\u89d2\u5ea6\uff1a\" + rot.toString ())\n\n    editText.hint = \"\u89d2\u5ea6\u3092\u5165\u529b\"\n    \/\/ \u6570\u5b57\u306e\u5165\u529b\u306e\u307f\u306b\u5236\u9650\n    editText.inputType = TYPE_CLASS_NUMBER\n}  <\/code><\/pre>\n\n\n\n<p> fitImageSize \u95a2\u6570\u306fImageView\u306e\u30b5\u30a4\u30ba\u306b\u5408\u308f\u305b\u3066\u753b\u50cf\u3092<br>\u62e1\u5927\u3059\u308b\u305f\u3081\u306e\u95a2\u6570\u3067\u3059\u3002<br>\u9ad8\u3055\u3092\u57fa\u6e96\u306b\u62e1\u5927\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>private fun fitImageSize (view: ImageView) {\n    val drawable : Drawable = view.drawable\n    val matrix : Matrix = view.imageMatrix\n    \/\/ \u63cf\u753b\u3059\u308b\u753b\u50cf\u306e\u30a2\u30b9\u30da\u30af\u30c8\u6bd4\u3092\u6c42\u3081\u308b\n    val aspectRatio =\n        drawable.intrinsicWidth \/ drawable.intrinsicHeight.toFloat ()\n    \/\/ view\u306e\u9ad8\u3055\u306b\u30d5\u30a3\u30c3\u30c8\u3055\u305b\u308b\u306e\u3067\u9ad8\u3055\u57fa\u6e96\n    val viewWidth : Float = view.height * aspectRatio\n    val viewHeight : Float = view.height * 1.0f\n    \/\/ \u753b\u50cf\u304c\u306f\u307f\u51fa\u305f\u91cf\u3092\u6c42\u3081\u308b\n    val diff : Float = viewWidth - view.width\n    \/\/ \u63cf\u753b\u3059\u308b\u753b\u50cf\u3068view\u306e\u77e9\u5f62\u3092\u6c42\u3081\u3000\u77e9\u5f62\u306b\u5408\u308f\u305b\u308b\u884c\u5217\u3092\u4f5c\u6210\n    val imageRectF =\n        RectF (\n            0f, 0f,\n            drawable.intrinsicWidth.toFloat (),\n            drawable.intrinsicHeight.toFloat ()\n        )\n    val viewRectF = RectF (0f, 0f, viewWidth, viewHeight)\n    matrix.setRectToRect (imageRectF, viewRectF, Matrix.ScaleToFit.CENTER)\n    \/\/ \u753b\u50cf\u304c\u306f\u307f\u51fa\u305f\u5206\u3092\u88dc\u6b63\u3057\u3066\u4e2d\u592e\u3078\u79fb\u52d5\n    matrix.postTranslate (-(diff * 0.5f), 0f)\n    view.imageMatrix = matrix\n}<\/code><\/pre>\n\n\n\n<p>\u30bf\u30c3\u30c1\u30a4\u30d9\u30f3\u30c8\u3068\u9023\u52d5\u3055\u305b\u308c\u3070\u7c21\u5358\u306a\u30b2\u30fc\u30e0\u306e\u3088\u3046\u306a\u30a2\u30d7\u30ea\u3082\u4f5c\u308c\u305d\u3046\u3067\u3059\u306d\u3002<\/p>\n\n\n\n<p>\u6c34\u66dc\u62c5\u5f53\uff1aTanaka<\/p>\n<div class='wp_social_bookmarking_light'>\n            <div class=\"wsbl_google_plus_one\"><g:plusone size=\"medium\" annotation=\"none\" href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/8546\" ><\/g:plusone><\/div>\n            <div class=\"wsbl_hatena_button\"><a href=\"\/\/b.hatena.ne.jp\/entry\/https:\/\/www.gigas-jp.com\/appnews\/archives\/8546\" class=\"hatena-bookmark-button\" data-hatena-bookmark-title=\"Android\u306b\u8868\u793a\u3059\u308b\u753b\u50cf\u3092\u52d5\u7684\u306b\u56de\u8ee2\u3055\u305b\u308b\" data-hatena-bookmark-layout=\"standard\" title=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\"> <img src=\"\/\/b.hatena.ne.jp\/images\/entry-button\/button-only@2x.png\" alt=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\" width=\"20\" height=\"20\" style=\"border: none;\" \/><\/a><script type=\"text\/javascript\" src=\"\/\/b.hatena.ne.jp\/js\/bookmark_button.js\" charset=\"utf-8\" async=\"async\"><\/script><\/div>\n            <div class=\"wsbl_twitter\"><a href=\"https:\/\/twitter.com\/share\" class=\"twitter-share-button\" data-url=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/8546\" data-text=\"Android\u306b\u8868\u793a\u3059\u308b\u753b\u50cf\u3092\u52d5\u7684\u306b\u56de\u8ee2\u3055\u305b\u308b\" data-via=\"GIGASJAPAN_APPS\" data-lang=\"ja\">Tweet<\/a><\/div>\n            <div class=\"wsbl_facebook_like\"><div id=\"fb-root\"><\/div><fb:like href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/8546\" layout=\"button_count\" action=\"like\" width=\"100\" share=\"false\" show_faces=\"false\" ><\/fb:like><\/div>\n            <div class=\"wsbl_facebook_send\"><div id=\"fb-root\"><\/div><fb:send href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/8546\" colorscheme=\"light\" ><\/fb:send><\/div>\n    <\/div>\n<br class='wp_social_bookmarking_light_clear' \/>\n","protected":false},"excerpt":{"rendered":"<p>ImageView\u306b\u8868\u793a\u3057\u3066\u3044\u308b\u753b\u50cf\u3092\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u4e0a\u3067\u52d5\u7684\u306b\u56de\u8ee2\u3084\u62e1\u5927\u3092\u884c\u3046\u30b3\u30fc\u30c9\u306e\u3054\u7d39\u4ecb\u3067\u3059\u3002<\/p>\n","protected":false},"author":17,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[119,12],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/8546"}],"collection":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/users\/17"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/comments?post=8546"}],"version-history":[{"count":11,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/8546\/revisions"}],"predecessor-version":[{"id":8562,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/8546\/revisions\/8562"}],"wp:attachment":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/media?parent=8546"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/categories?post=8546"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/tags?post=8546"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}