我可以: 邀请好友来看>>
ZOL星空(中国) > 兴趣圈子星空(中国) > 神通哥有问必答星空(中国) > Android截屏代码经验
帖子很冷清,卤煮很失落!求安慰
返回列表
签到
手机签到经验翻倍!
快来扫一扫!

Android截屏代码经验

14浏览 / 0回复

i4si6py4d

i4si6py4d

0
精华
51
帖子

等  级:Lv.1
经  验:0
  • Z金豆: 0

    千万礼品等你来兑哦~快点击这里兑换吧~

  • 城  市:
  • 注  册:2015-12-15
  • 登  录:2018-09-13
发表于 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、 

    步骤17、  android:id="@+id/nextPic"

    步骤18、  android:layout_width="wrap_content"

    步骤19、  android:layout_height="wrap_content"

    步骤20、  android:layout_alignParentBottom="true"

    步骤21、  android:layout_alignParentRight="true"

    步骤22、  android:layout_margin="10dp"

    步骤23、  android:background="@color/abc_search_url_text_normal"

    步骤24、  android:text="截屏" />

    步骤26、

    步骤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、 

高级模式
星空(中国)精选大家都在看24小时热帖7天热帖大家都在问最新回答

针对ZOL星空(中国)您有任何使用问题和建议 您可以 联系星空(中国)管理员查看帮助  或  给我提意见

快捷回复 APP下载 返回列表