Platforms to show: All Mac Windows Linux Cross-Platform

/Picture/PictureWriter Test


Required plugins for this example: MBS Picture Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Picture/PictureWriter Test

This example is the version from Sun, 17th Mar 2012.

Project "PictureWriter Test.xojo_binary_project"
FileTypes
Filetype text
End FileTypes
Class WindowPictureWriter Inherits Window
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() Darker End EventHandler
End Control
Control Canvas1 Inherits Canvas
ControlInstance Canvas1 Inherits Canvas
End Control
Control PushButton2 Inherits PushButton
ControlInstance PushButton2 Inherits PushButton
EventHandler Sub Action() Stats End EventHandler
End Control
EventHandler Sub Open() Create End EventHandler
Protected Sub Create() dim p as PictureWriterMBS dim m as MemoryBlock dim r,g,b,rRow,gRow,bRow,h1,w1,x,y,bpp,RowBytes as integer // Create a new picture writer p=NewPictureWriterMBS(512,512) if p=nil then MsgBox "Failed to create PictureWriterMBS object!" Return end if // Get data in memory. This Memoryblock has a size property of 0! h1=p.Height-1 w1=p.Width-1 RowBytes = p.RowBytes bpp = p.BytesPerPixel rRow = p.RedOffset gRow = p.GreenOffset bRow = p.BlueOffset // in each row the red, blue and green channels have different offsets. // but offsets are platform dependend for y=0 to h1 m = p.Data(y) r=rRow g=gRow b=bRow for x=0 to w1 m.UInt8Value(r)=x\2 m.UInt8Value(g)=y\2 m.UInt8Value(b)=x*y\2 r=r+bpp g=g+bpp b=b+bpp next next // Use Render to make a picture object Canvas1.Backdrop=p.Render End Sub
Protected Sub Darker() dim p as PictureEditorMBS dim m as MemoryBlock dim RowBytes,r,g,b,rRow,gRow,bRow,h1,w1,x,y,bpp as integer dim rv,bv,gv as integer p=NewPictureEditorMBS(Canvas1.Backdrop) if p=nil then MsgBox "Failed to create PictureEditorMBS object!" Return end if // Get data in memory. This Memoryblock has a size property of 0! h1=p.Height-1 w1=p.Width-1 RowBytes = p.RowBytes bpp = p.BytesPerPixel rRow = p.RedOffset gRow = p.GreenOffset bRow = p.BlueOffset // in each row the red, blue and green channels have different offsets. // but offsets are platform dependend for y = 0 to h1 m = p.Data(y) r = rRow g = gRow b = bRow for x=0 to w1 rv = m.UInt8Value(r) gv = m.UInt8Value(g) bv = m.UInt8Value(b) rv = rv - 8 gv = gv - 8 bv = bv - 8 if rv < 0 then rv = 0 end if if gv < 0 then gv = 0 end if if bv < 0 then bv =0 end if m.UInt8Value(r) = rv m.UInt8Value(g) = gv m.UInt8Value(b) = bv r = r + bpp g = g + bpp b = b + bpp next next p = nil Refresh End Sub
Protected Sub Stats() dim p as PictureReaderMBS dim m as MemoryBlock dim r,g,b,rRow,gRow,bRow,h1,w1,x,y,bpp as integer dim rs,gs,bs,rv,bv,gv as integer p=NewPictureReaderMBS(Canvas1.Backdrop) if p=nil then MsgBox "Failed to create PictureReaderMBS object!" Return end if // Get data in memory. This Memoryblock has a size property of 0! m=p.Data h1=p.Height-1 w1=p.Width-1 bpp=p.BytesPerPixel rRow=p.RedOffset gRow=p.GreenOffset bRow=p.BlueOffset // in each row the red, blue and green channels have different offsets. // but offsets are platform dependend for y=0 to h1 r=rRow g=gRow b=bRow for x=0 to w1 rv=m.UInt8Value(r) gv=m.UInt8Value(g) bv=m.UInt8Value(b) rs=rs+rv gs=gs+gv bs=bs+bv r=r+bpp g=g+bpp b=b+bpp next // rowbytes is not always with*bpp so use rowbytes property rRow=rRow+p.RowBytes gRow=gRow+p.RowBytes bRow=bRow+p.RowBytes next p = nil MsgBox "Total pixel values: "+EndOfLine+"Red: "+Format(rs,"0")+EndOfLine+"Green: "+Format(gs,"0")+EndOfLine+"Blue: "+Format(bs,"0") End Sub
End Class
MenuBar MenuBar1
MenuItem UntitledMenu1 = ""
MenuItem FileMenu = "&File"
MenuItem FileQuit = "Quit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu0 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class App Inherits Application
End Class
End Project

The items on this page are in the following plugins: MBS Picture Plugin.


The biggest plugin in space...