当前活动采取截图并保存图像到SD卡中andoid截图、并保存、图像、andoid

2023-09-06 22:48:24 作者:猫腻@

喜在我的应用程序,我想提出在android的应用程序中,我必须采取当前活动的屏幕截图,并保存到SD卡。

有关,我用命名为下载一个菜单按钮,当我点击我想目前的活动保存到SD卡中下载。

现在我的问题是它保存到SD卡,但截图未来half.I要下载的整个屏幕,并保存到sdcard.how下载完整的活动。

任何人都可以请帮我如何解决这个问题。

notify_image

 公共类notify_image延伸活动{



        ImageView的ImageView的;

        活动AV = notify_image.this;
        位图B:
        字符串strFileName;

        / **第一次创建活动时调用。 * /
        @覆盖
        公共无效的onCreate(包savedInstanceState){
            super.onCreate(savedInstanceState);
            的setContentView(R.layout.notify_image);


            ImageView的=(ImageView的)findViewById(R.id.iv_imageview);
            意图= getIntent();

            字符串标题= in.getStringExtra(TAG_TITLE);
            字符串URL = in.getStringExtra(TAG_URL);
            字符串名称= in.getStringExtra(TAG_NAME);
            字符串的地方= in.getStringExtra(TAG_PLACE);
            字符串日期= in.getStringExtra(TAG_DATE);
            最终的字符串URL =网址;
            TextView的stitle =(TextView中)findViewById(R.id.tv_title);
            TextView的SNAME =(TextView中)findViewById(R.id.tv_name);
            TextView的splace =(TextView中)findViewById(R.id.tv_place);
            TextView的SDATE =(TextView中)findViewById(R.id.tv_date);

            //显示所选择的产品名称
            stitle.setText(职称);
            sname.setText(名称);
            splace.setText(地方);
            sdate.setText(日期);






            //为AsyncTask的子类中创建一个对象
            GetXMLTask任务=新GetXMLTask();
            //执行任务
            task.execute(新的String [] {URL});
        }


        //创建按钮
        公共布尔onCreateOptionsMenu(功能菜单){
            MenuInflater充气= getMenuInflater();
            inflater.inflate(R.menu.downloads,菜单);
            返回true;
        }

        //在点击功能按钮
        公共布尔onOptionsItemSelected(菜单项项){
            开关(item.getItemId()){
                案例R.id.downloads:
                    / *位图位= takeScreenshot();
                       saveBitmap(位);
                    * /
                    // captureScreen(五);
                    尝试{
                        点阵位图= takeScreenShot(AV); // AV是实例打招呼
                        savePic(位​​图,strFileName);
                        }
                    赶上(例外五){
               的System.out.println(E);
            }

         返回true;

            默认:
                返回super.onOptionsItemSelected(项目);
        }



        }
       私有静态位图takeScreenShot(活动活动){
            查看查看= activity.getWindow()getDecorView()。
            view.setDrawingCacheEnabled(真正的);
            view.buildDrawingCache();
            位图B1 = view.getDrawingCache();
            矩形框=新的矩形();
            。activity.getWindow()getDecorView()getWindowVisibleDisplayFrame(帧)。
            INT statusBarHeight = frame.top;
            INT宽度= activity.getWindowManager()getDefaultDisplay()的getWidth()。
            INT高= activity.getWindowManager()。getDefaultDisplay()
            .getHeight();
            //位图B = Bitmap.createBitmap(B1,0,25,320,455);
            位图B = Bitmap.createBitmap(B1,0,statusBarHeight,宽度,高度
              -  statusBarHeight);
            view.destroyDrawingCache();
            返回b;
                }
        / *公共无效takeScreen(){
            点阵位图= ImageUtils.loadBitmapFromView(这一点,视图); //从视图中得到位图
            字符串的mpath = Environment.getExternalStorageDirectory()+文件分割符+screen_+ System.currentTimeMillis的()+.JPEG;
            文件镜像文件=新的文件(的mpath);
            OutputStream的FOUT = NULL;
            尝试 {
                FOUT =新的FileOutputStream(镜像文件);
                bitmap.com preSS(Bitmap.Com pressFormat.JPEG,90,FOUT);
                fout.flush();
            }赶上(FileNotFoundException异常E){
                e.printStackTrace();
            }赶上(IOException异常E){
                e.printStackTrace();
            } 最后 {
                fout.close();
            }
        } * /
        @燮pressWarnings(未使用)
       私有静态无效savePic(位​​图位图,字符串strFileName){
            //文件strFileName1 =新的文件(Environment.getExternalStorageDirectory()+/screenshottt.png);
            FileOutputStream中FOS = NULL;
            尝试 {
            FOS =新的FileOutputStream(MNT / SD卡/ print.png);
            如果(NULL!= FOS){
            bitmap.com preSS(Bitmap.Com pressFormat.PNG,90,FOS);
            的System.out.println(b为:+位图);
            fos.flush();
            fos.close();
            }
            }赶上(FileNotFoundException异常E){
            e.printStackTrace();
            }赶上(IOException异常E){
            e.printStackTrace();
            }
            }

            公共静态无效的拍摄(活动一,字符串二){
            // savePic(takeScreenShot(a)中,SD卡/ xx.png);
            savePic(takeScreenShot(A),B);
            }
      / *公共位图takeScreenshot(){
               查看rootView = findViewById(android.R.id.content).getRootView();
               rootView.setDrawingCacheEnabled(真正的);
               返回rootView.getDrawingCache();
            } * /
        / *公共位图captureScreen(视图v)
        {
        点阵位图= NULL;

        尝试 {
        如果(V!= NULL)
        {
        INT宽度= v.getWidth();
        INT高= v.getHeight();

        位图的截图= Bitmap.createBitmap(宽度,高度,Bitmap.Config.ARGB_4444);
        v.draw(新的Canvas(截图));
        }
        }赶上(例外五)
        {
        Log.d(captureScreen,失败);
        }

        返回的位图;
        }
        * /
       / *公共位图截图(查看视图){
            点阵位图= Bitmap.createBitmap(view.getWidth()
                    view.getHeight(),Config.ARGB_8888);
            帆布油画=新的Canvas(位);
            view.draw(画布);
            返回的位图;
        } * /
       / *公共无效saveBitmap(位图位图){
            文件的ImagePath =新的文件(Environment.getExternalStorageDirectory()+/screenshot.png);
            FileOutputStream中FOS;
            尝试 {
                FOS =新的FileOutputStream(的ImagePath);
                bitmap.com preSS(比较pressFormat.JPEG,100,FOS);
                fos.flush();
                fos.close();
            }赶上(FileNotFoundException异常E){
                Log.e(GREC,e.getMessage(),E);
            }赶上(IOException异常E){
                Log.e(GREC,e.getMessage(),E);
            }
        } * /

        //图像的URL转换为位图

        私有类GetXMLTask扩展的AsyncTask<字符串,太虚,位图> {
            @覆盖
            受保护的位图doInBackground(字符串...网址){
                位图图= NULL;
                对于(字符串网址:网址){
                    地图= downloadImage(URL);
                }
                返回地图;
            }

            //设置由doInBackground返回的位图
            @覆盖
            保护无效onPostExecute(位图的结果){
                imageView.setImageBitmap(结果);
            }

            //创建位图从InputStream和返回它
            私人位图downloadImage(字符串URL){
                点阵位图= NULL;
                的InputStream流= NULL;
                BitmapFactory.Options bmOptions =新BitmapFactory.Options();
                bmOptions.inSampleSize = 1;

                尝试 {
                    流= getHttpConnection(URL);
                    位= BitmapFactory。
                            德codeStream(流空,bmOptions);
                    stream.close();
                }赶上(IOException异常E1){
                    e1.printStackTrace();
                }
                返回的位图;
            }

            //使HttpURLConnection类,返回的InputStream
            私人的InputStream getHttpConnection(字符串urlString)
                    抛出IOException异常{
                的InputStream流= NULL;
                网址URL =新的URL(urlString);
                URLConnection的连接= url.openConnection();

                尝试 {
                    HttpURLConnection的的HttpConnection =(HttpURLConnection类)连接;
                    httpConnection.setRequestMethod(GET);
                    httpConnection.connect();

                    如果(httpConnection.getResponse code()== HttpURLConnection.HTTP_OK){
                        流= httpConnection.getInputStream();
                    }
                }赶上(例外前){
                    ex.printStackTrace();
                }
                返回流;
            }
        }
    }
 
