Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在不影响图像质量的情况下将带有文本的图像上载到服务器,_Android - Fatal编程技术网

Android 如何在不影响图像质量的情况下将带有文本的图像上载到服务器,

Android 如何在不影响图像质量的情况下将带有文本的图像上载到服务器,,android,Android,我通过截击和位图将图像上传到服务器,并成功地传递了数据,但当我使用相机拍摄图像时,图像质量变得非常差,而且当我传递的图像大小超过500kb时,应用程序也会崩溃。为什么会发生这种情况?? 有人能帮我吗 这就是我的相机的性能 private void onCaptureImageResult(Intent data) { thumbnail = (Bitmap) data.getExtras().get("data"); File destination = new File(E

我通过截击和位图将图像上传到服务器,并成功地传递了数据,但当我使用相机拍摄图像时,图像质量变得非常差,而且当我传递的图像大小超过500kb时,应用程序也会崩溃。为什么会发生这种情况?? 有人能帮我吗

这就是我的相机的性能

 private void onCaptureImageResult(Intent data) {
    thumbnail = (Bitmap) data.getExtras().get("data");

    File destination = new File(Environment.getExternalStorageDirectory(),
            System.currentTimeMillis() + ".jpg");

    FileOutputStream fo;
    try {
        destination.createNewFile();
        fo = new FileOutputStream(destination);
        //fo.write(bytes.toByteArray());
        fo.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    if (thumbnail!=null){
        addImageNew.setImageBitmap(thumbnail);
    }


}
private void onSelectFromGalleryResult(Intent data) {
    thumbnail=null;
    if (data != null) {
        try {
            thumbnail =    MediaStore.Images.Media.getBitmap(getApplicationContext().getContentResolver(), data.getData());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    if (thumbnail!=null){
        addImageNew.setImageBitmap(thumbnail);
    }
}
这就是我的图库意图的表现

 private void onCaptureImageResult(Intent data) {
    thumbnail = (Bitmap) data.getExtras().get("data");

    File destination = new File(Environment.getExternalStorageDirectory(),
            System.currentTimeMillis() + ".jpg");

    FileOutputStream fo;
    try {
        destination.createNewFile();
        fo = new FileOutputStream(destination);
        //fo.write(bytes.toByteArray());
        fo.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    if (thumbnail!=null){
        addImageNew.setImageBitmap(thumbnail);
    }


}
private void onSelectFromGalleryResult(Intent data) {
    thumbnail=null;
    if (data != null) {
        try {
            thumbnail =    MediaStore.Images.Media.getBitmap(getApplicationContext().getContentResolver(), data.getData());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    if (thumbnail!=null){
        addImageNew.setImageBitmap(thumbnail);
    }
}
这就是我如何将位图转换为字符串

 public String getStringImage(Bitmap bmp){
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bmp.compress(Bitmap.CompressFormat.JPEG, 90, baos);
    byte[] imageBytes = baos.toByteArray();
    String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT);
    return encodedImage;
}

注意:我只有图像质量和高尺寸图像传递方面的问题,您可以尝试使用下面的链接解决方案。这可能对你有用


我没有找到调用
getStringImage(位图bmp)
的位置,但您可以尝试这样做:

BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 1;
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length, options);
getStringImage(bitmap);
或者,您可以将
压缩
更改为100,以获得高质量:

bmp.compress(Bitmap.CompressFormat.JPEG, 100, baos);
我使用getStringImage()将位图转换为传递到服务器的字符串image=getStringImage(缩略图);/**其他代码**/参数输入(按键图像,图像)//用于将映像传递到服务器