Platforms to show: All Mac Windows Linux Cross-Platform
/Picture/Picture MinMax/mmx_demo
Required plugins for this example:
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Picture/Picture MinMax/mmx_demo
This example is the version from Wed, 14th May 2019.
Project "mmx_demo.xojo_binary_project"
Class Fenster1 Inherits Window
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action()
quit
End EventHandler
End Control
Control scr Inherits Canvas
ControlInstance scr Inherits Canvas
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect)
if intern <> nil then
g.drawpicture intern,0,0
end if
End EventHandler
End Control
Control PushButton2 Inherits PushButton
ControlInstance PushButton2 Inherits PushButton
EventHandler Sub Action()
dim t as integer
t=ticks
find_minimax(intern,result)
t=ticks-t
res_list.deleteAllRows
res_list.AddRow "ticks "+str(t)
addpoint "red max",result(0),result(1)
addpoint "grn max",result(2),result(3)
addpoint "blu max",result(4),result(5)
addpoint "sum max",result(6),result(7)
addpoint "red min",result(8),result(9)
addpoint "grn min",result(10),result(11)
addpoint "blu min",result(12),result(13)
addpoint "sum min",result(14),result(15)
min_btn.enabled=true
max_btn.enabled=true
me.Enabled=false
End EventHandler
End Control
Control res_list Inherits ListBox
ControlInstance res_list Inherits ListBox
End Control
Control min_btn Inherits PushButton
ControlInstance min_btn Inherits PushButton
EventHandler Sub Action()
intern.graphics.drawpicture test,0,0
draw_mark intern, result(0),result(1),red
draw_mark intern, result(2),result(3),grn
draw_mark intern, result(4),result(5),blu
draw_mark intern, result(6),result(7),blk
End EventHandler
End Control
Control max_btn Inherits PushButton
ControlInstance max_btn Inherits PushButton
EventHandler Sub Action()
intern.graphics.drawpicture test,0,0
draw_mark intern, result(8),result(9),red
draw_mark intern, result(10),result(11),grn
draw_mark intern, result(12),result(13),blu
draw_mark intern, result(14),result(15),blk
End EventHandler
End Control
EventHandler Sub Open()
intern = New Picture(256,256,32)
intern.graphics.drawpicture test,0,0
red=rgb(255,0,0)
grn=rgb(0,255,0)
blu=rgb(0,0,255)
blk=rgb(0,0,0)
wht=rgb(255,255,255)
End EventHandler
Sub addpoint(s as string, x as integer, y as integer)
dim c as color
c=Intern.RGBSurface.Pixel(x,y)
res_list.addrow s+" x "+str(x)
res_list.cell(res_list.LastIndex,1)=str(c.red)
res_list.cell(res_list.LastIndex,2)=str(c.green)
res_list.cell(res_list.LastIndex,3)=str(c.blue)
res_list.addrow s+" y "+str(y)
End Sub
Sub draw_mark(pic as picture, x as integer, y as integer, col as color)
pic.graphics.penwidth=1
pic.graphics.penheight=1
pic.graphics.forecolor=blk
pic.graphics.drawOval x-5,y-5,11,11
pic.graphics.forecolor=wht
pic.graphics.drawOval x-4,y-4,9,9
pic.graphics.forecolor=col
pic.graphics.drawline x-5,y,x-1,y
pic.graphics.drawline x+1,y,x+5,y
pic.graphics.drawline x,y-5,x,y-1
pic.graphics.drawline x,y+5,x,y+1
show_image
End Sub
Sub find_minimax(pic as picture, byref res() as integer)
dim x,y,rr,gg,bb,ss as integer
dim red_max_x,red_max_y,red_min_x,red_min_y, red_min, red_max as integer
dim grn_max_x,grn_max_y,grn_min_x,grn_min_y, grn_min, grn_max as integer
dim blu_max_x,blu_max_y,blu_min_x,blu_min_y,blu_max, blu_min as integer
dim sum_max_x,sum_max_y,sum_min_x,sum_min_y,sum_max, sum_min as integer
dim sf as rgbSurface
dim col as color
sf=pic.rgBSurface
red_max=0
grn_max=0
blu_max=0
sum_max=0
red_min=255
grn_min=255
blu_min=255
sum_min=255
for y=0 to pic.width-1
for x=0 to pic.width-1
col=sf.pixel(x,y)
rr=col.red
gg=col.green
bb=col.blue
ss=rr+gg+bb
if rr>red_max then
red_max=rr
red_max_x=x
red_max_y=y
end if
if rr<red_min then
red_min=rr
red_min_x=x
red_min_y=y
end if
if gg>grn_max then
grn_max=gg
grn_max_x=x
grn_max_y=y
end if
if gg<grn_min then
grn_min=gg
grn_min_x=x
grn_min_y=y
end if
if bb>blu_max then
blu_max=bb
blu_max_x=x
blu_max_y=y
end if
if bb<red_min then
blu_min=bb
blu_min_x=x
blu_min_y=y
end if
if ss>sum_max then
sum_max=ss
sum_max_x=x
sum_max_y=y
end if
if ss<sum_min then
sum_min=ss
sum_min_x=x
sum_min_y=y
end if
next
next
res(0)=red_max_x
res(1)=red_max_y
res(2)=grn_max_x
res(3)=grn_max_y
res(4)=blu_max_x
res(5)=blu_max_y
res(6)=sum_max_x
res(7)=sum_max_y
res(8)=red_min_x
res(9)=red_min_y
res(10)=grn_min_x
res(11)=grn_min_y
res(12)=blu_min_x
res(13)=blu_min_y
res(14)=sum_min_x
res(15)=sum_min_y
End Sub
Sub show_image()
scr.Invalidate
End Sub
Property Protected blk As color
Property Protected blu As color
Property Protected grn As color
Property Protected intern As picture
Property Protected red As color
Property Protected result(15) As integer
Property Protected wht As color
End Class
MenuBar Menü
MenuItem UntitledMenu3 = ""
MenuItem UntitledMenu2 = "Ablage"
MenuItem FileQuit = "Beenden"
MenuItem UntitledMenu7 = ""
MenuItem UntitledMenu0 = "Bearbeiten"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Ausschneiden"
MenuItem EditCopy = "Kopieren"
MenuItem EditPaste = "Einfügen"
MenuItem EditClear = "Löschen"
MenuItem UntitledMenu6 = ""
MenuItem UntitledMenu5 = ""
MenuItem UntitledMenu4 = ""
End MenuBar
Class App Inherits Application
End Class
ExternalFile TEST
End ExternalFile
End Project
See also:
- /Picture/Picture Blending test
- /Picture/Picture blending/blend with plugin
- /Picture/Picture Blur
- /Picture/Picture Combine
- /Picture/Picture Copy Fast Test
- /Picture/Picture manipulation
- /Picture/Picture Matrix/matrix without plugin
- /Picture/Picture Scale/Scale Compare
- /Picture/Picture Scale/Scale Test
- /Picture/Picture To String
The items on this page are in the following plugins: MBS Picture Plugin.