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ā)入門與進(jìn)階教程》、《Android調(diào)試技巧與常見問題解決方法匯總》、《Android多媒體操作技巧匯總(音頻,視頻,錄音等)》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)》
希望本文所述對大家Android程序設(shè)計有所幫助。
相關(guān)文章
Android自定義View實現(xiàn)字母導(dǎo)航欄的代碼
這篇文章主要介紹了Android自定義View實現(xiàn)字母導(dǎo)航欄的實例代碼,代碼簡單易懂,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2016-09-09
flutter優(yōu)雅實現(xiàn)掃碼槍獲取數(shù)據(jù)源示例詳解
這篇文章主要為大家介紹了flutter優(yōu)雅實現(xiàn)掃碼槍獲取數(shù)據(jù)源示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-01-01
Android實現(xiàn)調(diào)用攝像頭拍照并存儲照片
本文主要介紹了如何利用Android調(diào)用攝像頭拍照,并顯示拍照后的圖片到ImageView中,文中的示例代碼講解詳細(xì),感興趣的可以動手試一試2022-01-01
Android Flutter自適應(yīng)瀑布流案例詳解
這篇文章主要介紹了Android Flutter自適應(yīng)瀑布流案例詳解,本篇文章通過簡要的案例,講解了該項技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-09-09
Android自定義ViewGroup實現(xiàn)九宮格布局
這篇文章主要為大家詳細(xì)介紹了Android如何通過自定義ViewGroup實現(xiàn)九宮格布局,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以了解一下2022-12-12
Android中關(guān)于CoordinatorLayout的一些實用布局技巧
大家都知道CoordinatorLayout是一個“加強(qiáng)版”的 FrameLayout,那么下面這篇文章主要給大家分享了Android中關(guān)于CoordinatorLayout的一些布局技巧,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面來一起看看吧。2017-06-06
Android仿QQ微信實時監(jiān)測網(wǎng)絡(luò)狀態(tài)
這篇文章主要為大家詳細(xì)介紹了Android仿QQ微信實時監(jiān)測網(wǎng)絡(luò)狀態(tài),具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-05-05
詳解xamarin Android 實現(xiàn)ListView萬能適配器
這篇文章主要介紹了詳解xamarin Android 實現(xiàn)ListView萬能適配器的相關(guān)資料,這里主要實現(xiàn)listview 適配器的實例,需要的朋友可以參考下2017-08-08

