Sub loadjpeg_button_Click
' choose a jpeg
ret = fd.Show("Choose a file to load:", "Okay", "Cancel", "", Null)
If ret = -3 OR fd.ChosenName = "" Then
Return
End If
If File.Exists(fd.FilePath, fd.ChosenName) = False Then
Msgbox(fd.ChosenName & " does not exist.", "")
Return
End If
inputjpegname = fd.ChosenName ' this holds the name of the file chosen
jpegdir = fd.FilePath
Dim in As InputStream
Dim out As OutputStream
Dim c As Canvas
Dim r As Rect
Dim w, h As Int
' as bmp is a local variable it will be GCed on exit reclaiming the memory as there will be no refence to it held
Dim bmp, bmp2 As Bitmap
jpg.Initialize("jpg")
c.Initialize(ImageView1)
in = File.OpenInput(fd.FilePath, fd.ChosenName)
Jpg.LoadJpegSizeOnly(in)
in = File.OpenInput(fd.FilePath, fd.ChosenName)
bmp = Jpg.LoadJpegSmaller(in, Jpg.JpegHeight/ImageView1.Height)
'out = File.OpenOutput(File.DirRootExternal, "Bmp.Jpg", False)
'bmp.WriteToStream(out, 100, "JPEG")
'out.Flush
'out.Close
Dim pixels(), pixelval, rd, gn, bl As Int
'originX = jpg.BmpWidth
'originY = jpg.BmpHeight
r.Initialize(0, 0, ImageView1.Width, ImageView1.Height)
c.DrawBitmap(bmp, Null, r) ' draw the smaller preview on screen
ImageView1.Invalidate
' *********
' From here on is the part that has the problem
pixels = Jpg.BmpPixels ' get the argb values for the original bitmap
Jpg.PixelsABGRtoARGB
' Test routine to alter some pixels values
For n2 = 0 To 10
For n = 0 To originX -1
pixelval = jpg.GetBmpPixel(n ,n2) ' get the argb value of pixel n,n2
pixelval = pixelval +75 ' add 75 to its value
jpg.SetBmpPixel(n,0, pixelval) ' replace the previous value for the pixel with the new one
Next
Next
'end test
Jpg.SetPixelsFromBmp(bmp)
bmp2 = jpg.GetBmpFromPixels
out = File.OpenOutput(File.DirRootExternal, "NEW_" & fd.ChosenName, False)
bmp2.WriteToStream(out, 100, "JPEG")
in.Close
out.Flush
out.Close
pixelval = jpg.GetBmpPixel(100 ,0)
Msgbox("Height = " & Jpg.JpegHeight & " Width = " & Jpg.JpegWidth & " Pixel argb = " & pixelval, "Jpeg details")
End Sub