【问题标题】:ImageView Share IntentImageView 分享意图
【发布时间】:2012-03-20 03:21:35
【问题描述】:

您好,我的应用中有一个图库,当您单击缩略图时,它会在图像视图中显示图像。我正在为一个警报对话框设置一个长按监听器,该对话框有 2 个按钮,一个设置为墙纸,一个用于共享。我有共享意图和获取绘图缓存有点工作。它适用于模拟器,但不适用于我的手机。我已经使用了这个网站上的许多示例来实现这一点,但它根本不起作用。它不断强制关闭我手机上的应用程序。任何帮助表示赞赏。

                alertDialog.setButton2("Share",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog,
                                int which) {
                            imgView.setDrawingCacheEnabled(true);
                            Bitmap b = imgView.getDrawingCache();
                            File sdCard = Environment.getExternalStorageDirectory();
                            File file = new File(sdCard, "image.jpg");
                            FileOutputStream fos;
                            try {
                                fos = new FileOutputStream(file);
                                b.compress(CompressFormat.JPEG, 95,fos);
                               } catch (FileNotFoundException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                               }

                            Log.d("Save Example", "Image saved.");

                            Intent intent = new Intent(Intent.ACTION_SEND);
                            intent.setType("image/jpeg");
                            intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/image.jpg"));

                            startActivity(Intent.createChooser(intent, "Share Picture Via..")); 
                        }   

            });

            alertDialog.show();
            return true;

更新:这似乎是一个问题

b.compress(CompressFormat.JPEG, 95, fos);

它一直说空指针。

原来空指针实际上是一个只读错误..所以它实际上并没有写入文件我得到一个 ioexception 只读文件系统。为什么要这样做?

【问题讨论】:

    标签: android android-intent bitmap compression imageview


    【解决方案1】:
    imgView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); imgView.layout(0, 0, imgView.getMeasuredWidth(), imgView.getMeasuredHeight());
    

    在此之前看看这是否有帮助

     Bitmap b = imgView.getDrawingCache();
    

    也看看这是否有帮助 Android drawing cache

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-09-04
      • 2014-03-18
      • 1970-01-01
      • 1970-01-01
      • 2021-11-14
      • 2017-07-01
      • 1970-01-01
      相关资源
      最近更新 更多