Learn Android<bitmap graphics components from scratch. 47 .>

Source: Internet
Author: User

Android.graphics.Bitmap (bitmap) is an action class specifically provided in the Android phone for manipulating picture resources, using this class to read image resources directly from a resource file, and to make some simple modifications to the images.
Common methods
1 public static Bitmap CreateBitmap (Bitmap src) Ordinary Copy a bitmap
2 public static Bitmap CreateBitmap (Bitmap source, int x, int y, int width, int height, Matrix m, Boolean filter) Ordinary To cut a bitmap
3 Public final int getheight () Ordinary Get the high image
4 Public final int getwidth () Ordinary Get the width of the image
5 public static Bitmap Createscaledbitmap (Bitmap src, int dstwidth, int dstheight, Boolean filter) Ordinary Creates a bitmap of a specified size

The next step is to use a simple example to illustrate
<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android"    xmlns:tools= "http// Schemas.android.com/tools "    android:layout_width=" match_parent "    android:layout_height=" Match_parent "    android:paddingbottom= "@dimen/activity_vertical_margin"    android:paddingleft= "@dimen/activity_ Horizontal_margin "    android:paddingright=" @dimen/activity_horizontal_margin "    android:paddingtop=" @dimen /activity_vertical_margin "    tools:context=". Mainactivity ">    <com.example.bitmap1.myview        android:layout_width=" Wrap_content "        android: layout_height= "Wrap_content" ></com.example.bitmap1.MyView></RelativeLayout>


Main program
Package Com.example.bitmap1;import Android.os.bundle;import Android.app.activity;public class MainActivity extends Activity {    @Override    protected void onCreate (Bundle savedinstancestate) {        super.oncreate ( Savedinstancestate);        Setcontentview (R.layout.activity_main);      }    }

Bitmap defined in the MyView

package              COM.EXAMPLE.BITMAP1; Import Android.content.context;import Android.graphics.bitmap;import Android.graphics.bitmapfactory;import Android.graphics.canvas;import Android.graphics.color;import Android.graphics.paint;import Android.util.attributeset;import Android.view.view;public class MyView extends View {public MyView (context context, AttributeSet attrs) {Super (context, attrs);//TODO auto-generated constructor stub} @Overrideprotected void OnDraw ( Canvas canvas) {//TODO auto-generated method stub//get picture file bitmap bitmap = Bitmapfactory.decoderesource ( Super.getresources (), r.drawable.a4);//Set Background canvas color Canvas.drawcolor (color.white);//Initialize Brush paint paint=new paint ();// Set Edge Feather Paint.setantialias (true);//Draw Picture Canvas.drawbitmap (bitmap, 0, 0,paint);//Set Brush color Paint.setcolor (color.blue);// Set the font size paint.settextsize (20);//Draw Text Canvas.drawtext ("My Avatar", Ten, Bitmap.getheight () +20, paint);}} 


Although a bit ugly, but the drawing is also good, the operation of bitmap there are many, we can refer to the API self-learning, graphics drawing in the game and the app guide more

Next forecast: MediaPlayer self-brought player

Learn Android<bitmap graphics components from scratch. 47 .>

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.