捕捉截图图片'Android'

时间:2011-12-14 13:28:39

标签: android image screenshot

我可以在我的应用中拍摄“图片截图”,但我需要在该图片中截取“特定部分”的屏幕截图。请有人帮我这样做......谢谢...... 这是我用来截取图像截图的代码....

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);

    }

});

`

1 个答案:

答案 0 :(得分:0)

获取位图后这样做

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();
            }