Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在android中清除位图?_Android_Email_Bitmap_Screenshot - Fatal编程技术网

如何在android中清除位图?

如何在android中清除位图?,android,email,bitmap,screenshot,Android,Email,Bitmap,Screenshot,您好,我有一个应用程序来截图并发送到电子邮件。当我第二次截图并附加到电子邮件时,电子邮件包含第一个截图。我认为位图没有清除。谁能帮我一下吗。我很抱歉我的英语不好 这是我的密码 email_icon1.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-g

您好,我有一个应用程序来截图并发送到电子邮件。当我第二次截图并附加到电子邮件时,电子邮件包含第一个截图。我认为位图没有清除。谁能帮我一下吗。我很抱歉我的英语不好

这是我的密码

email_icon1.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub

                    Toast.makeText(getApplicationContext(), "email_icon clicked", Toast.LENGTH_SHORT).show();


                     View v1 = getWindow().getDecorView().getRootView();
                        // View v1 = iv.getRootView(); //even this works
                        // View v1 = findViewById(android.R.id.content); //this works too
                        // but gives only content
                     v1.setDrawingCacheEnabled(true);
                        myBitmap = v1.getDrawingCache();

                        saveBitmap(myBitmap);
                }
            });

public void saveBitmap(Bitmap bitmap) {
          String filePath = Environment.getExternalStorageDirectory()
                  + File.separator + "Pictures/screenshot.png";
          File imagePath = new File(filePath);
          FileOutputStream fos;
          try {
              fos = new FileOutputStream(imagePath);
              bitmap.compress(CompressFormat.PNG, 100, fos);
              fos.flush();
              fos.close();
              sendMail(filePath);
          } catch (FileNotFoundException e) {
              Log.e("GREC", e.getMessage(), e);
          } catch (IOException e) {
              Log.e("GREC", e.getMessage(), e);
          }
        }

        public void sendMail(String path) {


          Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
          emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
                  new String[] { "athulya@extraslice.com" });
          emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
                  "giMobile ScreenShot");
          emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,
                  "Sent from my AndroidTab");
          emailIntent.setType("image/png");
          Uri myUri = Uri.parse("file://" + path);
          emailIntent.putExtra(Intent.EXTRA_STREAM, myUri);
          startActivity(Intent.createChooser(emailIntent, "Send mail..."));
        }

提前感谢。

为了让您从视图中重新创建位图,请按照以下顺序操作

    holder.setDrawingCacheEnabled(true);
    Bitmap bmp = holder.getDrawingCache();
保存后,请确保销毁视图缓存,并将其添加到保存方法的末尾,以完全销毁视图缓存,并在每次单击保存方法或正在使用的任何方法时重新开始重新绘制视图

holder.setDrawingCacheEnabled(false);

得到位图后,请执行此操作

v1.setDrawingCacheEnabledtrue;myBitmap=v1.getDrawingCache; v1.setDrawingCacheEnabledfalse;saveBitmapmyBitmap


使用以下代码清除位图数据。。bitmap.recycle,bitmap=nullI已尝试,但它会导致空指针异常。一旦位图保存到文件中。你说的对吗?。你能用位图更新你的代码吗?