欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android實現(xiàn)畫板、寫字板功能(附源碼下載)

 更新時間:2017年01月24日 14:14:16   投稿:daisy  
這篇文章主要介紹了Android實現(xiàn)畫板、寫字板功能的方法,文中給出了簡單的介紹和示例代碼,想要了解更多的朋友可以下載源碼進(jìn)行學(xué)習(xí),感興趣的朋友們下面來一起看看吧。

前言

本文給大家分享一個使用Android開發(fā)寫字板功能Dem、簡單操作內(nèi)存中的圖像、對圖像進(jìn)行簡單的處理、繪制直線、以達(dá)到寫字板的效果

效果圖如下

XML布局代碼

<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="com.tomes.paint.MainActivity" >

 <ImageView 
  android:id="@ id/iv_drawingBoard"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:src="@drawable/bg"/>

</RelativeLayout>

Java代碼

public void init() {
 Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
   R.drawable.bg);
 copyBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
 paint = new Paint();
 canvas = new Canvas(copyBitmap);
 Matrix matrix=new Matrix();
 canvas.drawBitmap(bitmap, matrix, paint);

 imageView = (ImageView) findViewById(R.id.iv_drawingBoard);

 imageView.setImageBitmap(copyBitmap);
 
 imageView.setOnTouchListener(new OnTouchListener() {

  @SuppressLint("ClickableViewAccessibility")
  @Override
  public boolean onTouch(View v, MotionEvent event) {
   int action = event.getAction();
   switch (action) {
   case MotionEvent.ACTION_DOWN:
     startX=event.getX();
     startY=event.getY();
    break;
   case MotionEvent.ACTION_MOVE:
    float currentX=event.getX();
    float currentY=event.getY();
    canvas.drawLine(startX, startY, currentX, currentY, paint);
    imageView.setImageBitmap(copyBitmap);
    startX=currentX;
    startY=currentY;
    
    break;
   case MotionEvent.ACTION_UP:

    break;

   }
   return true;
  }
 });

}

源碼下載:點(diǎn)擊這里

總結(jié)

以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對各位Android開發(fā)者們能帶來一定的幫助,如果有疑問大家可以留言交流。

相關(guān)文章

最新評論