Android implementation of the Screenshot applet sample _android

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.