无法在Android Studio中在我的屏幕上显示和保存捕获的图像

西瓦库马尔

当我仅显示捕获的图像时,我的代码有效,当我添加代码以将捕获的图像保存在图库中时,其代码不起作用。

public class MainActivity extends Activity {
    private static int RESULT_LOAD_IMG = 1;
    String imgDecodableString;
    ImageView iv;
    Button b;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        iv = (ImageView) findViewById(R.id.imgView);
        Button b = (Button) findViewById(R.id.buttonLoadPicture);
        b.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String path = Environment.getExternalStorageDirectory() + "/CameraImages/example.jpg";
                File file = new File(path);
                Uri outputFileUri = Uri.fromFile(file);
                Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
                startActivityForResult(intent, 1);
            }
        });
    }

    Bitmap bmp;

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

        if (data != null && data.getExtras() != null) {
            bmp = (Bitmap) data.getExtras().get("data");

            iv.setImageBitmap(bmp);
        }

    }
}

请帮帮我,我很震惊

编辑:这是我的Logcat

12-23 12:44:07.701 8180-8180/com.prgguru.example D/dalvikvm﹕ Late-enabling CheckJNI 
12-23 12:44:07.741 8180-8180/com.prgguru.example D/ActivityThread﹕ handleBindApplication:com.prgguru.example 
12-23 12:44:07.741 8180-8180/com.prgguru.example D/ActivityThread﹕ setTargetHeapUtilization:0.25 
12-23 12:44:07.741 8180-8180/com.prgguru.example D/ActivityThread﹕ setTargetHeapMinFree:2097152 
12-23 12:44:07.751 8180-8180/com.prgguru.example D/ActivityThread﹕ setTargetHeapConcurrentStart:2097152 
12-23 12:44:07.761 8180-8180/com.prgguru.example V/HwPolicyFactory﹕ : success to get AllImpl object and return.... 
12-23 12:44:07.781 8180-8180/com.prgguru.example V/HwWidgetFactory﹕ : successes to get AllImpl object and return.... 
12-23 12:44:07.931 8180-8180/com.prgguru.example I/Adreno-EGL﹕ : EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_LNX.LA.3.7.2.1_RB1.04.04.04.157.009_msm8916_32_LNX.LA.3.7.2.1_RB1__release_AU () OpenGL ES Shader Compiler Version: E031.24.02.07 Build Date: 07/30/14 Wed Local Branch: mybranch3995205 Remote Branch: quic/LNX.LA.3.7.2.1_rb1 Local Patches: NONE Reconstruct Branch: AU_LINUX_ANDROID_LNX.LA.3.7.2.1_RB1.04.04.04.157.009 + NOTHING 
12-23 12:44:07.951 8180-8180/com.prgguru.example D/OpenGLRenderer﹕ Enabling debug mode 0 
12-23 12:44:08.011 8180-8180/com.prgguru.example I/Timeline﹕ Timeline: Activity_idle id: android.os.BinderProxy@41d32720 time:84097175 
12-23 12:44:14.891 8180-8180/com.prgguru.example V/AudioManager﹕ playSoundEffect effectType: 0 
12-23 12:44:14.891 8180-8180/com.prgguru.example V/AudioManager﹕ querySoundEffectsEnabled... 
12-23 12:44:14.891 8180-8180/com.prgguru.example D/StubController﹕ holdAndGetPermissionType permissionType:1024 uid:10095 pid:8180 
12-23 12:44:14.891 8180-8180/com.prgguru.example D/StubController﹕ addRequestCount, mRequestCount =1 mPhoneIDRequestCount: 0 mLocationRequestCount: 0 permissionType is: 1024 
12-23 12:44:14.891 8180-8180/com.prgguru.example D/StubController﹕ holdForGetPermissionSelection mRequestCount:1 
12-23 12:44:14.901 8180-8180/com.prgguru.example D/StubController﹕ beforeShowDialogCheckResult:1 
12-23 12:44:14.901 8180-8180/com.prgguru.example D/StubController﹕ minusRequestCount, mRequestCount =0 mPhoneIDRequestCount: 0 mLocationRequestCount: 0 permissionType is: 1024 
12-23  12:44:20.441 8180-8180/com.prgguru.example I/Timeline﹕ Timeline: Activity_idle id: android.os.BinderProxy@41d32720 time:84109606 
12-23 12:44:23.131 8180-8180/com.prgguru.example I/Timeline﹕ Timeline: Activity_idle id: android.os.BinderProxy@41d32720 time:84112293

我的XML,这是我的xml文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<ImageView
    android:id="@+id/imgView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1" >
</ImageView>

<Button
    android:id="@+id/buttonLoadPicture"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_weight="0"
    android:onClick="loadImagefromGallery"
    android:text="Load Picture" >
</Button>

阿米特·蒂瓦里(Amit Tiwari)

此代码适用于使用相机捕获图像,然后将其存储。如果要将图像存储到特定位置,则可以进行适当的更改。

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            if (requestCode == REQUEST_CAMERA) {
                Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                assert thumbnail != null;
                thumbnail.compress(Bitmap.CompressFormat.PNG, 100, stream);

                File destination = new File(Environment.getExternalStorageDirectory(),
                        System.currentTimeMillis() + ".png");

                FileOutputStream fo;
                try {
                    destination.createNewFile();
                    fo = new FileOutputStream(destination);
                    fo.write(stream.toByteArray());
                    fo.close();
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Android:我无法在GridView中显示手机的图像

来自分类Dev

如何在android studio中截取屏幕截图或将我的片段应用程序保存为图像

来自分类Dev

在扫描捕获图像和检索 ocr 数据时,无法在 android studio 中 reslove 符号 <manifest>"@xml/filepaths" </manifest>?

来自分类Dev

我无法在数据库中显示保存的图像

来自分类Dev

无法保存裁剪的图像-Android

来自分类Dev

无法从 android studio 中的链接加载图像

来自分类Dev

Android 5.0中的屏幕捕获和共享

来自分类Dev

我无法让Mediaplayer在Android Studio中工作

来自分类Dev

无法运行我的Android应用。Android Studio显示为DEAD

来自分类Dev

在Pygame中无法在屏幕上移动图像

来自分类Dev

Android无法显示我从自定义相机应用程序保存的图像

来自分类Dev

Android Sharedpreferences无法保存

来自分类Dev

Android无法显示ProgressDialog

来自分类Dev

Android:无法显示吐司

来自分类Dev

Android View无法显示

来自分类Dev

Android View无法显示

来自分类Dev

无法启动Android Studio

来自分类Dev

无法启动Android Studio

来自分类Dev

Android Studio无法启动

来自分类Dev

无法启动Android Studio

来自分类Dev

android:issue在gridview中显示捕获的图像

来自分类Dev

我无法在屏幕上找到导航抽屉:android

来自分类Dev

我无法在屏幕上找到导航抽屉:android

来自分类Dev

无法在Android Webview上运行显示图像预览?

来自分类Dev

Android:获取我无法捕获的IllegalStateException

来自分类Dev

我无法在android的viewholder图像中设置图像

来自分类Dev

无法在Android上运行的Kivy应用中截取屏幕截图

来自分类Dev

无法在Android上运行的Kivy应用中截取屏幕截图

来自分类Dev

Android studio 3.4 无法保存我的配色方案,

Related 相关文章

热门标签

归档