简体   繁体   English

将拍摄的图片转换为位图

[英]Convert taken picture to bitmap

I want to edit the photo that was just taken by the camera in my app. 我想在应用程序中编辑相机刚刚拍摄的照片。 Got everything working in terms of taking a picture and saving that picture to the gallery; 在拍摄照片并将照片保存到图库方面,一切正常; however, I want to get that picture before saving it so I can overlay an logo on it. 但是,我想先保存图片,然后再在其上覆盖徽标。 My idea was running this bit of code in activity result: 我的想法是在活动结果中运行以下代码:

/* Decode the JPEG file into a Bitmap */
        Bitmap bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);

then creating another bitmap with my logo and overlay that on the first bitmap. 然后用我的徽标创建另一个位图,并将其覆盖在第一个位图上。 However the picture and drawable source are too big to decode into a bitmap and I get an OutOfMemoryError . 但是,图片和可绘制源太大,无法解码为位图,并且出现OutOfMemoryError I don't want to scale down my images, because it must be a high res image. 我不想按比例缩小图像,因为它必须是高分辨率图像。 What's the way to go now? 现在要走什么路?

Set Android:LargeHeap="true" option in the Manifest file. 在清单文件中设置Android:LargeHeap =“ true”选项。 And allow image loading action only when you have enough available memory. 并且仅在有足够的可用内存时才允许图像加载操作。 (this param is available I think only since Android 3.0) (我认为只有从Android 3.0开始,此参数才可用)

There is no magic. 没有魔术。 If image exceeds available memory, then you could read and edit parts of image. 如果图像超出可用内存,则可以读取和编辑部分图像。 But it's not the most convenient way to process images. 但这不是处理图像的最便捷方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM