保存旋转位图 android
(如果我完全错了,请原谅我,我是新手) 我正在显示一些使用 MediaStore.ACTION_IMAGE_CAPTURE
拍摄的照片。我尝试在拍照时禁用自动方向,但它似乎不起作用,我使用
putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION,ActivityInfo.SCREEN_ORIENTATION_NOSENSOR)
这迫使我旋转一些拍摄的照片。然后我将这些照片保存到 SDCARD。我的问题是我不想在每次用户加载照片时旋转它们。我尝试使用此代码创建一个新的位图,该位图将以“旋转”状态保存。它可以在模拟器上运行,但在我的 HTC 上崩溃。我认为这是一个内存问题。有什么办法可以有效地做到这一点吗?更好的是,有什么方法可以在使用相机意图拍照时真正禁用自动方向吗?
tempBitmap=BitmapFactory.decodeFile(dirPath+filename+".jpg");
int tempW = tempBitmap.getWidth();
int tempH = tempBitmap.getHeight();
if (tempW>tempH) {
Matrix mtx = new Matrix();
mtx.postRotate(90);
Bitmap rotatedBitmap = Bitmap.createBitmap(Bitmap.createBitmap(tempBitmap, 0, 0,
tempW, tempH, mtx, true));
} else{
//...
}
(Forgive me if Im getting this totally wrong, I am a newbie)
I am displaying some photos taken with MediaStore.ACTION_IMAGE_CAPTURE
. I tried to disable autoorientation when picture is being taken but it doesnt seem to work, i used
putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION,ActivityInfo.SCREEN_ORIENTATION_NOSENSOR)
This forced me to rotate some of the taken photos. I then save these photos to SDCARD. My problem is that i dont want to rotate them every time user loads a photo. I tried this code to create a new Bitmap that would be saved in 'rotated' state. It worked on emulator but crashes on my HTC. I assume its a memory problem. Is there any way to do this efficiently? Better yet, is there any way to really disable autoorientation while taking photos with Camera Intent?
tempBitmap=BitmapFactory.decodeFile(dirPath+filename+".jpg");
int tempW = tempBitmap.getWidth();
int tempH = tempBitmap.getHeight();
if (tempW>tempH) {
Matrix mtx = new Matrix();
mtx.postRotate(90);
Bitmap rotatedBitmap = Bitmap.createBitmap(Bitmap.createBitmap(tempBitmap, 0, 0,
tempW, tempH, mtx, true));
} else{
//...
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
与上面相同,但他忘记了最后一行的一些代码
Same as above but he forgot some code on the last line
尝试减少您正在使用的图像,这可能是内存问题。请参阅下文了解可能的解决方案。
try reducing the image that you are working with it may be a memory issue. See below for possible solution.
通过以下代码,
要停止图像的分级,请使用以下代码 -
如果您遇到任何问题,请参阅以下链接
http://androidlift.info/2016/01/07/android-camera-image-capturing-and-uploading-to-php-server/
Go through following code,
For Stop ratation of image use following code -
If you are facing any issue please refer following link
http://androidlift.info/2016/01/07/android-camera-image-capturing-and-uploading-to-php-server/