阅读你的答案:
我已经按照您之前的代码进行操作了。我能够上传图像进行解析。但我不知道如何将可绘制源切换为来自相机/画廊或图像视图的图像。 ——斯坦利·桑托索
to :
阿布舍克·班萨尔
我了解您的问题不是解析您的图像?
尝试回答你的问题:
我不知道如何将可绘制源切换为来自相机/画廊或图像视图的图像。
1 - R.drawable.androidbegin 似乎是你的问题,但事实是你已经在代码中解析了位图:
来自画廊->
mImageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
从相机 ->
Bitmap photo = (Bitmap) data.getExtras().get("data");
2 - 所以我建议在代码开头声明一个 Bitmap 类型的变量
private Bitmap yourbitmap;
3 - 然后在代码中为图库和相机分配位图并使用它来解析它。
...
yourbitmap = BitmapFactory.decodeFile(picturePath);
...
yourbitmap = (Bitmap) data.getExtras().get("data");
...
4 - 最后你可以像这样使用你的位图:
// Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
// R.drawable.androidbegin);
// Convert it to byte
ByteArrayOutputStream stream = new ByteArrayOutputStream();
// Compress image to lower quality scale 1 - 100
yourbitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] image = stream.toByteArray();
...