360云盘中的文件怎么转载到百度云盘中

在此先感谢。

新的更新,code

 公共类notify_image延伸活动{



    ImageView的ImageView的;

    活动AV = notify_image.this;
    位图B:
    字符串strFileName;
    按钮,下载;
    / **第一次创建活动时调用。 * /
    @覆盖
    公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.notify_image);


        ImageView的=(ImageView的)findViewById(R.id.iv_imageview);
        下载=(按钮)findViewById(R.id.button1);
        下载();

        意图= getIntent();

        字符串标题= in.getStringExtra(TAG_TITLE);
        字符串URL = in.getStringExtra(TAG_URL);
        字符串名称= in.getStringExtra(TAG_NAME);
        字符串的地方= in.getStringExtra(TAG_PLACE);
        字符串日期= in.getStringExtra(TAG_DATE);
        最终的字符串URL =网址;
        TextView的stitle =(TextView中)findViewById(R.id.tv_title);
        TextView的SNAME =(TextView中)findViewById(R.id.tv_name);
        TextView的splace =(TextView中)findViewById(R.id.tv_place);
        TextView的SDATE =(TextView中)findViewById(R.id.tv_date);

        //显示所选择的产品名称
        stitle.setText(职称);
        sname.setText(名称);
        splace.setText(地方);
        sdate.setText(日期);






        //为AsyncTask的子类中创建一个对象
        GetXMLTask任务=新GetXMLTask();
        //执行任务
        task.execute(新的String [] {URL});
    }


    //创建按钮
   / *公共布尔onCreateOptionsMenu(功能菜单){
        MenuInflater充气= getMenuInflater();
        inflater.inflate(R.menu.downloads,菜单);
        返回true;
    }
