源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

Android实现的截屏小程序示例

  • 时间:2021-08-08 14:03 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Android实现的截屏小程序示例
本文实例讲述了Android实现的截屏小程序。分享给大家供大家参考,具体如下: 先看截图,不过这个截屏还不够完整,头上的statusbar没有,呈黑色。 [img]http://files.jb51.net/file_images/article/201610/20161025102618261.jpg?2016925102650[/img] 多按了几次,就成这样了,呵呵。
package com.test;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Bitmap.Config;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
public class ScreenPrinter extends Activity {
 /** Called when the activity is first created. */
 boolean customTitleSupported;
 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.screen_printer);
 Button btn = (Button)findViewById(R.id.btn);
 btn.setOnClickListener(new Button.OnClickListener(){
  public void onClick(View arg0) {
  ImageView im = (ImageView)findViewById(R.id.img);
  Bitmap bmp = Bitmap.createBitmap(320, 480, Config.ARGB_8888);
  View cv = getWindow().getDecorView();
  cv.draw(new Canvas(bmp));
  im.setScaleType(ScaleType.FIT_XY);
  im.setImageBitmap(bmp);
  }});
 }
}

资源文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent" android:layout_height="fill_parent"
 android:orientation="vertical"
 android:background="@drawable/border">
 <Button android:layout_width="fill_parent"
 android:layout_height="wrap_content" android:id="@+id/btn"
 android:text="截屏"/>
 <LinearLayout android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:layout_weight="1" android:padding="10dip"
 android:background="#ffffdd">
 <ImageView android:id="@+id/img"
 android:layout_width="fill_parent" android:layout_height="fill_parent"/>
 </LinearLayout>
</LinearLayout>

更多关于Android相关内容感兴趣的读者可查看本站专题:《[url=http://www.1sucai.cn/Special/214.htm]Android图形与图像处理技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/410.htm]Android开发入门与进阶教程[/url]》、《[url=http://www.1sucai.cn/Special/508.htm]Android调试技巧与常见问题解决方法汇总[/url]》、《[url=http://www.1sucai.cn/Special/398.htm]Android多媒体操作技巧汇总(音频,视频,录音等)[/url]》、《[url=http://www.1sucai.cn/Special/381.htm]Android基本组件用法总结[/url]》、《[url=http://www.1sucai.cn/Special/375.htm]Android视图View技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/371.htm]Android布局layout技巧总结[/url]》及《[url=http://www.1sucai.cn/Special/124.htm]Android控件用法总结[/url]》 希望本文所述对大家Android程序设计有所帮助。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部