Dim pixelval As Int
' Test routine to alter some pixels values
For n = 0 To originX -1
pixelval = jpg.GetBmpPixel(n ,0)
pixelval = pixelval + 75
jpg.SetBmpPixel(n,0, pixelval) ' change the specified pixels value
Next
out = File.OpenOutput(File.DirDefaultExternal, "NEW.Jpg", False)
bmp2 = jpg.GetBmpFromPixels ' make new picture based on amended data
bmp2.WriteToStream(out, 100, "JPEG")
in.Close
out.Flush
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
pixels = Jpg.BmpPixels ' get the argb values for the original bitmap
pixelval = jpg.GetBmpPixel(100,100) ' get the argb value of pixel 100,100
pixelval = pixelval +75 ' add 75 to its value
jpg.SetBmpPixel(100,100, pixelval) ' replace value for the pixel with new one
Jpg.SetPixelsFromBmp(bmp)
Jpg.PixelsABGRtoARGB
bmp2 = jpg.GetBmpFromPixels
You haven't fixed the problem I already pointed out. Put Jpg.SetPixelsFromBmp(bmp) in the correct place.
which I took to mean that the SetPixels command must be called first and then after that call PixelsABGRtoARGB, and in the new code snippet that I posted in my previous post SetPixelsFromBmp is on the line before PixelsABGRtoARGB....Jpg.SetPixelsFromBmp(bmp) is in the wrong place. It should be before Jpg.PixelsABGRtoARGB
Jpg.SetPixelsFromBmp(bmp)
Jpg.PixelsABGRtoARGB
bmp2 = jpg.GetBmpFromPixels
You moved the wrong line. I said it was Jpg.SetPixelsFromBmp(bmp) that was in the wrong place but you moved Jpg.PixelsABGRtoARGB!
Check out the new demo in the archive, it should be clearer there.
Jpg.SetPixelsFromBmp(bmp)
pixels = Jpg.BmpPixels
Jpg.PixelsABGRtoARGB ' overcomes a longstanding bug in Android
bmp2 = jpg.GetBmpFromPixels
Jpg.SetPixelsFromBmp(bmp)
Jpg.PixelsABGRtoARGB
bmp2 = jpg.GetBmpFromPixels
Jpg.SetPixelsFromBmp(bmp)
Jpg.PixelsABGRtoARGB ' overcomes a longstanding bug in Android
' play with pixel component values
Dim pixelval, alpha, rd, gn, bl As Int
Jpg.SetBmpPixel(0, 0, Colors.ARGB(255, 192, 128, 64)) ' set a pixel
pixelval = Jpg.GetBmpPixel(0, 0) ' get a pixel
alpha = Bit.UnsignedShiftRight(Bit.And(pixelval, 0xff000000), 24)
rd = Bit.UnsignedShiftRight(Bit.And(pixelval, 0xff0000), 16)
gn = Bit.UnsignedShiftRight(Bit.And(pixelval, 0xff00), 8)
bl = Bit.And(pixelval, 0xff)
Log("ARGB = " & alpha & "," & rd & "," & gn & "," & bl)
' draw line
Dim i As Int
For i = 0 To 100
Jpg.SetBmpPixel(i, i, Colors.Cyan)
Next
' if you need to you can get the pixels as an array of Ints
Dim pixels() As Int
pixels = Jpg.BmpPixels
' draw line
Dim i As Int
For i = 0 To 100
pixels(i)= Colors.Yellow
Next
'save the changed bitmap
bmp2 = jpg.GetBmpFromPixels
out = File.OpenOutput(File.DirRootExternal, "Bmp2.Jpg", False)
bmp2.WriteToStream(out, 100, "JPEG")
in.Close
out.Flush
out.Close
The first thing you need to do is load the pixel array from a bitmap (although as noted in the help it is not needed if you have used LoadJpegArea). Then do the manipulation. Then save it. Why is this so difficult?
I don't see the code you attribute to me in the new demo.
Jpg.SetBmpPixel(0, 0, Colors.ARGB(255, 192, 128, 64)) ' set a pixel
That's why I put it in. You should be able to take it from there.the additional code looks like what I have been trying to achieve unsucessfully all along.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?