* /
    //在点击功能按钮
   / *公共布尔onOptionsItemSelected(菜单项项){
        开关(item.getItemId()){
            案例R.id.downloads:
                点阵位图= takeScreenshot();
                   saveBitmap(位);

                // captureScreen(五);
                尝试{
                    点阵位图= takeScreenShot(AV); // AV是实例打招呼
                    savePic(位​​图,strFileName);
                    }
                赶上(例外五){
           的System.out.println(E);
        }

     返回true;

        默认:
            返回super.onOptionsItemSelected(项目);
    }



    } * /

   私人无效下载(){
        // TODO自动生成方法存根

            // TODO自动生成方法存根
            / *意图nextScreen =新的意向书(getApplicationContext(),KnowYourLeader.class);
            startActivity(nextScreen); * /
       尝试{
           点阵位图= takeScreenShot(AV); // AV是实例打招呼
           savePic(位​​图,strFileName);
           }
       赶上(例外五){
  的System.out.println(E);
}

        }





私有静态位图takeScreenShot(活动活动){
        查看查看= activity.getWindow()getDecorView()。
        view.setDrawingCacheEnabled(真正的);
        view.buildDrawingCache();
        位图B1 = view.getDrawingCache();
        矩形框=新的矩形();
        。activity.getWindow()getDecorView()getWindowVisibleDisplayFrame(帧)。
        INT statusBarHeight = frame.top;
        INT宽度= activity.getWindowManager()getDefaultDisplay()的getWidth()。
        INT高= activity.getWindowManager()。getDefaultDisplay()
        .getHeight();
        //位图B = Bitmap.createBitmap(B1,0,25,320,455);
        位图B = Bitmap.createBitmap(B1,0,statusBarHeight,宽度,高度
          -  statusBarHeight);
        view.destroyDrawingCache();
        返回b;
            }
    / *公共无效takeScreen(){
        点阵位图= ImageUtils.loadBitmapFromView(这一点,视图); //从视图中得到位图
        字符串的mpath = Environment.getExternalStorageDirectory()+文件分割符+screen_+ System.currentTimeMillis的()+.JPEG;
        文件镜像文件=新的文件(的mpath);
        OutputStream的FOUT = NULL;
        尝试 {
            FOUT =新的FileOutputStream(镜像文件);
            bitmap.com preSS(Bitmap.Com pressFormat.JPEG,90,FOUT);
            fout.flush();
        }赶上(FileNotFoundException异常E){
            e.printStackTrace();
        }赶上(IOException异常E){
            e.printStackTrace();
        } 最后 {
            fout.close();
        }
    } * /
    @燮pressWarnings(未使用)
   私有静态无效savePic(位​​图位图,字符串strFileName){
        //文件strFileName1 =新的文件(Environment.getExternalStorageDirectory()+/screenshottt.png);
        FileOutputStream中FOS = NULL;
        尝试 {
        FOS =新的FileOutputStream(MNT / SD卡/ print.png);
        如果(NULL!= FOS){
        bitmap.com preSS(Bitmap.Com pressFormat.PNG,90,FOS);
        的System.out.println(b为:+位图);
        fos.flush();
        fos.close();
        }
        }赶上(FileNotFoundException异常E){
        e.printStackTrace();
        }赶上(IOException异常E){
        e.printStackTrace();
        }
        }

        公共静态无效的拍摄(活动一,字符串二){
        // savePic(takeScreenShot(a)中,SD卡/ xx.png);
        savePic(takeScreenShot(A),B);
        }
  / *公共位图takeScreenshot(){
           查看rootView = findViewById(android.R.id.content).getRootView();
           rootView.setDrawingCacheEnabled(真正的);
           返回rootView.getDrawingCache();
        } * /
    / *公共位图captureScreen(视图v)
    {
    点阵位图= NULL;

    尝试 {
    如果(V!= NULL)
    {
    INT宽度= v.getWidth();
    INT高= v.getHeight();

    位图的截图= Bitmap.createBitmap(宽度,高度,Bitmap.Config.ARGB_4444);
    v.draw(新的Canvas(截图));
    }
    }赶上(例外五)
    {
    Log.d(captureScreen,失败);
    }

    返回的位图;
    }
    * /
   / *公共位图截图(查看视图){
        点阵位图= Bitmap.createBitmap(view.getWidth()
                view.getHeight(),Config.ARGB_8888);
        帆布油画=新的Canvas(位);
        view.draw(画布);
        返回的位图;
    } * /
   / *公共无效saveBitmap(位图位图){
        文件的ImagePath =新的文件(Environment.getExternalStorageDirectory()+/screenshot.png);
        FileOutputStream中FOS;
        尝试 {
            FOS =新的FileOutputStream(的ImagePath);
            bitmap.com preSS(比较pressFormat.JPEG,100,FOS);
            fos.flush();
            fos.close();
        }赶上(FileNotFoundException异常E){
            Log.e(GREC,e.getMessage(),E);
        }赶上(IOException异常E){
            Log.e(GREC,e.getMessage(),E);
        }
    } * /

    //图像的URL转换为位图

    私有类GetXMLTask扩展的AsyncTask<字符串,太虚,位图> {
        @覆盖
        受保护的位图doInBackground(字符串...网址){
            位图图= NULL;
            对于(字符串网址:网址){
                地图= downloadImage(URL);
            }
            返回地图;
        }

        //设置由doInBackground返回的位图
        @覆盖
        保护无效onPostExecute(位图的结果){
            imageView.setImageBitmap(结果);
        }

        //创建位图从InputStream和返回它
        私人位图downloadImage(字符串URL){
            点阵位图= NULL;
            的InputStream流= NULL;
            BitmapFactory.Options bmOptions =新BitmapFactory.Options();
            bmOptions.inSampleSize = 1;

            尝试 {
                流= getHttpConnection(URL);
                位= BitmapFactory。
                        德codeStream(流空,bmOptions);
                stream.close();
            }赶上(IOException异常E1){
                e1.printStackTrace();
            }
            返回的位图;
        }

        //使HttpURLConnection类,返回的InputStream
        私人的InputStream getHttpConnection(字符串urlString)
                抛出IOException异常{
            的InputStream流= NULL;
            网址URL =新的URL(urlString);
            URLConnection的连接= url.openConnection();

            尝试 {
                HttpURLConnection的的HttpConnection =(HttpURLConnection类)连接;
                httpConnection.setRequestMethod(GET);
                httpConnection.connect();

                如果(httpConnection.getResponse code()== HttpURLConnection.HTTP_OK){
                    流= httpConnection.getInputStream();
                }
            }赶上(例外前){
                ex.printStackTrace();
            }
            返回流;
        }
    }
}
 

