使用一个预装的Intent.Action_Pick通知Android选择一块数据。android.provider.MediaStore.Images.EXTERNAL_CONETENT_URI.
Intent choosePictureIntent=new Intent(Intent.ACTION_PICK,android.provider.Mediastore.Images.Media.EXTERNAL_CONTENT_URI);
触发onActivityResult(int requestCode,int resultCode,Intent intent){
super.onActivityResult(requestCode,resultCode,intent);
if(resultCode==RESULT_OK){
Uri imageFileUri=intent.getData();
}
}
3.2 在位图上绘制位图
Bitmap bmp=BitmapFactory.decodeStream(getContentResolver().openInputStream(imageFileUri),null,bmpFactoryOptions);
Bitmap alteredBitmap=Bitmap.createBitmap(bmp.getWidth(),bmp.getheight(),bmp.getConfig());
绘制:
1.获得画布和Paint对象
Canvas canvas=new Canvas(alteredBitmap);
Paint paint=new Paint();
2.绘制
canvas.drawBitmap(bmp,0,0,paint);
3.3.1 输入矩阵
Matrix matrix=new Matrix();
matrix.setValues(new float[]{
1,0,0,
0,1,0,
0,0,1});
canvas.drawBitmap(bmp,matrix,paint);
3.3.2 Matix类的方法
Mtrix matrix=new Matrix();
matrix.setRotate(15);
canvas.drawBitmap(bmp,matrix,paint);
2.缩放
Matix有用的方法是setscale方法,第一个参数是x轴的缩放比例,第二个参数是y轴的缩放比例
matrix.setScale(1.5f,1);
3.平移
Matrix类中setTranslate方法,平移setTranslate(1.5f,-10);
5.镜像
matrix.setScale(-1,1);
matrix.postTranslate(bmp.getWidth(),0);
绘图设置字体
Typeface serif_italic=Typeface.create(Typeface.SERIF,Typeface.ITALIC);
paint.setTypeface(serif_italic);
Typeface chops=Typeface.createFromAsset(getAssets(),"chopinScript.ttf");
paint.setTypeface(chops);
4.路径上的文本
Paint paint=new Paint();
paint.setColor(Color.Green);
paint.setTextSize(20);
paint.setTypeface(Typeface.DEFAULT);
canvas.drawTextOnPath("Hello this is text on a path",p,0,0,paint);
4.2 手指绘图
4.2.1 触摸事件
SimpleFingerDraw extends Activity implements OnTouchListener{
boolean onTouch(View v,MotionEvent event){
int action=event.getAction();
switch(action){
case MotionEvent.Action_down:
downx=evnent.getX();
downy=event.getY();
}
}
}