• 无题


    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;
    	}
    }
    
  • 相关阅读:
    stream流
    python笔记:str.contains小坑之 UserWarning To actually get the groups, use str.extract.
    获取excel的行索引值
    Pandas学习(4、数据载入、存储及文件格式
    python中如何压缩和解压缩文件
    保持服务器屏幕可控制状态
    python判断文件和文件夹是否存在、创建文件夹
    PDF处理
    selenium+python配置chrome浏览器的选项
    python实现复制粘贴
  • 原文地址:https://www.cnblogs.com/94007boy/p/3425856.html
Copyright © 2020-2023  润新知