标签:风飞雪未扬 从零开始学android android位图 bitmap
1
|
public static Bitmap createBitmap (Bitmap src)
|
普通
|
复制一个Bitmap
|
2
|
public static Bitmap createBitmap(Bitmap source, int x, int y, int width, int height, Matrix m, boolean filter)
|
普通
|
对一个Bitmap进行剪切
|
3
|
public final int getHeight()
|
普通
|
取得图像的高
|
4
|
public final int getWidth()
|
普通
|
取得图像的宽
|
5
|
public static Bitmap createScaledBitmap(Bitmap src, int dstWidth, int dstHeight, boolean filter)
|
普通
|
创建一个指定大小的Bitmap
|
<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>
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); } }
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 } @Override protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub // 获取图片文件 Bitmap bitmap = BitmapFactory.decodeResource(super.getResources(), R.drawable.a4); // 设置背景画布颜色 canvas.drawColor(Color.WHITE); // 初始化画笔 Paint paint=new Paint(); // 设置边缘羽化 paint.setAntiAlias(true); // 绘制图片 canvas.drawBitmap(bitmap, 0, 0,paint ); // 设置画笔颜色 paint.setColor(Color.BLUE); // 设置字体尺寸 paint.setTextSize(20); // 绘制文字 canvas.drawText("我的头像", 10, bitmap.getHeight()+20, paint); } }
标签:风飞雪未扬 从零开始学android android位图 bitmap
原文地址:http://blog.csdn.net/u013616976/article/details/40116323