在Android中调整相机图像的大小
我想调整sd卡上图像的大小并将其发送到Web服务,调用是异步的,在Android中调整相机图像的大小,android,image-resizing,parcelable,Android,Image Resizing,Parcelable,我想调整sd卡上图像的大小并将其发送到Web服务,调用是异步的,ParcelFileDescriptor和CountingInputStreamEntity用于显示进度条。我应该怎么做才能以同样的方式调整大小和发送!这是我当前的代码: ParcelFileDescriptor fileDescriptor = context.getContentResolver().openFileDescriptor(uri, "r"); InputStream in = context.getContent
ParcelFileDescriptor
和CountingInputStreamEntity
用于显示进度条。我应该怎么做才能以同样的方式调整大小和发送!这是我当前的代码:
ParcelFileDescriptor fileDescriptor = context.getContentResolver().openFileDescriptor(uri, "r");
InputStream in = context.getContentResolver().openInputStream(uri);
CountingInputStreamEntity entity = new CountingInputStreamEntity(in, fileDescriptor.getStatSize());
entity.setUploadListener(this);
entity.setContentType("application/octet-stream");
put.setEntity(entity);
提前感谢。要调整相机图像的大小,您可以使用onActivitResult()中的以下代码 在中,您可以使用
选项调整图像大小。inSampleSize
然后根据您的样式将图像传递给web服务
我希望这有帮助。可以使用 您需要创建一个新的小宽度和高度的图像,如下所示:
private Bitmap decodeFile(File f){
Bitmap b = null;
try {
//Decode image size
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
FileInputStream fis = new FileInputStream(f);
BitmapFactory.decodeStream(fis, null, o);
fis.close();
int scale = 1;
if (o.outHeight > IMAGE_MAX_SIZE || o.outWidth > IMAGE_MAX_SIZE) {
scale = (int)Math.pow(2, (int) Math.round(Math.log(IMAGE_MAX_SIZE / (double) Math.max(o.outHeight, o.outWidth)) / Math.log(0.5)));
}
//Decode with inSampleSize
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = scale;
fis = new FileInputStream(f);
b = BitmapFactory.decodeStream(fis, null, o2);
fis.close();
} catch (IOException e) {
}
return b;
}
private Bitmap decodeFile(File f){
Bitmap b = null;
try {
//Decode image size
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
FileInputStream fis = new FileInputStream(f);
BitmapFactory.decodeStream(fis, null, o);
fis.close();
int scale = 1;
if (o.outHeight > IMAGE_MAX_SIZE || o.outWidth > IMAGE_MAX_SIZE) {
scale = (int)Math.pow(2, (int) Math.round(Math.log(IMAGE_MAX_SIZE / (double) Math.max(o.outHeight, o.outWidth)) / Math.log(0.5)));
}
//Decode with inSampleSize
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = scale;
fis = new FileInputStream(f);
b = BitmapFactory.decodeStream(fis, null, o2);
fis.close();
} catch (IOException e) {
}
return b;
}