{"action":"created","issue":{"url":"https://api.github.com/repos/bumptech/glide/issues/1239","repository_url":"https://api.github.com/repos/bumptech/glide","labels_url":"https://api.github.com/repos/bumptech/glide/issues/1239/labels{/name}","comments_url":"https://api.github.com/repos/bumptech/glide/issues/1239/comments","events_url":"https://api.github.com/repos/bumptech/glide/issues/1239/events","html_url":"https://github.com/bumptech/glide/issues/1239","id":157330817,"number":1239,"title":"Getting a Bitmap from a SVG Url resource","user":{"login":"gushoubang","id":8435230,"avatar_url":"https://avatars.githubusercontent.com/u/8435230?v=3","gravatar_id":"","url":"https://api.github.com/users/gushoubang","html_url":"https://github.com/gushoubang","followers_url":"https://api.github.com/users/gushoubang/followers","following_url":"https://api.github.com/users/gushoubang/following{/other_user}","gists_url":"https://api.github.com/users/gushoubang/gists{/gist_id}","starred_url":"https://api.github.com/users/gushoubang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gushoubang/subscriptions","organizations_url":"https://api.github.com/users/gushoubang/orgs","repos_url":"https://api.github.com/users/gushoubang/repos","events_url":"https://api.github.com/users/gushoubang/events{/privacy}","received_events_url":"https://api.github.com/users/gushoubang/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/bumptech/glide/labels/question","name":"question","color":"d4c5f9"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-05-28T09:51:56Z","updated_at":"2016-05-28T22:54:42Z","closed_at":null,"body":"I want it like this,becaus I need return the bitmap\r\n```java\r\nBitmap theBitmap = Glide.\r\n        with(this).\r\n        load(\"http://....\").\r\n        asBitmap().\r\n        into(100, 100). // Width and height\r\n        get();\r\n```\r\n \r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/bumptech/glide/issues/comments/222333386","html_url":"https://github.com/bumptech/glide/issues/1239#issuecomment-222333386","issue_url":"https://api.github.com/repos/bumptech/glide/issues/1239","id":222333386,"user":{"login":"TWiStErRob","id":2906988,"avatar_url":"https://avatars.githubusercontent.com/u/2906988?v=3","gravatar_id":"","url":"https://api.github.com/users/TWiStErRob","html_url":"https://github.com/TWiStErRob","followers_url":"https://api.github.com/users/TWiStErRob/followers","following_url":"https://api.github.com/users/TWiStErRob/following{/other_user}","gists_url":"https://api.github.com/users/TWiStErRob/gists{/gist_id}","starred_url":"https://api.github.com/users/TWiStErRob/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TWiStErRob/subscriptions","organizations_url":"https://api.github.com/users/TWiStErRob/orgs","repos_url":"https://api.github.com/users/TWiStErRob/repos","events_url":"https://api.github.com/users/TWiStErRob/events{/privacy}","received_events_url":"https://api.github.com/users/TWiStErRob/received_events","type":"User","site_admin":false},"created_at":"2016-05-28T22:54:42Z","updated_at":"2016-05-28T22:54:42Z","body":"Sorry the above was a rushed answer. I realize what's your problem now. That example only shows how to get a Drawable from SVG, but you need to render that to Bitmap, preferably with Glide, on a background thread. I use this class to rasterize my SVGs:\r\n```java\r\npublic class SvgBitmapDecoder implements ResourceDecoder<InputStream, Bitmap> {\r\n\tprivate final BitmapPool bitmapPool;\r\n\tpublic SvgBitmapDecoder(Context context) { this(Glide.get(context).getBitmapPool()); }\r\n\tpublic SvgBitmapDecoder(BitmapPool bitmapPool) { this.bitmapPool = bitmapPool; }\r\n\r\n\tpublic Resource<Bitmap> decode(InputStream source, int width, int height) throws IOException {\r\n\t\ttry {\r\n\t\t\tSVG svg = SVG.getFromInputStream(source);\r\n\t\t\tif (width == Target.SIZE_ORIGINAL && height == Target.SIZE_ORIGINAL) {\r\n\t\t\t\twidth = (int)svg.getDocumentWidth();\r\n\t\t\t\theight = (int)svg.getDocumentHeight();\r\n\t\t\t\tif (width <= 0 || height <= 0) {\r\n\t\t\t\t\tRectF viewBox = svg.getDocumentViewBox();\r\n\t\t\t\t\twidth = (int)viewBox.width();\r\n\t\t\t\t\theight = (int)viewBox.height();\r\n\t\t\t\t}\r\n\t\t\t} else {\r\n\t\t\t\tif (width == Target.SIZE_ORIGINAL) {\r\n\t\t\t\t\twidth = (int)(height * svg.getDocumentAspectRatio());\r\n\t\t\t\t}\r\n\t\t\t\tif (height == Target.SIZE_ORIGINAL) {\r\n\t\t\t\t\theight = (int)(width / svg.getDocumentAspectRatio());\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (width <= 0 || height <= 0) {\r\n\t\t\t\tthrow new IllegalArgumentException(\"Either the Target or the SVG document must declare a size.\");\r\n\t\t\t}\r\n\r\n\t\t\tBitmap bitmap = findBitmap(width, height);\r\n\t\t\tCanvas canvas = new Canvas(bitmap);\r\n\t\t\tsvg.renderToCanvas(canvas);\r\n\t\t\treturn BitmapResource.obtain(bitmap, bitmapPool);\r\n\t\t} catch (SVGParseException ex) {\r\n\t\t\tthrow new IOException(\"Cannot load SVG from stream\", ex);\r\n\t\t}\r\n\t}\r\n\r\n\tprivate Bitmap findBitmap(int width, int height) {\r\n\t\tBitmap bitmap = bitmapPool.get(width, height, Config.ARGB_8888);\r\n\t\tif (bitmap == null) {\r\n\t\t\tbitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);\r\n\t\t}\r\n\t\treturn bitmap;\r\n\t}\r\n\r\n\t@Override public String getId() {\r\n\t\treturn getClass().getSimpleName();\r\n\t}\r\n}\r\n```\r\nand all my SVGs look like this:\r\n```xml\r\n<?xml version=\"1.0\"?>\r\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\"> \r\n<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0,0 1000 1000\">...</svg>\r\n```\r\nI'm using Option 2 from #362 to end up with a GlideDrawable-compatible resource, even though I'm using a Bitmap a decoder, if you really just need a bitmap try something like this:\r\n```java\r\nGlide.with(context)\r\n     .load(source)\r\n     .asBitmap()\r\n     .imageDecoder(new SvgBitmapDecoder(context))\r\n     ....\r\n;\r\n```\r\n\r\nI would also suggest considering `.diskCacheStrategy(SOURCE)` or `.diskCacheStrategy(ALL)` due to small SVG source size."}}
{"actor":{"display_login":"TWiStErRob"}}