I have never tried using graphics and have hit a problem. I am trying to load a jpeg, alter some pixels argb values, then save the amended version.
I don't want the picture displayed, just to alter the values then save the new version. So I have tried the following code
The problem is that I cannot tell if this is working because although I get no errors there is no new file created (defaultexternal is my sd card and is writeable by my other applications although they write text this is my first try with graphics)
As I understand it the code above should get the value of pixel n and alter it, then create a new picture in bmp2 (dim'd as a bitmap of course) and write that to the sd card.
The original point was to learn about the argb values and how changing them affects the picture as I noticed the argb values could be of quite different length and originally just wanted to edit the rgb parts themselves not the alpha value but I do need to be able to save the amended picture.
So is there an obvious reason why despite no error messages no file is created?
Thanks.
Dave
Edit: I forgot to point out that jpg is dim'd as Jpeg using the jpeg library and that originally I did have it save to the sd card folder the original pic was in with some letters added to the originals name but that would give me a file not exists error saying that permission was denied (but I know the sd card is writeable with text files as a number of my apps do save to the sd card).
I don't want the picture displayed, just to alter the values then save the new version. So I have tried the following code
B4X:
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
The problem is that I cannot tell if this is working because although I get no errors there is no new file created (defaultexternal is my sd card and is writeable by my other applications although they write text this is my first try with graphics)
As I understand it the code above should get the value of pixel n and alter it, then create a new picture in bmp2 (dim'd as a bitmap of course) and write that to the sd card.
The original point was to learn about the argb values and how changing them affects the picture as I noticed the argb values could be of quite different length and originally just wanted to edit the rgb parts themselves not the alpha value but I do need to be able to save the amended picture.
So is there an obvious reason why despite no error messages no file is created?
Thanks.
Dave
Edit: I forgot to point out that jpg is dim'd as Jpeg using the jpeg library and that originally I did have it save to the sd card folder the original pic was in with some letters added to the originals name but that would give me a file not exists error saying that permission was denied (but I know the sd card is writeable with text files as a number of my apps do save to the sd card).
Last edited: