android 图片画画板
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 图片画画板的更多相关文章
- Android 实现图片画画板
本文主要讲述了Android 实现图片画画板 设计项目布局: <RelativeLayout xmlns:android="http://schemas.android.com/apk ...
- Android(java)学习笔记238:多媒体之图片画画板案例
1.首先我们编写布局文件activity_main.xml如下: <RelativeLayout xmlns:android="http://schemas.android.com/a ...
- Android(java)学习笔记181:多媒体之图片画画板案例
1.首先我们编写布局文件activity_main.xml如下: <RelativeLayout xmlns:android="http://schemas.android.com/a ...
- Android简单开发的画画板
Android开发画画板要考虑得几个问题如下: 1 屏幕画板.画笔如何绘制问题 2 用户手指触摸屏幕画板监听事件,以及对应的几种状态处理问题 3 保存图片到SD卡,以及在系统相册打开时自动加载刚才的 ...
- Android -- 图片处理, 画画板,缩放,旋转,平移,镜面,倒影,图片合成,颜色处理
1. 画画板 示例代码 public class MainActivity extends Activity { private ImageView iv; private Bitmap baseBi ...
- android96 内存创建图片副本,画画板
package com.itheima.copy; import android.os.Bundle; import android.app.Activity; import android.grap ...
- Android简易实战教程--第二十四话《画画板》
今天完成一个画画板. 首先来个布局: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android ...
- Android图片缓存之Lru算法
前言: 上篇我们总结了Bitmap的处理,同时对比了各种处理的效率以及对内存占用大小.我们得知一个应用如果使用大量图片就会导致OOM(out of memory),那该如何处理才能近可能的降低oom发 ...
- android图片处理方法
Java代码 //压缩图片大小 public static Bitmap compressImage(Bitmap image) { ByteArrayOutputStream baos = new ...
随机推荐
- OpenGL9-(FreeImage)加载图片-作为纹理
/*** 这个例子展示如何使用FreeImage加载图片作为纹理* 初学者,在学习OpenGL的时候,往往因为OpenGL读图片没有那么方便* 而浪费了大量的时间在研究图片格式上,其实大可不必. 1. ...
- SOA 的基本概念及设计原则浅议
SOA是英文词语"Service Oriented Architecture"的缩写,中文有多种翻译,如"面向服务的体系结构"."以服务为中心的体系结 ...
- Bugzilla 使用指南
Bugzilla安装见前一篇博客,本篇文章主要关注于如何高效合理的使用Bugzilla,作为为公司内部人员的培训使用指南. Bugzilla是一个开源的缺陷跟踪系统,它可以管理软件开发过程中缺陷的提交 ...
- 仿360手机卫士界面效果android版源码
仿360手机卫士界面效果android版,这个今天一大早在源码天堂的那个网站上看到了一个那个网站最新更新的一个源码,所以就分享给大学习一下吧,布局还挺不错的,而且也很简单的,我就不把我修改的那个分享出 ...
- 导出excel表格
一. 1.获取数据源2.DataTable dt = st.Tables[0]; HttpResponse resp; // HTTP响应信息 resp = Page.Response; resp.C ...
- JS如何获取iframe内html的body值
default页面: <html> <head> <script type="text/javascript"> window.onload=f ...
- Microsoft Visual Studio Ultimate 2012 旗舰版 有效注册密钥
Microsoft Visual Studio Ultimate 2012 旗舰版 有效注册密钥: YKCW6-BPFPF-BT8C9-7DCTH-QXGWC 已经过本人测试 本着分享的精神,希望大家 ...
- MySQL的alter的使用
ALTER TABLE 语句用于在已有的表中添加.修改或删除列 1.ADD [COLUMN] column name (column definitions) [FIRST or AFTER colu ...
- Google code: Why ‘Everything up-to-date’ when pushing (git)
原文链接:http://blog.rexzhao.com/2011/11/28/google-code-git-everything-up-to-date-when-push.html 第一次在Goo ...
- 通过物理模型生成Java代码
通过物理模型生成Java代码 软件开发过程中,我们一般是先针对数据库建模,物理建模完成后,生成数据库表,编码阶段的时候我们会针对数据库表生成大量的Javaeban或者是实体类 Powertdesign ...