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 .>