微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

com.android.camera.action.CROP在Motorola Defy上设置墙纸

如何解决com.android.camera.action.CROP在Motorola Defy上设置墙纸

|| 我正在使用Android 2.1+应用程序,试图拍照,然后将意图的结果发送到裁剪功能。它似乎可以在索尼爱立信xmp上工作,但是当我将其放在Moto Defy上时,裁切功能失败,因为它似乎忽略了我为数据输入的文件名,而是出于某种原因而将其查找为“ 0”。结果是裁剪功能不返回任何数据,我刚刚拍摄的图像被设置为手机的墙纸图像! 这是一些示例代码
public static final String SD_CARD_TEMP_DIR = Environment.getExternalStorageDirectory() + File.separator;
public static final String SD_CARD_TEMP_ORIG = SD_CARD_TEMP_DIR + \"origPhoto.jpg\";
public static final String SD_CARD_TEMP_CROP = SD_CARD_TEMP_DIR + \"croppedPhoto.jpg\";

Intent intent = new Intent(\"com.android.camera.action.CROP\");
intent.setDataAndType(Uri.fromFile(new File(Const.SD_CARD_TEMP_ORIG)),\"image/*\");
intent.putExtra(\"crop\",true);
intent.putExtra(\"aspectX\",1);
intent.putExtra(\"aspectY\",1);
intent.putExtra(\"outputX\",512);
intent.putExtra(\"outputY\",512);
intent.putExtra(\"return-data\",false);
intent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(new File(Const.SD_CARD_TEMP_CROP)));
这样的输出是这样的:
INFO/ActivityManager(1242): Starting activity: Intent { act=com.android.camera.action.CROP dat=file:///sdcard/origPhoto.jpg typ=image/* cmp=com.motorola.gallery/.CropImage (has extras) }
INFO/ActivityManager(1242): Start proc com.motorola.gallery:CropImage for activity com.motorola.gallery/.CropImage: pid=25733 uid=10014 gids={1015,9003,9007,9008,2001,3003}
WARN/CropImage(25733): CropImg mBitmap was null,retreive frm URIfile:///sdcard/origPhoto.jpg
ERROR/CropImage(25733): got IOException java.io.FileNotFoundException: /data/data/com.motorola.gallery/files/temp-wallpaper 
INFO/ActivityManager(1242): displayed activity com.motorola.gallery/.CropImage: 5664 ms (total 5664 ms)
WARN/System.err(25672): java.io.FileNotFoundException: /sdcard/croppedPhoto.jpg
DEBUG/(25672): unable to unlink \'/sdcard/croppedPhoto.jpg\': No such file or directory (errno=2)
是否有人对此问题有任何经验或解决方法

解决方法

我会远离您使用的Intent,因为它不是标准的,因此可能不会在所有地方得到支持, 通过您使用的额外数据,我相信您正在进行固定大小的裁剪,并且不需要任何用户输入。只要您不耗尽内存,这就使解决方案变得非常简单。 通过BitmapFactory.decodeFile加载图像。您可以传入BitmapFactory.options对象以选择在加载时缩放图像。 使用Bitmap.createBitmap创建裁剪的位图(位图源,int x,int y,int宽度,int高度) 使用Bitmap.compress将其写出到磁盘

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。