【发布时间】:2017-04-19 14:16:11
【问题描述】:
我不知道,是剪切功能的问题还是解码代码的问题? : 我使用代码进行上传:
public void Upload(View view) {
Bitmap Bimg = ((BitmapDrawable) image1.getDrawable()).getBitmap();
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
Bimg.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
// Bimg.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream); // bad too
encodimg = Base64.encodeToString(byteArrayOutputStream.toByteArray(), Base64.DEFAULT);
我使用此代码剪切图像:
private void performCrop(){
try {
Intent cropIntent = new Intent("com.android.camera.action.CROP");
cropIntent.setDataAndType(picUri, "image/*");
cropIntent.putExtra("crop", "true");
cropIntent.putExtra("aspectX", 1);
cropIntent.putExtra("aspectY", 1);
cropIntent.putExtra("outputX", 512);
cropIntent.putExtra("outputY", 512);
cropIntent.putExtra("return-data", true);
startActivityForResult(cropIntent, PIC_CROP);
Toast toast = Toast.makeText(this, "Done", Toast.LENGTH_SHORT);
}
catch(ActivityNotFoundException anfe){
String errorMessage = "Soory - your device doesn't support the crop action!";
Toast toast = Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT);
toast.show();
}
}
<ImageView
android:onClick="Load_Picture"
android:id="@+id/imageview1"
android:background="@drawable/default_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
但我不喜欢,xml中的图像大小是问题
像这样从相机或画廊中获取位图:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if ( requestCode==111 && resultCode==RESULT_OK ){
// Uri uri = data.getData();
// imageView.setImageURI(uri);
imageView.setImageBitmap((Bitmap)data.getExtras().get("data"));
}
}
问题是切割方法,因为如果我在切割前上传位图,我会得到非常好的质量。所以问题是:
performCrop(){
【问题讨论】:
-
我们看不到您对裁剪后的图像做了什么。
-
I use the code for for uploading:该代码无法上传。 -
is the problem the cut function or the Decoding Code。你是说裁剪功能?还有编码? -
例如:
cropIntent.putExtra("outputX", 2028); cropIntent.putExtra("outputY", 1152);只有在拍摄前尽可能将图像放大到最大或通过剪切,我才能获得良好的质量,我应该选择小空间,否则质量会很差。