如何在画布中拉伸图像时调整大小?

时间:2015-03-30 11:19:23

标签: android android-canvas

我在画布上显示了一个图像。下面是代码。当用户在各个方向拖动图像时,有没有办法动态拉伸或缩小图像?怎么接近它?

public class MainActivity extends Activity 
{
     @Override
     public void onCreate(Bundle savedInstanceState)
     {
         super.onCreate(savedInstanceState);
         setContentView(new MyView(this));
     }

     public class MyView extends View
     {
         public MyView(Context context) 
         {
              super(context);
         }

         @Override
         protected void onDraw(Canvas canvas) 
         {
            super.onDraw(canvas);
            Bitmap _scratch =  BitmapFactory.decodeResource(getResources(), R.drawable.dog);
            canvas.drawColor(Color.WHITE);
            canvas.drawBitmap(_scratch, 0, 0, null);
        }
     }
}

1 个答案:

答案 0 :(得分:0)