package com.android.mPaint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.graphics.BlurMaskFilter;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.EmbossMaskFilter;
import android.graphics.MaskFilter;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.RectF;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
public class mPaint extends Activity {
/** Called when the activity is first created. */
private float mX,mY;
private float startX,startY;
private Paint mPaint,mBitmapPaint;
private Canvas mCanvas;
private Bitmap mBitmap;
Bitmap bitmap=null;
private Path mPath;
private MaskFilter mEmboss;
private MaskFilter mBlur;
private static final String[] color=new String[]{"红色","蓝色","绿色"};
private static final String[] shape=new String[]{"浮现的","模糊的","正常的"};
private static final String[] graph=new String[]{"点","线","圆形","椭圆","矩形"};
private game mGameView;
int choice=2;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mGameView = new game(this);
setContentView(mGameView);
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setDither(true);
mPaint.setColor(Color.BLACK);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeJoin(Paint.Join.BEVEL);
mPaint.setStrokeCap(Paint.Cap.SQUARE);
mPaint.setStrokeWidth(12);
}
public boolean onCreateOptionsMenu(Menu menu)
{
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item)
{
mPaint.setXfermode(null);
int item_id = item.getItemId();
switch (item_id)
{
case R.id.color:
AlertDialog dlg = new AlertDialog.Builder(mPaint.this)
.setTitle("颜色选择")
.setSingleChoiceItems(color, 0,
new DialogInterface.OnClickListener() //设置事件监听
{
public void onClick(DialogInterface dialog, int whichButton)
{
if(whichButton==0){
mPaint.setColor(Color.RED);
dialog.dismiss();
}
if(whichButton==1){
mPaint.setColor(Color.BLUE);
dialog.dismiss();
}
if(whichButton==2){
mPaint.setColor(Color.GREEN);
dialog.dismiss();
}
}
})
.create();//创建
dlg.show();//显示
return true;
case R.id.shape:
AlertDialog dlg1 = new AlertDialog.Builder(mPaint.this)
.setTitle("画笔样式选择")
.setSingleChoiceItems(shape, 0,
new DialogInterface.OnClickListener() //设置事件监听
{
public void onClick(DialogInterface dialog, int whichButton)
{
if(whichButton==0){
if (mPaint.getMaskFilter() != mEmboss) {
mPaint.setMaskFilter(mEmboss);
} else {
mPaint.setMaskFilter(null);
}
dialog.dismiss();
}
if(whichButton==1){
if (mPaint.getMaskFilter() != mBlur) {
mPaint.setMaskFilter(mBlur);
} else {
mPaint.setMaskFilter(null);
}
dialog.dismiss();
}
if(whichButton==2){
mPaint.setMaskFilter(null);
dialog.dismiss();
}
}
})
.create();//创建
dlg1.show();//显示
return true;
case R.id.graph:
AlertDialog dlg2 = new AlertDialog.Builder(mPaint.this)
.setTitle("选择需要使用的几何图形")
.setSingleChoiceItems(graph, 0,
new DialogInterface.OnClickListener() //设置事件监听
{
public void onClick(DialogInterface dialog, int whichButton)
{
if(whichButton==0){
choice=1;
dialog.dismiss();
}
if(whichButton==1){
choice=2;
dialog.dismiss();
}
if(whichButton==2){
choice=3;
dialog.dismiss();
}
if(whichButton==3){
choice=4;
dialog.dismiss();
}
if(whichButton==4){
choice=5;
dialog.dismiss();
}
}
})
.create();//创建
dlg2.show();//显示
return true;
case R.id.clean:
mCanvas.drawColor(0xFFAAAAAA);
return true;
case R.id.rubber:
choice=2;
mPaint.setXfermode(new PorterDuffXfermode(
PorterDuff.Mode.CLEAR));
return true;
}
return super.onOptionsItemSelected(item);
}
public class game extends View implements Runnable{
public game(Context context) {
super(context);
mPath = new Path();
mEmboss = new EmbossMaskFilter(new float[] { 1, 1, 1 },
0.4f, 6, 3.5f);
mBlur = new BlurMaskFilter(8, BlurMaskFilter.Blur.NORMAL);
mBitmap = Bitmap.createBitmap(320, 480, Bitmap.Config.ARGB_8888);
mCanvas = new Canvas(mBitmap);
mBitmapPaint = new Paint(Paint.DITHER_FLAG);
}
public void onDraw(Canvas canvas) {
canvas.drawColor(0xFFAAAAAA);
canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
canvas.drawPath(mPath, mPaint);
}
private void touch_start(float x, float y) {
mPath.reset();
mPath.moveTo(x, y);
startX = x;
startY = y;
}
private void touch_move(float x, float y) {
switch(choice){
case 2:
float dx = Math.abs(x - startX);
float dy = Math.abs(y - startY);
if (dx >= 4 || dy >= 4) {
mPath.quadTo(startX, startY, (x + startX)/2, (y + startY)/2);
startX = x;
startY = y;
}
break;
case 1:
case 3:
case 4:
case 5:
mX=x;
mY=y;
break;
}
}
private void touch_up(float x, float y) {
mX=x;
mY=y;
RectF mRectF=new RectF(startX,sta
没有合适的资源?快使用搜索试试~ 我知道了~
android简易画图工具
共32个文件
class:12个
png:7个
xml:5个
5星 · 超过95%的资源 需积分: 10 94 下载量 88 浏览量
2011-04-12
14:44:13
上传
评论 2
收藏 442KB RAR 举报
温馨提示
使用android编写的一个画图工具,在以前的基础上修改的,改正了很多错误(如橡皮擦功能)
资源推荐
资源详情
资源评论
收起资源包目录
android简易画图工具.rar (32个子文件)
mPaint
.project 842B
default.properties 364B
bin
com
android
mPaint
R$string.class 427B
R$layout.class 424B
R$drawable.class 508B
mPaint$1.class 1KB
R$menu.class 381B
R.class 577B
R$attr.class 340B
mPaint$game.class 5KB
mPaint$2.class 1KB
R$id.class 500B
mPaint.class 6KB
mPaint$3.class 1KB
resources.ap_ 126KB
classes.dex 11KB
mPaint.apk 134KB
AndroidManifest.xml 679B
src
com
android
mPaint
mPaint.java 9KB
res
values
strings.xml 163B
layout
dialog.xml 208B
main.xml 382B
drawable-ldpi
icon.png 2KB
drawable-hdpi
icon.png 4KB
drawable
tu1.png 18KB
tu2.png 50KB
tu3.png 43KB
tu4.png 48KB
drawable-mdpi
icon.png 3KB
menu
menu.xml 474B
.classpath 280B
gen
com
android
mPaint
R.java 1KB
assets
共 32 条
- 1
yao891203
- 粉丝: 7
- 资源: 15
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
前往页