import java.io.File;import java.io.FileNotFoundException;import java.io.FileOutputStream;import android.net.Uri;import android.os.Bundle;import android.os.Environment;import android.app.Activity;import android.content.Intent;import android.graphics.Bitmap;import android.graphics.Bitmap.CompressFormat;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.graphics.SweepGradient;import android.view.Menu;import android.view.MotionEvent;import android.view.View;import android.view.View.OnTouchListener;import android.widget.ImageView;import android.widget.Toast;public class MainActivity extends Activity {private ImageView iv;private Bitmap baseBitmap;private Canvas canvas;private Paint paint;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);iv = (ImageView) findViewById(R.id.iv);paint = new Paint();paint.setStrokeWidth(5);paint.setColor(Color.GREEN);// 创建一个可以被修改的bitmapbaseBitmap = Bitmap.createBitmap(, ,Bitmap.Config.ARGB_);System.out.println("图宽度:"iv.getWidth());System.out.println("图宽高:"iv.getHeight());canvas = new Canvas(baseBitmap);canvas.drawColor(Color.WHITE);// 知道用户手指在屏幕上移动的轨迹iv.setOnTouchListener(new OnTouchListener() {//定义手指开始位置的坐标int startX;int startY;@Overridepublic boolean onTouch(View v, MotionEvent event) {switch (event.getAction()) {case MotionEvent.ACTION_DOWN: // 手指第一次接触屏幕System.out.println("手指按下");startX = (int) event.getX();startY = (int) event.getY();break;case MotionEvent.ACTION_MOVE: // 手指在屏幕上滑动System.out.println("手指移动");int newX = (int) event.getX();int newY = (int) event.getY();canvas.drawLine(startX,startY, newX, newY, paint);//重新更新画笔的开始位置.startX = (int) event.getX();startY = (int) event.getY();iv.setImageBitmap(baseBitmap);break;case MotionEvent. 手指离开屏幕break;}return true;}});}public void save(View view) {try {File file = new File(Environment.getExternalStorageDirectory(),System.currentTimeMillis()".jpg");FileOutputStream stream = new FileOutputStream(file);baseBitmap.compress(CompressFormat.JPEG, , stream);stream.close();Toast.makeText(this, "保存图片成功", 1).show();//模拟一个消息 通知系统sd卡被重新挂载了.Intent intent = new Intent();intent.setAction(Intent.ACTION_MEDIA_MOUNTED);intent.setData(Uri.fromFile(Environment.getExternalStorageDirectory()));sendBroadcast(intent);} catch (Exception e) {Toast.makeText(this, "保存图片失败", 1).show();e.printStackTrace();}}
推荐整理分享android 画画板(安卓画图板),希望有所帮助,仅作参考,欢迎阅读内容。
文章相关热门搜索词:安卓画板app,安卓画图板,安卓画图板,android 画画app,安卓画画板,安卓画板app,安卓画板app,安卓画板app,内容如对您有帮助,希望把文章链接给更多的朋友!
}
整理自 ppt和源码
Android Studio 1.1.0 配置androidannotations框架 环境:AndroidStudio1.1.0、JDK8、Win7-x大致分为五步吧进入build.gradle(Project:**)里添加classpath‘com.neenbedankt.gradle.plugins:android-apt:1.4’,位置如下图:进入build.g
把android 中图片局部区域改为透明 importandroid.app.Activity;importandroid.graphics.Bitmap;importandroid.graphics.BitmapFactory;importandroid.graphics.Canvas;importandroid.graphics.Color;importandroid.graphics.Matrix;importandroid.gra
Android:UI线程与子线程 在一个Android程序开始运行的时候,会单独启动一个Process。默认的情况下,所有这个程序中的Activity或者Service(Service和Activity只是Android提供的Components中