{"action":"created","issue":{"url":"https://api.github.com/repos/mit-cml/appinventor-sources/issues/407","labels_url":"https://api.github.com/repos/mit-cml/appinventor-sources/issues/407/labels{/name}","comments_url":"https://api.github.com/repos/mit-cml/appinventor-sources/issues/407/comments","events_url":"https://api.github.com/repos/mit-cml/appinventor-sources/issues/407/events","html_url":"https://github.com/mit-cml/appinventor-sources/issues/407","id":84298174,"number":407,"title":"Improve the drawing code for image sprites (and rotating them)","user":{"login":"halatmit","id":789431,"avatar_url":"https://avatars.githubusercontent.com/u/789431?v=3","gravatar_id":"","url":"https://api.github.com/users/halatmit","html_url":"https://github.com/halatmit","followers_url":"https://api.github.com/users/halatmit/followers","following_url":"https://api.github.com/users/halatmit/following{/other_user}","gists_url":"https://api.github.com/users/halatmit/gists{/gist_id}","starred_url":"https://api.github.com/users/halatmit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/halatmit/subscriptions","organizations_url":"https://api.github.com/users/halatmit/orgs","repos_url":"https://api.github.com/users/halatmit/repos","events_url":"https://api.github.com/users/halatmit/events{/privacy}","received_events_url":"https://api.github.com/users/halatmit/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-06-03T01:30:30Z","updated_at":"2015-06-05T14:14:05Z","closed_at":"2015-06-05T14:14:05Z","body":"This in an exchange between Hal and Dan Sandler of the Android team regarding how we rotate sprites.     You'll see that Dan suggest changing how we do the drawing.    Try this, and see if it's an improvement.  Make sure it does not have the \"black border\" bug that was fixed in pr #403\r\n\r\n\r\nHere's how we create the spriteL\r\n\r\nWe initially create a BitMapDrawable from an image:\r\n\r\n\r\nInputStream is2 = openMedia(form, mediaPath, mediaSource);\r\n\r\nreturn new BitmapDrawable(decodeStream(is2, null, options));\r\n\r\nI see that the BitmapDrawable constructor is deprecated.  I wonder if that's the issue.\r\n\r\nWe then build a bitmap\r\n  unrotatedBitmap = drawable.getBitmap();\r\n\r\nThen we scale the bitmap and rotate  it using a matrix, mat\r\nscaledBitmap = Bitmap.createScaledBitmap(unrotatedBitmap, w, h, true);\r\n\r\n rotatedBitmap = Bitmap.createBitmap(scaledBitmap,0, 0,scaledBitmap.getWidth(), scaledBitmap.getHeight(),mat, true);\r\n\r\nThen we build a drawable from the rotated bitmap\r\n\r\n  rotatedDrawable = new BitmapDrawable(rotatedBitmap);\r\n\r\nand we draw that on the canvas\r\n\r\n  rotatedDrawable.draw(canvas);\r\n\r\nAs I wrote, this all worked before Lollipop, but starting with system 5, the drawn rotated bitmap is surrounded by black, that fills out the bounding square.\r\nWe can fix this by doing rotatedBitmap.setAlpha before calling Bitmapdrawable.\r\n\r\nBut I'm wondering what changed and/or if we should be doing this another way.\r\n\r\nThanks\r\n\r\n\r\nDan Sandler\r\n12:29 PM (8 hours ago)\r\n\r\nto me \r\nA few things:\r\n\r\n(1) You're unnecessarily creating a BitmapDrawable when what you really want is the Bitmap; you want to use BitmapFactory.decodeStream() to go right to a Bitmap. \r\n\r\n(2) You probably don't want to bake a new rotated bitmap; you rather want to draw it with rotation (i.e. with a rotation matrix on the Canvas) so that you can keep the original bitmap around for a different rotation, but more importantly this should allow you to take advantage of hardware acceleration in the drawing.\r\n\r\n(3) Another way to do this is to create a BitmapDrawable as before (but use the non-deprecated constructor, BitmapDrawable (Resources res, InputStream is)) but then wrap it in a RotateDrawable and let it do all the work for you.\r\n"},"comment":{"url":"https://api.github.com/repos/mit-cml/appinventor-sources/issues/comments/109305711","html_url":"https://github.com/mit-cml/appinventor-sources/issues/407#issuecomment-109305711","issue_url":"https://api.github.com/repos/mit-cml/appinventor-sources/issues/407","id":109305711,"user":{"login":"jisqyv","id":1596728,"avatar_url":"https://avatars.githubusercontent.com/u/1596728?v=3","gravatar_id":"","url":"https://api.github.com/users/jisqyv","html_url":"https://github.com/jisqyv","followers_url":"https://api.github.com/users/jisqyv/followers","following_url":"https://api.github.com/users/jisqyv/following{/other_user}","gists_url":"https://api.github.com/users/jisqyv/gists{/gist_id}","starred_url":"https://api.github.com/users/jisqyv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jisqyv/subscriptions","organizations_url":"https://api.github.com/users/jisqyv/orgs","repos_url":"https://api.github.com/users/jisqyv/repos","events_url":"https://api.github.com/users/jisqyv/events{/privacy}","received_events_url":"https://api.github.com/users/jisqyv/received_events","type":"User","site_admin":false},"created_at":"2015-06-05T14:14:05Z","updated_at":"2015-06-05T14:14:05Z","body":"#408  Merged into ucr branch."}}