我从手机的相机中捕获了2592x1936
的图像,并将其转换为位图。我将其imageview显示为myImageVew.setImageBitmap(myBitmap);
显示此位图后,我对此图像执行了一些操作(在imageview内),现在我使用
保存Bitmap bitmap;
// frmCaptureThis is the root framelayout (this contains my imageview)
View v1 = frmCaptureThis;
v1.setDrawingCacheEnabled(true);
bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);
saveImgToSDcard(bitmap);
这是将我的图像保存到SD卡但不是2592x1936
分辨率,它保存的图像大小等于imageView大小(即400X620)。我想以原始分辨率保存图像,即2592x1936
修改
这是我通过意图拍摄图像的代码
// ////////// Capture Button Handler//////////////////
btnCapture.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, "New Picture");
values.put(MediaStore.Images.Media.DESCRIPTION,
"From your Camera");
imageUri = getActivity().getContentResolver().insert(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION,
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(intent, REQUEST_OPEN_CAMERA);
}
});
这是我的活动结果方法
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
String imageurl = null;
if (requestCode == REQUEST_OPEN_CAMERA
&& resultCode == Activity.RESULT_OK) {
captureFlage = true;
relTapToCapture.setEnabled(false);
relHeader.setVisibility(View.INVISIBLE);
frmCaptureThis.setVisibility(View.VISIBLE);
btnCapture.setVisibility(View.VISIBLE);
btnSave.setVisibility(View.VISIBLE);
txtTapToCapture.setVisibility(View.INVISIBLE);
try {
thumbnail = MediaStore.Images.Media.getBitmap(getActivity()
.getContentResolver(), imageUri);
} catch (FileNotFoundException e) {
} catch (IOException e) {
}
imageurl = getRealPathFromURI(imageUri);
if (thumbnail.getWidth() > thumbnail.getHeight()) {
// Log.i("Orientation", "LandScape");
// thumbnail = rotateImage_90(thumbnail);
imgCaptured.setImageBitmap(thumbnail);
} else {
// Log.i("Orientation", "Portrait");
imgCaptured.setImageBitmap(thumbnail);
}
File file = new File(imageurl);
boolean deleted = file.delete();
}
super.onActivityResult(requestCode, resultCode, data);
}
这是我在SD卡中保存图像的方法
public void saveImgToSDcard(Bitmap bitmap) {
Calendar cal = Calendar.getInstance();
System.out.println("Current milliseconds since 13 Oct, 2008 are :"
+ cal.getTimeInMillis());
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
File f = new File(Environment.getExternalStorageDirectory()
+ File.separator + "brandYourImage" + cal.getTimeInMillis()
+ ".jpg");
try {
f.createNewFile();
} catch (IOException e) {
}
// write the bytes in file
FileOutputStream fo = null;
try {
fo = new FileOutputStream(f);
} catch (FileNotFoundException e) {
}
try {
fo.write(bytes.toByteArray());
} catch (IOException e) {
}
// remember close de FileOutput
try {
fo.close();
Toast.makeText(getActivity(), "Saved Successfully",
Toast.LENGTH_SHORT).show();
} catch (IOException e) {
}
}