使用内置的Gallery应用程序选择图形

使用一个预装的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();

         }

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值