Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Dim imat(512,512) As Int
Dim inew(512,512) As Int
Dim new(512*512) As Int
Dim img,imgnew As Image
Private btnQuit As Button
Private ImageView1 As ImageView
Private Pane1 As Pane
Dim bc As ByteConverter
Dim mycanvas As Canvas
Dim k As Int
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("1") 'Load the layout file.
MainForm.Show
img.Initialize(File.DirApp, "lena_gray.bmp")
'bc.LittleEndian = True
For i=0 To 511
For j=0 To 511
Dim p As Int=ToUnsigned(img.GetPixel(i,j))
imat(i,j)=p
If p>=127 Then
inew(i,j)=1
Else
inew(i,j)=0
End If
new(k)=inew(i,j)
k=k+1
Next
Next
imgnew=BytesToImage(bc.IntsToBytes(new))
Log(new.Length)
Dim out As OutputStream = File.OpenOutput(File.dirapp,"image.bmp", False)
imgnew.WriteToStream(out)
out.Close
ImageView1.SetImage(img)
End Sub
Sub ToUnsigned(b As Byte) As Int
Return Bit.And(0xFF, b)
End Sub
'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
Public Sub ImageToBytes(I As Image)
Dim Out As OutputStream = File.OpenOutput(File.DirApp, "1.bmp",True)
Out.InitializeToBytesArray(0)
I.WriteToStream(Out)
Out.Close
Return
End Sub
Public Sub BytesToImage(bytes() As Byte) As Image
Dim In As InputStream
In.InitializeFromBytesArray(bytes, 0, bytes.Length)
Dim bmp As Image
bmp.Initialize2(In)
Return bmp
End Sub
Sub btnQuit_Click
MainForm.Close
End Sub