简体   繁体   中英

Capturing Screenshot Image 'Android'

I am able to take 'screenshot of image' in my app but i need to take screenshot of 'particular part' in that image. Please anyone help me to do that... Thank you... Here is the code I am using to take screenshot of an image....

L1 = (LinearLayout) findViewById(R.id.LinearLayout01);
Button but = (Button) findViewById(R.id.Button01);
but.setOnClickListener(new View.OnClickListener() {

    @Override

    public void onClick(View v) {

        View v1 = L1.getRootView();

        v1.setDrawingCacheEnabled(true);

        Bitmap bm = v1.getDrawingCache();

        BitmapDrawable bitmapDrawable = new BitmapDrawable(bm);
        image = (ImageView) findViewById(R.id.ImageView01);

        image.setBackgroundDrawable(bitmapDrawable);

    }

});

`

after getting the bitmap do this way

Bitmap new_bmp = Bitmap.createBitmap(bm, 0, 0, linear.getWidth(), linear.getHeight(), matrix, false);

            image.draw(new Canvas(new_bmp));
            String s = Environment.getExternalStorageDirectory().toString();

            linear.setBackgroundColor(Color.BLACK);
            OutputStream outStream = null;
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_hhmmss");
            String file_name = sdf.format(new Date())+".PNG";
            File file = new File(s, file_name);
            try {
             outStream = new FileOutputStream(file);
             new_bmp.compress(Bitmap.CompressFormat.PNG, 100, outStream);
             outStream.flush();
             outStream.close();
            } catch (FileNotFoundException e) {
                 e.printStackTrace();
                 Toast.makeText(CaptureImage.this, e.toString(), Toast.LENGTH_LONG).show();
            } catch (IOException e) {
                 e.printStackTrace();
                 Toast.makeText(CaptureImage.this, e.toString(), Toast.LENGTH_LONG).show();
            }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM