热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

在不使用位图的情况下旋转和保存捕获的图像。-RotateandSavecapturedimagewithoutusingbitmap

IwanttorotateandsavemyCapturedImageusingAndroidNativeCameratosdcard.Asnativecameras

I want to rotate and save my Captured Image using Android Native Camera to sdcard. As native cameras is in landscape by default. But the I don't want to use bitmap. Is it possible to do so ? please help. I am new to android development.

我想用安卓自带的相机到sdcard来旋转和保存捕获的图像。在默认情况下,原生相机在景观中。但是我不想使用位图。有可能这样做吗?请帮助。我是android开发的新手。

As my image is rotated by 90 degrees I need to rotate it using Bitmap before saving. But on some devices bmp is coming null.

当我的图像旋转90度时,我需要在保存之前使用位图旋转它。但是在某些设备上,bmp是零。

Camera Activity Layout

相机活动布局



    

ManifestFile

ManifestFile



Camera Activity.java

相机Activity.java

FileOutputStream fos = new FileOutputStream(pictureFile);
Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length);
Matrix matrix = new Matrix();
matrix.postRotate(90);

bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
bmp.compress(Bitmap.CompressFormat.JPEG, 100,fos);

1 个解决方案

#1


0  

You should call onActivityResult after taking picture from camera and show your captured picture on ImageView. Bitmap takes memory but you should handle it. Follow the following steps below hopefully solve your Problem

您应该在从相机中拍照并在ImageView上显示您的捕获图片后调用onActivityResult。位图需要内存,但你应该处理它。按照下面的步骤,希望能解决你的问题。

STEP 1: open camera Intent and capture image from it:

第一步:打开相机的意图和捕捉图像:

private static final int REQUEST_CAMERA = 0;

Bitmap bmp;

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

startActivityForResult(intent, REQUEST_CAMERA);

STEP 2: override onActivityResult Method

步骤2:重写onActivityResult方法。

@Override   
protected void onActivityResult(int requestCode, int resultCode, Intent data) 
    {
        super.onActivityResult(requestCode, resultCode, data);

        if(resultCode == RESULT_OK)
        {
            if(requestCode == REQUEST_CAMERA)
            {               
                Uri uri = (Uri) data.getData();

                try 
                {
                    bmp = decodeUri(uri);

                    your_image_view.setImageBitmap(bmp);
                } 
                catch (FileNotFoundException e) 
                {
                    e.printStackTrace();
                }
            }

        }
    }

STEP 3: copy below method and paste it in your Activity

步骤三:复制下面的方法并粘贴到你的活动中。

private Bitmap decodeUri(Uri selectedImage) throws FileNotFoundException 
    {
        BitmapFactory.Options o = new BitmapFactory.Options();

        o.inJustDecodeBounds = true;

        BitmapFactory.decodeStream(
                getContentResolver().openInputStream(selectedImage), null, o);

        final int REQUIRED_SIZE = 70;

        int width_tmp = o.outWidth, height_tmp = o.outHeight;

        int scale = 1;

        while (true) 
        {
            if (width_tmp / 2 

and you are done after following these steps you will be able to capture image from camera and set it to your imageview without having memory error. Hope this will help you.

在完成这些步骤之后,您将能够从相机捕获图像并将其设置为您的imageview,而不会出现内存错误。希望这对你有帮助。


推荐阅读
author-avatar
潇湘V烟雨
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有