public
class
Pen
extends
Graphics2DActivity {
int
menuOption;
@Override
protected
void
drawImage() {
switch
(menuOption) {
case
R.id.mnuLines:
drawLines();
break
;
case
R.id.mnuDashes:
drawDash();
break
;
case
R.id.mnuLineCap:
drawLineCap();
break
;
case
R.id.mnuLineJoin:
drawLineJoin();
break
;
default
:
drawLines();
break
;
}
graphic2dView.refreshCanvas();
}
@Override
public
boolean
onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_option_line, menu);
return
true
;
}
@Override
public
boolean
onOptionsItemSelected(MenuItem item) {
menuOption = item.getItemId();
drawImage();
return
true
;
}
private
void
drawLineJoin() {
Color blackColor =
new
Color(
0xff000000
);
Color whiteColor =
new
Color(
0xffffffff
);
com.mapdigit.drawing.geometry.Path path
=
new
com.mapdigit.drawing.geometry.Path();
path.moveTo(
40
,
60
);
path.lineTo(
90
,
20
);
path.lineTo(
140
,
60
);
graphics2D.clear(Color.WHITE);
AffineTransform matrix =
new
AffineTransform();
graphics2D.setAffineTransform(matrix);
com.mapdigit.drawing.Pen pen
=
new
com.mapdigit.drawing.Pen(blackColor,
20
, com.mapdigit.drawing.Pen.CAP_BUTT,
com.mapdigit.drawing.Pen.JOIN_MITER);
graphics2D.draw(pen, path);
pen =
new
com.mapdigit.drawing.Pen(whiteColor,
1
);
graphics2D.draw(pen, path);
matrix.translate(
0
,
50
);
graphics2D.setAffineTransform(matrix);
pen =
new
com.mapdigit.drawing.Pen(blackColor,
20
,
com.mapdigit.drawing.Pen.CAP_BUTT,
com.mapdigit.drawing.Pen.JOIN_ROUND);
graphics2D.draw(pen, path);
pen =
new
com.mapdigit.drawing.Pen(whiteColor,
1
);
graphics2D.draw(pen, path);
matrix =
new
AffineTransform();
matrix.translate(
0
,
100
);
graphics2D.setAffineTransform(matrix);
pen =
new
com.mapdigit.drawing.Pen(blackColor,
20
,
com.mapdigit.drawing.Pen.CAP_BUTT,
com.mapdigit.drawing.Pen.JOIN_BEVEL);
graphics2D.draw(pen, path);
pen =
new
com.mapdigit.drawing.Pen(whiteColor,
1
);
graphics2D.draw(pen, path);
}
private
void
drawLineCap() {
Color blackColor =
new
Color(
0xff000000
);
Color whiteColor =
new
Color(
0xffffffff
);
graphics2D.clear(Color.WHITE);
AffineTransform matrix =
new
AffineTransform();
graphics2D.setAffineTransform(matrix);
com.mapdigit.drawing.Pen pen
=
new
com.mapdigit.drawing.Pen(blackColor,
20
, com.mapdigit.drawing.Pen.CAP_BUTT,
com.mapdigit.drawing.Pen.JOIN_MITER);
graphics2D.drawLine(pen,
40
,
60
,
140
,
60
);
pen =
new
com.mapdigit.drawing.Pen(whiteColor,
1
);
graphics2D.drawLine(pen,
40
,
60
,
140
,
60
);
pen =
new
com.mapdigit.drawing.Pen(blackColor,
20
,
com.mapdigit.drawing.Pen.CAP_ROUND,
com.mapdigit.drawing.Pen.JOIN_MITER);
graphics2D.drawLine(pen,
40
,
100
,
140
,
100
);
pen =
new
com.mapdigit.drawing.Pen(whiteColor,
1
);
graphics2D.drawLine(pen,
40
,
100
,
140
,
100
);
pen =
new
com.mapdigit.drawing.Pen(blackColor,
20
,
com.mapdigit.drawing.Pen.CAP_SQUARE,
com.mapdigit.drawing.Pen.JOIN_MITER);
graphics2D.drawLine(pen,
40
,
140
,
140
,
140
);
pen =
new
com.mapdigit.drawing.Pen(whiteColor,
1
);
graphics2D.drawLine(pen,
40
,
140
,
140
,
140
);
}
private
void
drawLines() {
Color greenColor =
new
Color(
0xff00ff00
);
graphics2D.clear(Color.WHITE);
AffineTransform matrix =
new
AffineTransform();
graphics2D.setAffineTransform(matrix);
com.mapdigit.drawing.Pen pen
=
new
com.mapdigit.drawing.Pen(greenColor,
1
);
graphics2D.drawLine(pen,
20
,
150
,
60
,
50
);
pen =
new
com.mapdigit.drawing.Pen(greenColor,
2
);
graphics2D.drawLine(pen,
40
,
150
,
80
,
50
);
pen =
new
com.mapdigit.drawing.Pen(greenColor,
3
);
graphics2D.drawLine(pen,
60
,
150
,
100
,
50
);
pen =
new
com.mapdigit.drawing.Pen(greenColor,
5
);
graphics2D.drawLine(pen,
80
,
150
,
120
,
50
);
pen =
new
com.mapdigit.drawing.Pen(greenColor,
7
);
graphics2D.drawLine(pen,
100
,
150
,
140
,
50
);
pen =
new
com.mapdigit.drawing.Pen(greenColor,
10
);
graphics2D.drawLine(pen,
120
,
150
,
160
,
50
);
}
private
void
drawDash() {
Color blackColor =
new
Color(
0xff000000
);
int
dashArray1[] = {
2
,
2
};
int
dashArray2[] = {
6
,
6
};
int
dashArray3[] = {
4
,
1
,
2
,
1
,
1
,
6
};
graphics2D.clear(Color.WHITE);
AffineTransform matrix =
new
AffineTransform();
graphics2D.setAffineTransform(matrix);
com.mapdigit.drawing.Pen pen
=
new
com.mapdigit.drawing.Pen(blackColor,
20
, com.mapdigit.drawing.Pen.CAP_BUTT,
com.mapdigit.drawing.Pen.JOIN_MITER, dashArray1,
0
);
graphics2D.drawLine(pen,
40
,
60
,
140
,
60
);
pen =
new
com.mapdigit.drawing.Pen(blackColor,
20
,
com.mapdigit.drawing.Pen.CAP_BUTT,
com.mapdigit.drawing.Pen.JOIN_MITER, dashArray2,
0
);
graphics2D.drawLine(pen,
40
,
100
,
140
,
100
);
pen =
new
com.mapdigit.drawing.Pen(blackColor,
20
,
com.mapdigit.drawing.Pen.CAP_BUTT,
com.mapdigit.drawing.Pen.JOIN_MITER, dashArray3,
0
);
graphics2D.drawLine(pen,
40
,
140
,
140
,
140
);
}
}
相关推荐
《Android简明开发教程》是一份详尽的指南,旨在帮助初学者和有经验的开发者快速掌握Android应用开发。这份教程共分为二十四篇,涵盖了Android开发的基础到高级主题,包括安装Android SDK、创建第一个应用程序、理解...
在Android平台进行3D图形开发时,OpenGL ES(Open Graphics Library for Embedded Systems)是一项关键的技术。它允许开发者在移动设备上创建复杂的3D图形和动画。在OpenGL ES的环境中,3D坐标变换是构建和操作3D...
《Android开发教程CHM》是一本专为Android开发者设计的详尽指南,旨在帮助初学者和有经验的开发者深入理解Android平台的各个方面。这个CHM(Microsoft Compiled HTML Help)文件包含了大量的信息,使得学习和查阅...
【Android开发简明教程中文版】是一份专为初学者设计的详细教程,旨在帮助学习者快速掌握Android应用开发的基本技能。这份资料由经验丰富的教师编写,内容全面且深入浅出,适合对移动开发感兴趣的开发者或者在校学生...
### Android OpenGL ES 开发教程详解 #### 概述与历史沿革 OpenGL ES(OpenGL for Embedded Systems)作为OpenGL API的子集,专为移动设备、PDA和游戏主机等嵌入式系统设计,旨在简化3D图形应用的开发流程。自2003...
Android OpenGL ES 简明开发真正的3D图 Android平台提供的OpenGL ES API主要定义在包android.opengl ,javax.microedition.khronos.egl ,javax.microedition.khronos.opengles ,java.nio 等几个包中
Android OpenGL ES 简明开发教程相关源码添加颜色 简单的上色方法叫做顶点着色(Vertxt coloring),可以使用单色,也可以定义颜色渐变或者使用材质(类同于二维图形中各种Brush类型)。
这个简明开发教程主要参考了Jayway Team Blog中关于OpenGL ES开发的教程,该教程比较通俗易懂,非常适合OpenGL ES的初学者。教程主要通过示例和步骤讲解,旨在帮助没有3D开发经验的程序员快速入门。并且,由于很多...
这个“Android OpenGL ES 简明开发教程相关源码材质渲染”旨在教授如何在Android应用中利用OpenGL ES进行材质渲染,从而创建出丰富的视觉效果。 材质渲染是OpenGL ES中的关键概念,它涉及到物体表面的外观属性,如...
Web前端开发简明教程.pdf
- **SDK安装**:Android SDK(Software Development Kit)是开发Android应用的基础工具包,包含了编译代码所需的库文件、文档、示例代码等资源。开发者需从官方渠道下载SDK,并根据操作系统(Windows、macOS或Linux...
本教程主要介绍了Android APP开发的基本步骤,从SDK下载、开发环境搭建、代码编写、APP打包等步骤一一讲解,为读者提供了一个简明的Android APP开发入门教程。 一、准备工作 在开始Android APP开发之前,需要准备...
AndroidOpenGLES简明开发教程.pdf
### MFC简明教程知识点详解 #### 一、MFC简介与重要性 **MFC**(Microsoft Foundation Classes)是微软提供的一个C++类库,它封装了大部分的**Windows API**(应用程序接口),使得开发者能够更加高效地开发Windows...
《Java大学简明教程:实例程序设计》是一本面向初学者和在校大学生的Java编程教材。这本书通过丰富的实例,深入浅出地介绍了Java语言的基础知识和应用技巧,旨在帮助读者快速掌握Java编程技能。 首先,从"Java简明...
简明数学手册 作者:《简明数学手册》编写组编 出版社:上海教育出版社
MATLAB(Matrix Laboratory)是一种强大的数学计算软件,广泛应用于工程计算、数据分析、算法开发和图形可视化等多个领域。《MATLAB 简明教程》是一部专为初学者设计的指导资料,旨在帮助用户快速掌握MATLAB的基本...