捕获的图像采用BITMAP格式。通常我们会在将图像上传到服务器之前压缩图像。我需要上传图像而不压缩。请找到以下代码:
if (CAMERA_PIC_REQUEST == 11)
{
switch (resultCode)
{
case CertificationAddOwnerImage.RESULT_OK:
if(CAMERA_PIC_REQUEST==11)
{
Bitmap myBitmap = BitmapFactory.decodeFile(mCurrentPhotoPath);
click_img.setImageBitmap(myBitmap);
//onCaptureImageResult(data);
}
else
{
Toast.makeText(this, "The file was saved at"+imageFile.getAbsolutePath(),
Toast.LENGTH_SHORT).show();
}
break;
case Activity.RESULT_CANCELED:
break;
}
}
答案 0 :(得分:0)
你可以尝试获取位图的字节数组
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
然后通过请求正文
上传字节数组RequestBody requestBody = RequestBody
.create(MediaType.parse("application/octet-stream"), byteArray);