• 无题


    public class MainActivity extends Activity {
        /** Called when the activity is first created. */
            private static final String TAG ="llsskk";
            private Button btnShort;
            ImageView image = null;
            public static String SCREEN_SHOTS_LOCATION = Environment.getExternalStorageDirectory().getPath();
            private Context mContext=this;
            private int mLCDWidth;
            private int mLCDHeight;
            private static final int PIXEL_BYTES = 4;
            private Bitmap mBitmap=null;
    		private DataOutputStream dos=null;
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            requestWindowFeature(Window.FEATURE_NO_TITLE);
            setContentView(R.layout.activity_main);   
            WindowManager mWm = ((WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE));
            Point DisplaySize = new Point();
            mWm.getDefaultDisplay().getSize(DisplaySize);
    
            mLCDWidth = DisplaySize.x;
            mLCDWidth += 8; // fusion3(SGH-I337), maybe plus 8 pixel.
            mLCDHeight = DisplaySize.y;
            image = (ImageView)findViewById(R.id.image);
            btnShort = (Button) findViewById(R.id.btnShots);
            btnShort.setOnClickListener(new Button.OnClickListener() {
                    private Bitmap bitmao;
    
    				public void onClick(View v) {
                            try {
                            	Log.v(TAG, "click!!");
                            	bitmao = takeScreenShotBySec();
                            	image.setImageBitmap(bitmao);
                            } catch (Exception e) {
                                    // TODO Auto-generated catch block
                                    Log.e("tag",TAG);
                            }
                    }
            });
        }
    	public boolean root() {
    		try {
    			// 执行su变更用户身份为root
    			Process process = Runtime.getRuntime().exec("su");
    			dos = new DataOutputStream(process.getOutputStream());
    		} catch (Exception e) {
    			e.printStackTrace();
    			return false;
    		}
    		return true;
    	}
        protected Bitmap takeScreenShotBySec() {
    		// TODO Auto-generated method stub
        	byte[] bytestream = new byte[mLCDWidth * mLCDHeight * PIXEL_BYTES];    	
    
            InputStream mFIS = null;
            if(root()){    		
        			try {
        				dos.writeBytes("chmod 777 /dev/graphics/fb0
    ");
        				dos.flush();
        			} catch (IOException e) {
        				e.printStackTrace();
        			
        			}  		    		
            }
    
    		try {
    			mFIS = new FileInputStream(new File("/dev/graphics/fb0"));
    			mFIS.read(bytestream);	       
    
            if (mBitmap != null)
                mBitmap.recycle();
            Log.v(TAG, "take!!");
            mBitmap = Bitmap.createBitmap(mLCDWidth, mLCDHeight, Config.ARGB_8888);
            Log.v(TAG, mBitmap.toString());
    
            for (int i = 0; i < bytestream.length; i = i + PIXEL_BYTES) {
                byte tem = bytestream[i];
                bytestream[i] = bytestream[i + 2];
                bytestream[i + 2] = tem;
            }
    
            Buffer buffer = ByteBuffer.wrap(bytestream);
    
            mBitmap.copyPixelsFromBuffer(buffer);
    		
    		} catch (Exception e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    			Log.v(TAG, e.toString());
    		} finally{
    			if(mFIS!=null){
    				try {
    					mFIS.close();
    				} catch (IOException e) {
    					// TODO Auto-generated catch block
    					e.printStackTrace();
    				}
    			}
    		}
    		return mBitmap;
    	}
    }
    
  • 相关阅读:
    android学习十四(android的接收短信)
    C/C++知识要点4——printf函数以及cout的计算顺序
    HDU 5355 Cake(2015多校第六场,搜索 + 剪枝)
    微信错误提示code= -4/微信发送被拒绝
    struts2的validate在使用过程中的一个问题
    28.字符串的排列
    Redis入门经典——The Little Redis Book (翻译)
    POJ 3155 Hard Life(最大密度子图)
    BZOJ 1798 AHOI2009 Seq 维护序列 线段树
    RT-Thread开篇
  • 原文地址:https://www.cnblogs.com/94007boy/p/3425856.html
Copyright © 2020-2023  润新知