欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  技术分享

Android画板功能实现_Android写字板Demo源代码下载

程序员文章站 2021-12-25 10:58:20
...

很久没有分享Android源码App项目了、今天给给大家分享一个使用Android开发写字板功能Dem、简单操作内存中的图像、对图像进行简单的处理、绘制直线、以达到写字板的效果、效果图如下、大家可以先看看

Android画板功能实现_Android写字板Demo源代码下载


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;
        }
    });

}


android 写字板源代码下载链接: android写字板 密码: pdq7