{"action":"created","issue":{"url":"https://api.github.com/repos/jpush/aurora-imui/issues/259","repository_url":"https://api.github.com/repos/jpush/aurora-imui","labels_url":"https://api.github.com/repos/jpush/aurora-imui/issues/259/labels{/name}","comments_url":"https://api.github.com/repos/jpush/aurora-imui/issues/259/comments","events_url":"https://api.github.com/repos/jpush/aurora-imui/issues/259/events","html_url":"https://github.com/jpush/aurora-imui/issues/259","id":294605674,"number":259,"title":"从本地相册选图片和拍照的图片需限制大小","user":{"login":"musicode","id":2732303,"avatar_url":"https://avatars2.githubusercontent.com/u/2732303?v=4","gravatar_id":"","url":"https://api.github.com/users/musicode","html_url":"https://github.com/musicode","followers_url":"https://api.github.com/users/musicode/followers","following_url":"https://api.github.com/users/musicode/following{/other_user}","gists_url":"https://api.github.com/users/musicode/gists{/gist_id}","starred_url":"https://api.github.com/users/musicode/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/musicode/subscriptions","organizations_url":"https://api.github.com/users/musicode/orgs","repos_url":"https://api.github.com/users/musicode/repos","events_url":"https://api.github.com/users/musicode/events{/privacy}","received_events_url":"https://api.github.com/users/musicode/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-02-06T01:55:15Z","updated_at":"2018-02-07T07:11:46Z","closed_at":null,"author_association":"NONE","body":"微信发出去的大图，基本只有100多KB，希望 imui 也可以限制一下"},"comment":{"url":"https://api.github.com/repos/jpush/aurora-imui/issues/comments/363677880","html_url":"https://github.com/jpush/aurora-imui/issues/259#issuecomment-363677880","issue_url":"https://api.github.com/repos/jpush/aurora-imui/issues/259","id":363677880,"user":{"login":"KenChoi1992","id":8196928,"avatar_url":"https://avatars1.githubusercontent.com/u/8196928?v=4","gravatar_id":"","url":"https://api.github.com/users/KenChoi1992","html_url":"https://github.com/KenChoi1992","followers_url":"https://api.github.com/users/KenChoi1992/followers","following_url":"https://api.github.com/users/KenChoi1992/following{/other_user}","gists_url":"https://api.github.com/users/KenChoi1992/gists{/gist_id}","starred_url":"https://api.github.com/users/KenChoi1992/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/KenChoi1992/subscriptions","organizations_url":"https://api.github.com/users/KenChoi1992/orgs","repos_url":"https://api.github.com/users/KenChoi1992/repos","events_url":"https://api.github.com/users/KenChoi1992/events{/privacy}","received_events_url":"https://api.github.com/users/KenChoi1992/received_events","type":"User","site_admin":false},"created_at":"2018-02-07T07:11:46Z","updated_at":"2018-02-07T07:11:46Z","author_association":"MEMBER","body":"@musicode 你可以自己操作一下，我这里可以贴上代码。\r\n```\r\nimport cn.jiguang.imui.commons.BitmapLoader;\r\n\r\n...\r\n/**\r\n     * 裁剪图片，将图片按比例裁剪成 width * height 大小\r\n     * @param map 包含 path，width，height 参数\r\n     * @param callback 回调包含裁剪后的路径\r\n     */\r\n    @ReactMethod\r\n    public void scaleImage(ReadableMap map, Callback callback) {\r\n        try {\r\n            String path = map.getString(\"path\");\r\n            int width = map.getInt(\"width\");\r\n            int height = map.getInt(\"height\");\r\n            File file = new File(path);\r\n            WritableMap result = Arguments.createMap();\r\n            if (file.isFile()) {\r\n                Bitmap bitmap = BitmapLoader.getBitmapFromFile(path, width, height);\r\n                String fileName = file.getName();\r\n                String thumbPath = saveBitmapToLocal(bitmap, fileName);\r\n                result.putInt(\"code\", 0);\r\n                result.putString(\"thumbPath\", thumbPath);\r\n                callback.invoke(result);\r\n            } else {\r\n                result.putInt(\"code\", -1);\r\n                result.putString(\"error\", \"Path is invalid\");\r\n                callback.invoke(result);\r\n            }\r\n        } catch (Exception e) {\r\n            e.printStackTrace();\r\n        }\r\n    }\r\n\r\n    /**\r\n     * 根据bitmap保存图片到本地\r\n     *\r\n     * @param bitmap bitmap\r\n     * @return file path\r\n     */\r\n    private String saveBitmapToLocal(Bitmap bitmap, String fileName) {\r\n        if (null == bitmap) {\r\n            return null;\r\n        }\r\n        String filePath;\r\n        FileOutputStream fileOutput = null;\r\n        File imgFile;\r\n        try {\r\n            File desDir = new File(getReactApplicationContext().getFilesDir() + \"/thumbnails/\");\r\n            if (!desDir.exists()) {\r\n                desDir.mkdirs();\r\n            }\r\n            imgFile = new File(getReactApplicationContext().getFilesDir() + \"/thumbnails/\", fileName);\r\n            imgFile.createNewFile();\r\n            fileOutput = new FileOutputStream(imgFile);\r\n            bitmap.compress(Bitmap.CompressFormat.PNG, 100, fileOutput);\r\n            fileOutput.flush();\r\n            filePath = imgFile.getAbsolutePath();\r\n        } catch (FileNotFoundException e) {\r\n            e.printStackTrace();\r\n            filePath = null;\r\n        } catch (IOException e) {\r\n            e.printStackTrace();\r\n            filePath = null;\r\n        } finally {\r\n            if (null != fileOutput) {\r\n                try {\r\n                    fileOutput.close();\r\n                } catch (IOException e) {\r\n                    e.printStackTrace();\r\n                }\r\n            }\r\n        }\r\n        return filePath;\r\n    }\r\n```"}}
{"actor":{"display_login":"KenChoi1992"}}