Chu*_*lly 2 upload android asynchronous file bitmap
经过一天的头痛,由于以前的问题实施工作照片上传系统,我觉得我在家里伸展.我的最后和最后一步是允许我的用户在裁剪后上传图像.
裁剪发生后,我可以访问位图和使用位图的imageView.使用的异步请求库是:http://loopj.com/android-async-http/
api im using以这样的方式设置,我需要发送一个"文件",如下所示:
File myFile = new File("/path/to/file.png");
RequestParams params = new RequestParams();
try {
params.put("profile_picture", myFile);
} catch(FileNotFoundException e) {}
Run Code Online (Sandbox Code Playgroud)
将位图转换为"文件"有什么选择?
您可以使用Bitmap.compress方法将Bitmap保存到文件.只需提供适当的FileOutputStream作为参数.
您也可以不使用文件上传图像,只需将其保存到字节数组,然后上传为该数组.
ByteArrayOutputStream out = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 85, out);
byte[] myByteArray = out.toByteArray();
RequestParams params = new RequestParams();
params.put("profile_picture", new ByteArrayInputStream(myByteArray), "image.png");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1360 次 |
| 最近记录: |