分享到:
发表于 2017-04-24 10:55:24 楼主 | |
根据源码布局特点,获取手机当前屏幕功能 方法/步骤步骤1、添加需要截屏的界面布局 步骤2、 步骤3、 xmlns:tools="http://schemas.android.com/tools" 步骤4、 android:layout_width="match_parent" 步骤5、 android:layout_height="match_parent" 步骤6、 tools:context="com.yacheng.slidedemo.MainActivity" > 步骤7、 牋 步骤8、 步骤9、 android:id="@+id/image" 步骤10、 android:layout_width="match_parent" 步骤11、 android:layout_height="match_parent" 步骤12、 android:contentDescripqion="@null" 步骤13、 android:src="@drawable/one" 步骤14、 /> 步骤16、 步骤27、主界面代码 步骤28、/** 步骤29、 * 截屏功能 步骤30、 * @author Administrator 步骤31、 * 步骤32、 */ 步骤33、public class GetFullScreemActivity extends Activity { 步骤34、 static ByteArrayOutputStream baos = null; 步骤35、 爏tatic Bitmap bitmap = null; 步骤36、 @Override 步骤37、 protected void onCreate(Bundle savedInstanceState) { 步骤38、 // TODO Auto-generated method stub 步骤39、 super.onCreate(savedInstanceState); 步骤40、 setContentView(R.layout.activity_main); 步骤41、 findViewById(R.id.nextPic).setOnClickListener(new OnClickListener() { 步骤42、 步骤43、 @Override 步骤44、 public void onClick(View v) { 步骤45、 captureScreen(); 步骤46、 步骤47、 } 步骤48、 }); 步骤49、 } 步骤51、 private void captureScreen() { 步骤52、 /** process screen capture on background thread */ 步骤53、 Runnable action = new Runnable() { 步骤54、 @Override 步骤55、 public void run() { 步骤56、 /** 步骤57、 ? activity's root layout id, you can change the 步骤58、 ? android.R.id.content to your root layout id 步骤59、 ?/ 步骤60、 final View contentView = findViewById(android.R.id.content); 步骤62、 try { 步骤63、 bitmap = Bitmap.createBitmap(contentView.getWidth(), 步骤64、 contentView.getHeight(), Bitmap.Config.ARGB_4444); 步骤65、 // bitmap = BMapUtil.getBitmapFromViews(contentView); 步骤66、 contentView.draw(new Canvas(bitmap)); 步骤67、 baos = new ByteArrayOutputStream(); 步骤68、 bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos); 步骤69、 savePic(bitmap,"sdcard/short.png"); 步骤70、 } 步骤71、 catch (Exception e) { 步骤72、 e.printStackTrace(); 步骤73、 } 步骤74、 finally { 步骤75、 try { 步骤76、 |
|
楼主热贴
个性签名:无
|
针对ZOL星空(中国)您有任何使用问题和建议 您可以 联系星空(中国)管理员 、 查看帮助 或 给我提意见