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. BT之下拉菜单

    <div class="dropdown"> <button class="btn btn-default dropdown-toggle" ...

  2. feature.shape和feature.shapecopy的区别

    以前在写AE代码的时候也没有注意到feature.shape和feature.shapecopy的区别,觉得两者也差不多: 今天写入库程序才明白过来. 如果取feature.shape,则得到的是该要 ...

  3. 设置图层符号风格为用已有mxd里的同名图层风格

    //要加载的IFeatureClass IFeatureClass pFeatClass = dataset as IFeatureClass; //新建要加载到mxd文档中的图层 IFeatureL ...

  4. 暑假集训(4)第一弹 -----递推(Hdu2039)

    题意梗概:fff团团员小A想退团了,不过要退团,他必须绘制出贤者法阵,以证明他有资格不受大fff之灵的监督 并退团,小A他现在要开始收集材料了,但是,他不清楚应该买多少份材料. 虽然你并不想帮他退团, ...

  5. 函数 resize和reserve的区别

    reserve是容器预留空间,但在空间内不真正创建元素对象,所以在没有添加新的对象之前,不能引用容器内的元素.加入新的元素时,要调用push_back()/insert()函数. resize是改变容 ...

  6. 一种简单的权限管理ER图设计

    权限管理支持动态地管理用户的角色和权限.权限代表用户可以在什么对象上进行什么操作:角色是一组权限的集合. PS:当增加或删除某个用户的角色时,系统自动将该角色对应的权限(角色 -权限关联表)增加或删除 ...

  7. 在HTML5中怎样实现Canvas阴影效果

    该文章是由e良师益友技术部小陈原创作品,转载是请注明来源,谢谢! 今天我给大家介绍一下在HTML5中怎样实现Canvas阴影效果,我们知道现在HTML5的Canvas阴影也经常使用的,这个就是HTML ...

  8. 一本JavaEE的案例书

    案例很好.1.网上书店 2.AJAX网页聊天

  9. 无法建立到http://localhost:6080/arcgis/manager/的连接

    安装ArcGIS server10.1后,打开管理页面提示“无法建立到http://localhost:6080/arcgis/manager/的连接” 原因是:在ArcGIS for Server ...

  10. php 实现 mysql数据表优化与修复

    <?php $link = mysql_connect("localhost", "root", "") or die("e ...