如何从drwable中获取照片并将其上传到Android中

如何从drwable中获取照片并将其上传到Android中,android,parsing,Android,Parsing,我想做一个代码,可以从drwable文件夹中获取JPG图像,并将其上传到parse,以及如何将其检索到列表视图中。首先,您需要将drawable转换为位图 Bitmap icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.icon_resource); 现在您可以使用下面的代码将位图转换为字符串 ByteArrayOut

我想做一个代码,可以从drwable文件夹中获取JPG图像,并将其上传到parse,以及如何将其检索到列表视图中。首先,您需要将drawable转换为位图

Bitmap icon = BitmapFactory.decodeResource(context.getResources(),
                                           R.drawable.icon_resource);
现在您可以使用下面的代码将位图转换为字符串

ByteArrayOutputStream baos = new ByteArrayOutputStream();
photo.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] imageBytes = baos.toByteArray();
String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT);
然后将此encodedImage作为字符串发送,在服务器中需要对其进行解码才能获得图像本身