我写了一段代码,用相机拍照并将其转换为jpeg文件,然后将其作为ParseFile上传到Parse.com。
问题在于照片非常小(153 x 204像素),而且质量很低。
我需要照片至少为5 MP的质量,并将其裁剪成300x300像素。
这是我现在使用的代码。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_picture);
img = (ImageView) findViewById(R.id.imgV);
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
byte[] image_byte_array;
ParseObject post_object = new ParseObject("Gallery");
Bundle extras = data.getExtras();
Bitmap image = (Bitmap) extras.get("data");
ByteArrayOutputStream stream = new ByteArrayOutputStream();
image.compress(Bitmap.CompressFormat.JPEG, 100, stream);
image_byte_array = stream.toByteArray();
ParseFile picture_file = new ParseFile("Picture.jpg", image_byte_array);
picture_file.saveInBackground();
post_object.put("photo", picture_file);
post_object.saveInBackground();
}
感谢您的提前帮助。
onActivityResult
返回的data
只是一个缩略图,所以它很小。 - Derek Fung