Android o2.inSampleSize=刻度; 位图位图=BitmapFactory.decodeFile(文件路径,o2); 返回位图; } 我不确定问题出在哪里。但发送图像时不必将图像解码为位图。事实上,您正在发送一个巨大的数组。因为内存中的映像比磁盘中的映像
o2.inSampleSize=刻度; 位图位图=BitmapFactory.decodeFile(文件路径,o2); 返回位图; }Android o2.inSampleSize=刻度; 位图位图=BitmapFactory.decodeFile(文件路径,o2); 返回位图; } 我不确定问题出在哪里。但发送图像时不必将图像解码为位图。事实上,您正在发送一个巨大的数组。因为内存中的映像比磁盘中的映像,android,Android,o2.inSampleSize=刻度; 位图位图=BitmapFactory.decodeFile(文件路径,o2); 返回位图; } 我不确定问题出在哪里。但发送图像时不必将图像解码为位图。事实上,您正在发送一个巨大的数组。因为内存中的映像比磁盘中的映像大。我认为更好的解决方案是读取文件并发送。也许你可以尝试以png格式存储。我不确定问题出在哪里。但发送图像时不必将图像解码为位图。事实上,您正在发送一个巨大的数组。因为内存中的映像比磁盘中的映像大。我认为更好的解决方案是读取文件并发送。也许你可
我不确定问题出在哪里。但发送图像时不必将图像解码为位图。事实上,您正在发送一个巨大的数组。因为内存中的映像比磁盘中的映像大。我认为更好的解决方案是读取文件并发送。也许你可以尝试以png格式存储。我不确定问题出在哪里。但发送图像时不必将图像解码为位图。事实上,您正在发送一个巨大的数组。因为内存中的映像比磁盘中的映像大。我认为更好的解决方案是读取文件并发送。也许你可以尝试以png格式存储。
// select image from Gallery
public void selectImageFromGallery() {
final String[] items = new String[]{"Camera", "Gallery"};
final Integer[] icons = new Integer[]{R.drawable.ic_camera, R.drawable.ic_gallery};
ListAdapter adapter = new ArrayAdapterWithIcon(CommentCreationUpdationActivity.this, items, icons);
new AlertDialog.Builder(CommentCreationUpdationActivity.this).setTitle("Select Picture")
.setAdapter(adapter, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
if (items[item].equals("Camera")) {
if (isDeviceSupportCamera()) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, REQUEST_CAMERA);
} else {
showCustomToast(" No camera on this device !!");
}
} else if (items[item].equals("Gallery")) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE);
}
}
}).show();
}
private boolean isDeviceSupportCamera() {
if (getApplicationContext().getPackageManager().hasSystemFeature(
PackageManager.FEATURE_CAMERA)) {
// this device has a camera
return true;
} else {
// no camera on this device
return false;
}
}
// get result after selecting image from Gallery
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_IMAGE && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor;
if (Build.VERSION.SDK_INT > 19) {
String wholeID = DocumentsContract.getDocumentId(selectedImage);
String id = wholeID.split(":")[1];
String sel = MediaStore.Images.Media._ID + "=?";
cursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
filePathColumn, sel, new String[]{id}, null);
} else {
cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
}
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
Constant.picturePathList.add(picturePath);
Bitmap bitmap1 = decodeFile(picturePath);
Constant.bitmapList.add(bitmap1);
cursor.close();
addImagesInLinearLayout();
}else if (requestCode == REQUEST_CAMERA && resultCode == RESULT_OK && null != data) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
// CALL THIS METHOD TO GET THE URI FROM THE BITMAP
Uri tempUri = getImageUri(getApplicationContext(), photo);
// CALL THIS METHOD TO GET THE ACTUAL PATH
String selectedImagePath =getRealPathFromURI(tempUri);
Constant.picturePathList.add(selectedImagePath);
Bitmap bitmap1 = decodeFile(selectedImagePath);
Constant.bitmapList.add(bitmap1);
addImagesInLinearLayout();
}
}
public Uri getImageUri(Context inContext, Bitmap inImage) {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);//I have doubt here
String path = MediaStore.Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null);
return Uri.parse(path);
}
public String getRealPathFromURI(Uri uri) {
Cursor cursor = getContentResolver().query(uri, null, null, null, null);
cursor.moveToFirst();
int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
return cursor.getString(idx);
}
public Bitmap decodeFile(String filePath) {
// Decode image size
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeFile(filePath, o);
// The new size we want to scale to
final int REQUIRED_SIZE = 1024; //I have doubt here
// Find the correct scale value. It should be the power of 2.
int width_tmp = o.outWidth, height_tmp = o.outHeight;
int scale = 1;
while (true) {
if (width_tmp < REQUIRED_SIZE && height_tmp < REQUIRED_SIZE)
break;
width_tmp /= 2;
height_tmp /= 2;
scale *= 2;
}
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = scale;
Bitmap bitmap = BitmapFactory.decodeFile(filePath, o2);
return bitmap;
}