解决方案

试用低于code捕捉整个屏幕,并保存为位图:

 视图V = view.getRootView();
v.setDrawingCacheEnabled(真正的);
位图B = v.getDrawingCache();
。字符串抽= Environment.getExternalStorageDirectory()的toString();
文件mypath中=新的文件(抽,print.jpg);
FileOutputStream中FOS = NULL;
尝试 {
    FOS =新的FileOutputStream(mypath中);
    b.com preSS(Bitmap.Com pressFormat.JPEG,100,FOS);
    fos.flush();
    fos.close();
    MediaStore.Images.Media.insertImage(getContentResolver(),B,
                                         屏幕,屏幕);
}赶上(FileNotFoundException异常E){
    // TODO自动生成的catch块
    e.printStackTrace();
}赶上(例外五){
    // TODO自动生成的catch块
    e.printStackTrace();
}
 

希望这会帮助你。

Hi In my application I am making an application in android in which I have to take screenshot of current activity and save it into sdcard.

For that i used one menu button named as download if i click the download i want to save the current activity into sdcard.

Now My problem is it's saving into sdcard but screenshot coming half.I want to download the whole screen and save it into sdcard.how to download the full activity.

Can anyone please help me how to solve this problem.

notify_image

public class notify_image extends Activity {



        ImageView imageView;

