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