android将我裁剪的图像设置为壁纸
我只是裁剪图像以获得其中的一部分。但是Android将返回的图像设置为壁纸。为什么?我跟踪android代码,在Gallery3D应用程序(com.cooliris)中发现:android将我裁剪的图像设置为壁纸,android,crop,wallpaper,Android,Crop,Wallpaper,我只是裁剪图像以获得其中的一部分。但是Android将返回的图像设置为壁纸。为什么?我跟踪android代码,在Gallery3D应用程序(com.cooliris)中发现: // TODO: A temporary file is NOT necessary // The CropImage intent should be able to set the wallpaper directly // without writing to a file, which we
// TODO: A temporary file is NOT necessary
// The CropImage intent should be able to set the wallpaper directly
// without writing to a file, which we then need to read here to write
// it again as the final wallpaper, this is silly
mTempFile = getFileStreamPath("temp-wallpaper");
mTempFile.getParentFile().mkdirs();
int width = getWallpaperDesiredMinimumWidth();
int height = getWallpaperDesiredMinimumHeight();
intent.putExtra("outputX", width);
intent.putExtra("outputY", height);
intent.putExtra("aspectX", width);
intent.putExtra("aspectY", height);
intent.putExtra("scale", true);
intent.putExtra("noFaceDetection", true);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mTempFile));
intent.putExtra("outputFormat", Bitmap.CompressFormat.PNG.name());
// TODO: we should have an extra called "setWallpaper" to ask CropImage
// to set the cropped image as a wallpaper directly. This means the
// SetWallpaperThread should be moved out of this class to CropImage
请关注最后几行,即待办事项。它表示裁剪意图将完成设置工作。嗯,我根本不需要它。那么,如何在不设置壁纸的情况下裁剪图像?谢谢 在你的代码中这样做(请记住,它不会适用于所有手机,比如HTC,因为它们使用自己的多媒体资料/摄像头)
File f = new File(Environment.getExternalStorageDirectory(), "/temporary_holder.png");
f.createNewFile();
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setClassName("com.android.gallery", "com.android.camera.CropImage");
intent.setType("image/*");
intent.setData(ImageToSetUri); // Local URI of your image
intent.putExtra("crop", true);
intent.putExtra("outputX", width); // width/height of your image
intent.putExtra("outputY", height);
intent.putExtra("aspectX", width);
intent.putExtra("aspectY", height);
intent.putExtra("scale", true);
intent.putExtra("noFaceDetection", true);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
intent.putExtra("outputFormat", Bitmap.CompressFormat.PNG.name());
startActivityForResult(intent, 1);
然后执行此操作以将图像检索为位图,或以您想要的方式检索图像
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK)
if (data != null) {
Bitmap selectedImage = BitmapFactory.decodeFile(f);
}
}
在你的代码中做到这一点(请记住,它不会在所有手机上都起作用,比如HTC,因为它们使用自己的多媒体资料/摄像头
File f = new File(Environment.getExternalStorageDirectory(), "/temporary_holder.png");
f.createNewFile();
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setClassName("com.android.gallery", "com.android.camera.CropImage");
intent.setType("image/*");
intent.setData(ImageToSetUri); // Local URI of your image
intent.putExtra("crop", true);
intent.putExtra("outputX", width); // width/height of your image
intent.putExtra("outputY", height);
intent.putExtra("aspectX", width);
intent.putExtra("aspectY", height);
intent.putExtra("scale", true);
intent.putExtra("noFaceDetection", true);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
intent.putExtra("outputFormat", Bitmap.CompressFormat.PNG.name());
startActivityForResult(intent, 1);
然后执行此操作以将图像检索为位图,或以您想要的方式检索图像
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK)
if (data != null) {
Bitmap selectedImage = BitmapFactory.decodeFile(f);
}
}