【问题标题】:quallity of the image will be bad after cutting the image and sending it on the server?剪切图片发送到服务器后,图片质量会变差吗?
【发布时间】: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();
    }

}

备注:我使用 xml 中的小图像作为小预览:

<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); 只有在拍摄前尽可能将图像放大到最大或通过剪切,我才能获得良好的质量,我应该选择小空间,否则质量会很差。

标签: java android image camera


【解决方案1】:

您没有尝试将裁剪后的图像发送到服务器。

相反,您将裁剪后的图像显示在图像视图中。然后,您从该图像视图中获取屏幕转储并将其上传到服务器。当然 hat screendump 的质量很差。

您应该上传从裁剪功能获得的图像。

请比较所有相关图像的像素分辨率。

【讨论】:

  • 是的,我从 imageview 获取位图作为屏幕截图。怎么做才能直接从数据中获取?这是我的代码:@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if ( requestCode==111 &amp;&amp; resultCode==RESULT_OK ){ // Uri uri = data.getData(); // imageView.setImageURI(uri); imageView.setImageBitmap((Bitmap)data.getExtras().get("data")); } }
  • 我不会尝试在 cmets 中解码代码。将您的代码放在您的帖子中并提供我要求的信息。
  • 请看上面2张图片,为什么我选择小空间我会得到很好的质量?
  • 你还没有发布我要求的以像素为单位的分辨率。
  • 我使用高分辨率的前置摄像头。但是如果问题是解决方案,为什么我从 Galerie 的存储中选择图片时会遇到同样的问题。检查我添加的分辨率图像
猜你喜欢
  • 2011-07-21
  • 2011-11-18
  • 2015-05-29
  • 2018-02-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-08
  • 1970-01-01
相关资源
最近更新 更多