Android實(shí)現(xiàn)的截屏小程序示例
本文實(shí)例講述了Android實(shí)現(xiàn)的截屏小程序。分享給大家供大家參考,具體如下:
先看截圖,不過(guò)這個(gè)截屏還不夠完整,頭上的statusbar沒(méi)有,呈黑色。
多按了幾次,就成這樣了,呵呵。
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>
更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android圖形與圖像處理技巧總結(jié)》、《Android開(kāi)發(fā)入門(mén)與進(jìn)階教程》、《Android調(diào)試技巧與常見(jiàn)問(wèn)題解決方法匯總》、《Android多媒體操作技巧匯總(音頻,視頻,錄音等)》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)》
希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。
相關(guān)文章
Android自定義View之簡(jiǎn)約風(fēng)歌詞控件實(shí)戰(zhàn)指南
一些接觸Android不久的朋友對(duì)自定義View都有一絲畏懼感,總感覺(jué)這是一個(gè)比較高級(jí)的技術(shù),但其實(shí)自定義View并不復(fù)雜,有時(shí)候只需要簡(jiǎn)單幾行代碼就可以完成了,這篇文章主要給大家介紹了關(guān)于Android自定義View之簡(jiǎn)約風(fēng)歌詞控件的相關(guān)資料,需要的朋友可以參考下2021-07-07WheelView實(shí)現(xiàn)上下滑動(dòng)選擇器
這篇文章主要為大家詳細(xì)介紹了WheelView實(shí)現(xiàn)上下滑動(dòng)選擇器的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-12-12Android 使用SharePerference判斷是否為第一次登陸的實(shí)現(xiàn)代碼
很多app中在第一次安裝登陸時(shí)會(huì)有引導(dǎo)歡迎界面,第二次打開(kāi)時(shí)就不再顯示引導(dǎo)頁(yè)面。這個(gè)怎么實(shí)現(xiàn)呢?下面小編給大家介紹下使用SharePerference判斷是否為第一次登陸的實(shí)現(xiàn)代碼,需要的的朋友參考下吧2017-03-03Android 偷拍功能實(shí)現(xiàn)(手機(jī)關(guān)閉依然拍照)詳解及實(shí)例代碼
這篇文章主要介紹了 Android 偷拍功能實(shí)現(xiàn)(手機(jī)關(guān)閉依然拍照)詳解及實(shí)例代碼的相關(guān)資料,這對(duì)Android相機(jī)在不開(kāi)手機(jī)的情況下還能繼續(xù)拍照,附有實(shí)例Demo,需要的朋友可以參考下2016-12-12Android編程實(shí)現(xiàn)將壓縮數(shù)據(jù)庫(kù)文件拷貝到安裝目錄的方法
這篇文章主要介紹了Android編程實(shí)現(xiàn)將壓縮數(shù)據(jù)庫(kù)文件拷貝到安裝目錄的方法,涉及Android處理壓縮文件的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-10-10android實(shí)現(xiàn)raw文件夾導(dǎo)入數(shù)據(jù)庫(kù)代碼
這篇文章主要介紹了android實(shí)現(xiàn)raw文件夾導(dǎo)入數(shù)據(jù)庫(kù)代碼,有需要的朋友可以參考一下2013-12-12Android實(shí)現(xiàn)歌曲播放時(shí)歌詞同步顯示具體思路
歌曲播放時(shí)歌詞同步顯示,我們需要讀取以上歌詞文件的每一行轉(zhuǎn)換成成一個(gè)個(gè)歌詞實(shí)體,可根據(jù)當(dāng)前播放器的播放進(jìn)度與每句歌詞的開(kāi)始時(shí)間,得到當(dāng)前屏幕中央高亮顯示的那句歌詞2013-06-06