        Activity av=notify_image.this;
        Bitmap b;
        String strFileName;

        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.notify_image);


            imageView = (ImageView) findViewById(R.id.iv_imageview);
            Intent in = getIntent();

            String title = in.getStringExtra("TAG_TITLE");
            String url = in.getStringExtra("TAG_URL");
            String name = in.getStringExtra("TAG_NAME");
            String place = in.getStringExtra("TAG_PLACE");
            String date = in.getStringExtra("TAG_DATE");
            final String URL =url;
            TextView stitle = (TextView) findViewById(R.id.tv_title);
            TextView sname = (TextView) findViewById(R.id.tv_name);
            TextView splace = (TextView) findViewById(R.id.tv_place);
            TextView sdate = (TextView) findViewById(R.id.tv_date);  

            // displaying selected product name
            stitle.setText(title);
            sname.setText(name);
            splace.setText(place);
            sdate.setText(date);






            // Create an object for subclass of AsyncTask
            GetXMLTask task = new GetXMLTask();
            // Execute the task
            task.execute(new String[] { URL });
        }


        //creating button
        public boolean onCreateOptionsMenu(Menu menu) {
            MenuInflater inflater = getMenuInflater();
            inflater.inflate(R.menu.downloads, menu);
            return true;
        }

        //button on click function
        public boolean onOptionsItemSelected(MenuItem item) {    
            switch (item.getItemId()) {    
                case R.id.downloads:
                    /*Bitmap bitmap = takeScreenshot();
                       saveBitmap(bitmap);
                    */
                    //captureScreen(v); 
                    try{
                        Bitmap bitmap = takeScreenShot(av); // av is instance of hello
                        savePic(bitmap, strFileName);
                        }
                    catch (Exception e) {
               System.out.println(e);
            }

         return true;

            default:
                return super.onOptionsItemSelected(item);
        }



        }
       private static Bitmap takeScreenShot(Activity activity) {
            View view = activity.getWindow().getDecorView();
            view.setDrawingCacheEnabled(true);
            view.buildDrawingCache();
            Bitmap b1 = view.getDrawingCache();
            Rect frame = new Rect();
            activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
            int statusBarHeight = frame.top;
            int width = activity.getWindowManager().getDefaultDisplay().getWidth();
            int height = activity.getWindowManager().getDefaultDisplay()
            .getHeight();
            // Bitmap b = Bitmap.createBitmap(b1, 0, 25, 320, 455);
            Bitmap b = Bitmap.createBitmap(b1, 0, statusBarHeight, width, height
             - statusBarHeight);
            view.destroyDrawingCache();
            return b;
                }
        /*public void takeScreen() {
            Bitmap bitmap = ImageUtils.loadBitmapFromView(this, view); //get Bitmap from the view
            String mPath = Environment.getExternalStorageDirectory() + File.separator + "screen_" + System.currentTimeMillis() + ".jpeg";
            File imageFile = new File(mPath);
            OutputStream fout = null;
            try {
                fout = new FileOutputStream(imageFile);
                bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fout);
                fout.flush();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                fout.close();
            }
        }*/
        @SuppressWarnings("unused")
       private static void savePic(Bitmap bitmap, String strFileName) {
            //File strFileName1 = new File(Environment.getExternalStorageDirectory() + "/screenshottt.png");
            FileOutputStream fos = null;
            try {
            fos = new FileOutputStream("mnt/sdcard/print.png");
            if (null != fos) {
            bitmap.compress(Bitmap.CompressFormat.PNG, 90, fos);
            System.out.println("b is:"+bitmap);
            fos.flush();
            fos.close();
            }
            } catch (FileNotFoundException e) {
            e.printStackTrace();
            } catch (IOException e) {
            e.printStackTrace();
            }
            }

            public static void shoot(Activity a,String b) {
            //savePic(takeScreenShot(a), "sdcard/xx.png");
            savePic(takeScreenShot(a), b);
            }
      /*public Bitmap takeScreenshot() {
               View rootView = findViewById(android.R.id.content).getRootView();
               rootView.setDrawingCacheEnabled(true);
               return rootView.getDrawingCache();
            }*/
        /*public Bitmap captureScreen(View v)
        {
        Bitmap bitmap = null;

        try {
        if(v!=null)
        {
        int width = v.getWidth();
        int height = v.getHeight();

        Bitmap screenshot = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444);
        v.draw(new Canvas(screenshot));
        }
        } catch (Exception e)
        {
        Log.d("captureScreen", "Failed");
        }

        return bitmap;
        }
        */
       /* public Bitmap screenShot(View view) {
            Bitmap bitmap = Bitmap.createBitmap(view.getWidth(),
                    view.getHeight(), Config.ARGB_8888);
            Canvas canvas = new Canvas(bitmap);
            view.draw(canvas);
            return bitmap;
        }*/
       /* public void saveBitmap(Bitmap bitmap) {
            File imagePath = new File(Environment.getExternalStorageDirectory() + "/screenshot.png");
            FileOutputStream fos;
            try {
                fos = new FileOutputStream(imagePath);
                bitmap.compress(CompressFormat.JPEG, 100, fos);
                fos.flush();
                fos.close();
            } catch (FileNotFoundException e) {
                Log.e("GREC", e.getMessage(), e);
            } catch (IOException e) {
                Log.e("GREC", e.getMessage(), e);
            }
        }*/

        //image url convert to bitmap

        private class GetXMLTask extends AsyncTask<String, Void, Bitmap> {
            @Override
            protected Bitmap doInBackground(String... urls) {
                Bitmap map = null;
                for (String url : urls) {
                    map = downloadImage(url);
                }
                return map;
            }

            // Sets the Bitmap returned by doInBackground
            @Override
            protected void onPostExecute(Bitmap result) {
                imageView.setImageBitmap(result);
            }

            // Creates Bitmap from InputStream and returns it
            private Bitmap downloadImage(String url) {
                Bitmap bitmap = null;
                InputStream stream = null;
                BitmapFactory.Options bmOptions = new BitmapFactory.Options();
                bmOptions.inSampleSize = 1;

                try {
                    stream = getHttpConnection(url);
                    bitmap = BitmapFactory.
                            decodeStream(stream, null, bmOptions);
                    stream.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
                return bitmap;
            }

            // Makes HttpURLConnection and returns InputStream
            private InputStream getHttpConnection(String urlString)
                    throws IOException {
                InputStream stream = null;
                URL url = new URL(urlString);
                URLConnection connection = url.openConnection();

                try {
                    HttpURLConnection httpConnection = (HttpURLConnection) connection;
                    httpConnection.setRequestMethod("GET");
                    httpConnection.connect();

                    if (httpConnection.getResponseCode() == HttpURLConnection.HTTP_OK) {
                        stream = httpConnection.getInputStream();
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                return stream;
            }
        }
    }

Thanks In Advance.

new updated code

public class notify_image extends Activity {



    ImageView imageView;

    Activity av=notify_image.this;
    Bitmap b;
    String strFileName;
    Button download;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.notify_image);


        imageView = (ImageView) findViewById(R.id.iv_imageview);
        download = (Button) findViewById(R.id.button1);
        download();

        Intent in = getIntent();

        String title = in.getStringExtra("TAG_TITLE");
        String url = in.getStringExtra("TAG_URL");
        String name = in.getStringExtra("TAG_NAME");
        String place = in.getStringExtra("TAG_PLACE");
        String date = in.getStringExtra("TAG_DATE");
        final String URL =url;
        TextView stitle = (TextView) findViewById(R.id.tv_title);
        TextView sname = (TextView) findViewById(R.id.tv_name);
        TextView splace = (TextView) findViewById(R.id.tv_place);
        TextView sdate = (TextView) findViewById(R.id.tv_date);  

        // displaying selected product name
        stitle.setText(title);
        sname.setText(name);
        splace.setText(place);
        sdate.setText(date);






        // Create an object for subclass of AsyncTask
        GetXMLTask task = new GetXMLTask();
        // Execute the task
        task.execute(new String[] { URL });
    }


    //creating button
   /* public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.downloads, menu);
        return true;
    }
*/
    //button on click function
   /* public boolean onOptionsItemSelected(MenuItem item) {    
        switch (item.getItemId()) {    
            case R.id.downloads:
                Bitmap bitmap = takeScreenshot();
                   saveBitmap(bitmap);

                //captureScreen(v); 
                try{
                    Bitmap bitmap = takeScreenShot(av); // av is instance of hello
                    savePic(bitmap, strFileName);
                    }
                catch (Exception e) {
           System.out.println(e);
        }

     return true;

        default:
            return super.onOptionsItemSelected(item);
    }



    }*/

   private void download() {
        // TODO Auto-generated method stub

            // TODO Auto-generated method stub
            /*Intent nextScreen = new Intent(getApplicationContext(), KnowYourLeader.class);
            startActivity(nextScreen);*/
       try{
           Bitmap bitmap = takeScreenShot(av); // av is instance of hello
           savePic(bitmap, strFileName);
           }
       catch (Exception e) {
  System.out.println(e);
}

        }





private static Bitmap takeScreenShot(Activity activity) {
        View view = activity.getWindow().getDecorView();
        view.setDrawingCacheEnabled(true);
        view.buildDrawingCache();
        Bitmap b1 = view.getDrawingCache();
        Rect frame = new Rect();
        activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
        int statusBarHeight = frame.top;
        int width = activity.getWindowManager().getDefaultDisplay().getWidth();
        int height = activity.getWindowManager().getDefaultDisplay()
        .getHeight();
        // Bitmap b = Bitmap.createBitmap(b1, 0, 25, 320, 455);
        Bitmap b = Bitmap.createBitmap(b1, 0, statusBarHeight, width, height
         - statusBarHeight);
        view.destroyDrawingCache();
        return b;
            }
    /*public void takeScreen() {
        Bitmap bitmap = ImageUtils.loadBitmapFromView(this, view); //get Bitmap from the view
        String mPath = Environment.getExternalStorageDirectory() + File.separator + "screen_" + System.currentTimeMillis() + ".jpeg";
        File imageFile = new File(mPath);
        OutputStream fout = null;
        try {
            fout = new FileOutputStream(imageFile);
            bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fout);
            fout.flush();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            fout.close();
        }
    }*/
    @SuppressWarnings("unused")
   private static void savePic(Bitmap bitmap, String strFileName) {
        //File strFileName1 = new File(Environment.getExternalStorageDirectory() + "/screenshottt.png");
        FileOutputStream fos = null;
        try {
        fos = new FileOutputStream("mnt/sdcard/print.png");
        if (null != fos) {
        bitmap.compress(Bitmap.CompressFormat.PNG, 90, fos);
        System.out.println("b is:"+bitmap);
        fos.flush();
        fos.close();
        }
        } catch (FileNotFoundException e) {
        e.printStackTrace();
        } catch (IOException e) {
        e.printStackTrace();
        }
        }

        public static void shoot(Activity a,String b) {
        //savePic(takeScreenShot(a), "sdcard/xx.png");
        savePic(takeScreenShot(a), b);
        }
  /*public Bitmap takeScreenshot() {
           View rootView = findViewById(android.R.id.content).getRootView();
           rootView.setDrawingCacheEnabled(true);
           return rootView.getDrawingCache();
        }*/
    /*public Bitmap captureScreen(View v)
    {
    Bitmap bitmap = null;

    try {
    if(v!=null)
    {
    int width = v.getWidth();
    int height = v.getHeight();

    Bitmap screenshot = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444);
    v.draw(new Canvas(screenshot));
    }
    } catch (Exception e)
    {
    Log.d("captureScreen", "Failed");
    }

    return bitmap;
    }
    */
   /* public Bitmap screenShot(View view) {
        Bitmap bitmap = Bitmap.createBitmap(view.getWidth(),
                view.getHeight(), Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        view.draw(canvas);
        return bitmap;
    }*/
   /* public void saveBitmap(Bitmap bitmap) {
        File imagePath = new File(Environment.getExternalStorageDirectory() + "/screenshot.png");
        FileOutputStream fos;
        try {
            fos = new FileOutputStream(imagePath);
            bitmap.compress(CompressFormat.JPEG, 100, fos);
            fos.flush();
            fos.close();
        } catch (FileNotFoundException e) {
            Log.e("GREC", e.getMessage(), e);
        } catch (IOException e) {
            Log.e("GREC", e.getMessage(), e);
        }
    }*/

    //image url convert to bitmap

    private class GetXMLTask extends AsyncTask<String, Void, Bitmap> {
        @Override
        protected Bitmap doInBackground(String... urls) {
            Bitmap map = null;
            for (String url : urls) {
                map = downloadImage(url);
            }
            return map;
        }

        // Sets the Bitmap returned by doInBackground
        @Override
        protected void onPostExecute(Bitmap result) {
            imageView.setImageBitmap(result);
        }

        // Creates Bitmap from InputStream and returns it
        private Bitmap downloadImage(String url) {
            Bitmap bitmap = null;
            InputStream stream = null;
            BitmapFactory.Options bmOptions = new BitmapFactory.Options();
            bmOptions.inSampleSize = 1;

            try {
                stream = getHttpConnection(url);
                bitmap = BitmapFactory.
                        decodeStream(stream, null, bmOptions);
                stream.close();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            return bitmap;
        }

        // Makes HttpURLConnection and returns InputStream
        private InputStream getHttpConnection(String urlString)
                throws IOException {
            InputStream stream = null;
            URL url = new URL(urlString);
            URLConnection connection = url.openConnection();

            try {
                HttpURLConnection httpConnection = (HttpURLConnection) connection;
                httpConnection.setRequestMethod("GET");
                httpConnection.connect();

                if (httpConnection.getResponseCode() == HttpURLConnection.HTTP_OK) {
                    stream = httpConnection.getInputStream();
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            return stream;
        }
    }
}

解决方案

Try out below code to capture the whole screen and save as bitmap.:

View v = view.getRootView();
v.setDrawingCacheEnabled(true);
Bitmap b = v.getDrawingCache();
String extr = Environment.getExternalStorageDirectory().toString();
File myPath = new File(extr, "print.jpg");
FileOutputStream fos = null;
try {
    fos = new FileOutputStream(myPath);
    b.compress(Bitmap.CompressFormat.JPEG, 100, fos);
    fos.flush();
    fos.close();
    MediaStore.Images.Media.insertImage( getContentResolver(), b, 
                                         "Screen", "screen");
} catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

Hope this will help you.