注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

你想快速掌握安卓编程吗

 
 
 

日志

 
 

一个屏幕画图例程  

2014-04-29 16:14:25|  分类: B.图形 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
一个屏幕画图例程 - 沉默蜂QQ793136625 - Basic4android安卓编程
 例程布局文件



一个屏幕画图例程 - 沉默蜂QQ793136625 - Basic4android安卓编程
 本例程运行效果图





来源《Simple Paint Program》
http://www.basic4ppc.com/android/forum/threads/simple-paint-program.7577/


——————————————  下面是Main活动视图代码  ——————————————

#Region Module Attributes
#FullScreen: False
#IncludeTitle: True
#ApplicationLabel: TestDrawing1
#VersionCode: 1
#VersionName: 
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: True
#End Region

'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.

End Sub

Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim rbtPointer, rbtLine, rbtCircle, rbtBitmap, rbtText As RadioButton 
Dim bmpImage, bmpTest, bmpTransparent As Bitmap
Dim cvsImage, cvsTest As Canvas
Dim Graph1 As Path
Dim Graph2 As Path
Dim Graph3 As Path
Dim SRect, DRect, Rect1 As Rect
Dim Label1, Label2, Label3, Label4, Label5, Label6 As Label
Dim btn1 As Button
Dim pnlTest As Panel
Dim spnTextSize As Spinner
Dim cPointer As Int : cPointer=0
Dim cLine As Int : cLine=1
Dim cCircle As Int : cCircle=2
Dim cPath As Int : cPath=3
Dim cBitmap As Int : cBitmap=4
Dim cText As Int : cText=5
Dim DrawFunc As Int : DrawFunc=cLine
Dim Angle As Float : Angle=0
Dim LineColor As Int : LineColor=Colors.Blue
Dim LineWidth As Float : LineWidth=3
Dim x1 As Float : x1=0
Dim y1 As Float : y1=0
Dim x2 As Float : x2=0
Dim y2 As Float : y2=0
Dim TextSize As Float : TextSize=20
End Sub

Sub Activity_Create(FirstTime As Boolean)
Dim xx, yy As Float
Activity.LoadLayout("Draw1")
cvsImage.Initialize(Activity)
bmpImage.Initialize(File.DirAssets, "Chataigner1.png")
SRect.Initialize(0,0,bmpImage.Width,bmpImage.Height)
xx=60
yy=130
DRect.Initialize(xx,yy,bmpImage.Width+xx,bmpImage.Height+yy)
Rect1.Initialize(175,175,225,225)

Label3.Text=bmpImage.Width
Label3.Text=Colors.Transparent
Label4.Text=bmpImage.Height
Label4.Text=Colors.White
pnlTest.Color=Colors.Transparent
pnlTest.Top=80
pnlTest.Left=0
cvsTest.Initialize(pnlTest)
bmpTest.Initialize3(cvsTest.Bitmap)
Graph1.Initialize(100,100)
Graph1.LineTo(260,100)
Graph1.LineTo(180,200)
Graph1.LineTo(100,100)

Graph2.Initialize(130,150)
Graph2.LineTo(290,150)
Graph2.LineTo(210,250)

Graph3.Initialize(150,200)
Graph3.LineTo(280,200)
Graph3.LineTo(200,300)
Colors.ARGB(0,0,0,0)
spnTextSize.AddAll(Array As Int(16,20,24,30))
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Activity_Touch (Action As Int, X As Float, Y As Float)
Dim r As Float
If Action=Activity.ACTION_DOWN Then
x1=X
y1=Y
x2=X
y2=Y
Label5.Text="Activity_Down"
If DrawFunc=0 Then
Label3.Text=X
Label4.Text=Y
End If
Else If Action=Activity.ACTION_MOVE Then
x2=X
y2=Y
If DrawFunc=cLine Then
pnlTest.Color=Colors.Transparent
cvsTest.Initialize(pnlTest)
cvsTest.DrawLine(x1,y1-pnlTest.Top,x2,y2-pnlTest.Top,Colors.Red,LineWidth)
pnlTest.Invalidate
Else If DrawFunc=cCircle Then
r=Sqrt(Power((x2-x1),2)+Power((y2-y1),2))
pnlTest.Color=Colors.Transparent
cvsTest.Initialize(pnlTest)
cvsTest.DrawCircle(x1,y1-pnlTest.Top,r,Colors.Red,False,LineWidth)
pnlTest.Invalidate
End If
Label5.Text="Activity_Move"
Label3.Text=X
Label4.Text=Y
Else If Action=Activity.ACTION_UP Then
Draw
Else
Label5.Text="Activity_Touch"
End If
End Sub

Sub rbtDrawFunc_Click
Dim Send As View
Send=Sender
DrawFunc=Send.Tag
If DrawFunc=cText Then
spnTextSize.Visible=True
btn1.Visible=False
Else
spnTextSize.Visible=False
btn1.Visible=True
End If
End Sub

Sub Draw
Dim r As Float
Label1.Text=DrawFunc
If DrawFunc=cPointer Then
Else If DrawFunc=cLine Then
pnlTest.Color=Colors.Transparent
cvsTest.Initialize(pnlTest)
cvsImage.DrawLine(x1,y1,x2,y2,LineColor,LineWidth)
Else If DrawFunc=cCircle Then
pnlTest.Color=Colors.Transparent
cvsTest.Initialize(pnlTest)
r=Sqrt(Power((x2-x1),2)+Power((y2-y1),2))
cvsImage.DrawCircle(x1,y1,r,LineColor,False,LineWidth)
Else If DrawFunc=cText Then
cvsImage.DrawText("Text",x2,y2,Typeface.DEFAULT,TextSize,Colors.Green,"LEFT")
End If
Activity.Invalidate
End Sub

Sub btn1_Click
Log(DrawFunc&" "&cBitmap)
If DrawFunc=cBitmap Then
cvsImage.DrawRectRotated(DRect,Colors.Black,True,1,Angle) ' does erase the previous bitmap 
Angle=Angle+10
Label5.Text=Angle
cvsImage.DrawBitmapRotated(bmpImage,SRect,DRect,Angle)
Else If DrawFunc=cPath Then
cvsImage.DrawPath(Graph1,Colors.Red,True,1)
cvsImage.DrawPath(Graph1,Colors.Blue,False,3)
cvsImage.DrawPath(Graph2,Colors.Green,True,1)
cvsImage.DrawPath(Graph3,Colors.RGB(200,100,10),True,1)
End If
Activity.Invalidate
End Sub

Sub spnTextSize_ItemClick (Position As Int, Value As Object)
TextSize=Value
End Sub

  评论这张
 
阅读(156)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017