This article describes the Android implementation of the screen-cutting applet. Share to everyone for your reference, specific as follows:
First look at the screenshot, but the screen is not complete, the head of the StatusBar is not, black.
Many times, it became so, hehe.
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; The public class Screenprinter extends activity {/** called the ' when ' is the ' The activity ' is the ' the '
rted;
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) findvi
Ewbyid (R.ID.IMG);
Bitmap bmp = Bitmap.createbitmap (config.argb_8888);
View CV = GetWindow (). Getdecorview ();
Cv.draw (new Canvas (BMP));
Im.setscaletype (SCALETYPE.FIT_XY);
Im.setimagebitmap (BMP);
}}); }
}
Resource file:
<?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=
"cut screen"/>
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>
For more information on Android-related content readers can view the site: "Android graphics and image processing skills summary", "Android Development introduction and Advanced Course", "Android debugging techniques and common problems solution summary", " Android Multimedia How-to Summary (audio, video, audio, etc), summary of Android Basic components usage, Android View tips Summary, Android layout layout tips and a summary of Android controls usage
I hope this article will help you with the Android program.