canvas.xml:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="保存"
android:onClick="save"
/> <ImageView
android:id="@+id/image"
android:layout_width="480px"
android:layout_height="320px"
/>
</LinearLayout>
package com.example.imageLoadBigImg;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast; import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException; /**
* 图片画板
* Created by Heyiyong on 2014-4-11 下午1:58.
*/
public class ImageCanvasActivity extends Activity { private ImageView imageView;
private Bitmap bitmap;
private Canvas canvas; public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.canvas); imageView = (ImageView) findViewById(R.id.image); //创建画笔样式
final Paint paint = new Paint();
paint.setColor(Color.RED); //创建一个可修改的bitmap
bitmap = Bitmap.createBitmap(480, 320, Bitmap.Config.ARGB_4444); //以bitmap为模板,创建画板对象
canvas = new Canvas(bitmap);
canvas.drawColor(Color.WHITE); imageView.setOnTouchListener(new View.OnTouchListener() {
int startX;
int startY; @Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN://按下的时候
startX = (int) event.getX();
startY = (int) event.getY();
break;
case MotionEvent.ACTION_MOVE://移动的时候 int newX = (int) event.getX();
int newY = (int) event.getY();
canvas.drawLine(startX, startY, newX, newY, paint);
//重置初始位置
startX = newX;
startY = newY;
//将画板的图片设置上去
imageView.setImageBitmap(bitmap);
break;
case MotionEvent.ACTION_UP://手放开的时候
break;
}
return true;
}
});
} public void save(View view) {
try {
File file = new File(Environment.getExternalStorageDirectory(), System.currentTimeMillis() + ".jpg");
FileOutputStream fos = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);//第一个参数为图片格式
fos.close();
Toast.makeText(this, "保存图片成功", 2000).show();
//模拟消息:SD卡被重新挂载了
Intent intent = new Intent();
intent.setAction(intent.ACTION_MEDIA_MOUNTED);
intent.setData(Uri.fromFile(Environment.getExternalStorageDirectory()));
sendBroadcast(intent);
} catch (FileNotFoundException e) {
Toast.makeText(this, "保存图片失败", 2000).show();
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}

android 图片画画板的更多相关文章

  1. Android 实现图片画画板

    本文主要讲述了Android 实现图片画画板 设计项目布局: <RelativeLayout xmlns:android="http://schemas.android.com/apk ...

  2. Android(java)学习笔记238:多媒体之图片画画板案例

    1.首先我们编写布局文件activity_main.xml如下: <RelativeLayout xmlns:android="http://schemas.android.com/a ...

  3. Android(java)学习笔记181:多媒体之图片画画板案例

    1.首先我们编写布局文件activity_main.xml如下: <RelativeLayout xmlns:android="http://schemas.android.com/a ...

  4. Android简单开发的画画板

    Android开发画画板要考虑得几个问题如下: 1 屏幕画板.画笔如何绘制问题 2 用户手指触摸屏幕画板监听事件,以及对应的几种状态处理问题 3  保存图片到SD卡,以及在系统相册打开时自动加载刚才的 ...

  5. Android -- 图片处理, 画画板,缩放,旋转,平移,镜面,倒影,图片合成,颜色处理

    1. 画画板 示例代码 public class MainActivity extends Activity { private ImageView iv; private Bitmap baseBi ...

  6. android96 内存创建图片副本,画画板

    package com.itheima.copy; import android.os.Bundle; import android.app.Activity; import android.grap ...

  7. Android简易实战教程--第二十四话《画画板》

    今天完成一个画画板. 首先来个布局: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android ...

  8. Android图片缓存之Lru算法

    前言: 上篇我们总结了Bitmap的处理,同时对比了各种处理的效率以及对内存占用大小.我们得知一个应用如果使用大量图片就会导致OOM(out of memory),那该如何处理才能近可能的降低oom发 ...

  9. android图片处理方法

    Java代码 //压缩图片大小 public static Bitmap compressImage(Bitmap image) { ByteArrayOutputStream baos = new ...

随机推荐

  1. 如何获取Window

    [[UIApplication sharedApplication].delegate window]

  2. OC 成员变量作用域

    1.  成员变量作用域:    @public :在任何地方都能直接访问对象的成员变量.    @private :只能在当前类的对象方法中直接访问.(@implementation中默认是@priv ...

  3. APC -- Asynchronous Procedure Call 异步过程调用

    异步过程调用(APC -- Asynchronous Procedure Call )是一种与常用的和简单的同步对象不同的一种同步机制. 我们在我们线程里使用基本的同步对象如MUTEX去通知其它线程, ...

  4. Android EditText不弹出输入法焦点问题的总结

    转自:http://mobile.51cto.com/aprogram-403138.htm 看一个manifest中Activity的配置,如果这个页面有EditText,并且我们想要进入这个页面的 ...

  5. OC2_ARC MRC混合编程

    // // main.m // OC2_ARC MRC混合编程 // // Created by zhangxueming on 15/6/19. // Copyright (c) 2015年 zha ...

  6. salvage 数据块打捞工具

    基本上所有数据库都是按块存储数据的,每种数据库的块都有自己有特征,我们可以找出特征,当数据库文件丢失,甚至文件系统完全损坏时,从硬盘扇区中把数据页打捞出来,从页从数据页中恢复出行数据.根据这个原理,开 ...

  7. myeclipse与数据库进行连接(无需写代码进行验证)

    首先对SqlServer配置管理器进行设置. 1.打开SqlServer配置管理器 2.进入SQL配置管理器后,选中左侧“SQL Server网络配置”>>再选中“MSSQLSERVER的 ...

  8. mysql 触发器,insert,auto字段竟然一样....

    a 表的字段有id,uid,name,其中id是自增值, CREATE TRIGGER trigger_insert_productAFTER INSERT ON aFOR EACH ROWBEGIN ...

  9. Linux 通过 shell 脚本修改密码

    交互方式修改密码 1. ssh 远程到主机: 2. 切换到root账号: [一般都是切换到root进行密码修改,如果普通用户修改自己的密码,要输入原密码,然后新密码要满足复杂度才OK]: 3. pas ...

  10. 将C# dataTable 做为参数传入到存储过程

    1.list转换为DataTable(如果有需要) public static DataTable ListToDataTable<T>(List<T> entitys) { ...