RGBSurface for iOS

I was thinking of making a simple drawing app for kids (nothing fancy, more or less an exercise)
But I see RGBSurface isn’t available for iOS Bitmap and/or Image.

Will this be added in the future?

Couldn’t you program vector graphics drawing instead?

http://documentation.xojo.com/index.php/FigureShape

Don’t thing they work in iOS.
Anyhow, I need bitmap RGBSurface. :slight_smile:

[quote=155611:@Christoph De Vocht]Don’t thing they work in iOS.
Anyhow, I need bitmap RGBSurface. :)[/quote]
Out of interest, why is bitmap a requirement?

If you take a peek at many kid drawing apps, you will notice they mostly use a black/white bitmap images so the kids can color it manually (for example by color filling parts).
That would be very hard to do with vectors. Correct me if I am wrong. :slight_smile:

[quote=155623:@Christoph De Vocht]If you take a peek at many kid drawing apps, you will notice they mostly use a black/white bitmap images so the kids can color it manually (for example by color filling parts).
That would be very hard to do with vectors. Correct me if I am wrong. :)[/quote]
I see. Even if vector programming floodfill would be easy, it would probably have to be a slow algorithm if it’s written in pure Xojo code so I think you might be wrong.

I was just curious more than anything. :slight_smile:

If your black and white image is actually a collection of white polygons with black border, then the opposite is true
Just change the fill colour and repaint.

But …if RGBSurface is missing, does that mean that .pixel(x,y) is also unavailable?

I’ve just trawled through the iOS docs.

I abandoned Corona because it didn’t offer the ability to get or set a pixel color, and waited patiently for years for Xojo to complete iOS.
I had readied myself to start all over again with Xojo iOS and so totally mothballed my Corona project.

Now it looks like Xojo doesn’t have this function either.
It can’t be impossible: there are plenty of image editors on the iPhone.
Whats the problem?

It is possible with declares. I’ll put together an example if you like.

That would be great. It is amazing that iOSGraphics has no pixel() method. It would seem so elementary.

Here you go:
https://www.dropbox.com/s/v5otcg1lhxcka9r/color%20at%20pixel.xojo_binary_project?dl=0
It works on both iOSGraphics and iOSImage. Just call img.Pixel(x,y) or g.Pixel(x,y) to get the color at the specified position. Enjoy!

Jason you rock!

Glad I could help!

[quote=155673:@Jason King]Here you go:
https://www.dropbox.com/s/v5otcg1lhxcka9r/color%20at%20pixel.xojo_binary_project?dl=0
It works on both iOSGraphics and iOSImage. Just call img.Pixel(x,y) or g.Pixel(x,y) to get the color at the specified position. Enjoy![/quote]

Thank you Jason. What would we do without your help ?

Hi Dave, my guess is that that code needs to be updated to support 64bit. I wrote it a while ago and if I remember correctly it won’t handle 64bit properly. Once I finish fixing the AVFoundation classes I’ll take a look at it, unless someone can fix it first?

Jason

Thank you Jason for creating your code! This is essential for a project I am working on - but having problems running more than 3080 times on the simulator before it shuts down. Is this related to the 64-bit challenge above? If not, any suggestions?
Thank you for all you are doing for XOJO iOS users!

Hi Jason

Hope you are still looking at these.

Have been using your code to get the Pixel value at a specific pixel in iOSImage

What I am wondering is about the differences I get when doing the “same” under OSX

So I do it via graphics.pixel in the OSX Console version as well, and via a Memory Block approach under Mac Desktop to bypass the Color Profile (Generic RGB) adjustments. I am reading a specific image into a Picture using Picture.Open
This delivers
Color at 0,0 : (203,207,193)
Color at 0,1 : (189,193,179)
Color at 1,0 : (207,211,197)
Color at 1,1 : (198,202,188)

I then did the iOS but just loaded the image into the project
Then I apply your approach using the iOSImage and get
Color at 0,0 : (180,197,192)
Color at 0,1 : (164,180,175)
Color at 1,0 : (185,202,196)
Color at 1,1 : (174,191,186)

I also checked the values at (x,y) 394,394 reports a value, but anything beyond that reports RGB(0,0,0)
Just looking at the relationship between Red Green Blue, I summised that the sequence is swapped.
Swapping it back and comparing to the Desktop and Console results I get
The rsulting differences are as follows
(r,g,b)
(11,10,13)
(14,13,15)
(11,9,12)
(12,11,14)

I’ve seen this pattern before and it was due to Xojo Mac desktop translating the RGB file values to RGB Generic and if you use RGBSurface.Pixel you get the RGB Generic values back

I then also do it with a drawpicture to a iOSBitmap and use the graphics pixel function and get
Color at 0,0 : (192,197,180)
Color at 0,1 : (0,0,0)
Color at 1,0 : (196,202,185)
Color at 1,1 : (0,0,0)
This swaps RGB around (back) for the first pixel, and there could be a hint here of what is going wrong?

Here is the iOS Code


  Using iOSPixelFunctions
  Using ColorExtensions // RGBAText just reports a RGBA as (r,g,b,a) as Text
  
  // We just want to insert the myTestImage to the Imageview
  dim endofline as Text = &u0A
  
  ImageView1.Image = myTestImage // this just etst the image works proeprly
  
  dim result as Text
  
  result = "Width: " + myTestImage.Width.ToText  // This reports the image width correctly as 395 
  result = result + endofline + "Color at 0,0 "  +myTestImage.Image.Pixel(0,0).RGBAText
  result = result + endofline + "Color at 0,1 "  + myTestImage.Image.Pixel(0,1).RGBAText
  result = result + endofline + "Color at 1,0 " + myTestImage.Image.Pixel(1,0).RGBAText
  result = result + endofline + "Color at 1,1 " + myTestImage.Image.Pixel(1,1).RGBAText
  
  dim myBitmap as new iOSBitmap (395,395,1.0,False)
  
  myBitmap.Graphics.DrawImage(myTestImage, 0,0)
  
  dim g as iOSGraphics = myBitmap.Graphics
  
  result = result + endofline + "Color at 0,0 "  +g.Pixel(0,0).RGBAText
  result = result + endofline + "Color at 0,1 "  + g.Pixel(0,1).RGBAText
  result = result + endofline + "Color at 1,0 " +g.Pixel(1,0).RGBAText
  result = result + endofline + "Color at 1,1 " + g.Pixel(1,1).RGBAText
  
  TextArea1.text =  result
  

Just to clarify I am looking at a jpg file, and the Photoshop on my Mac reports the same RGB values as the OSX console and Desktop approaches

What am I missing here?

Actually, what do I do to get at the pixels at the pre-RGB Generic conversion level?
(In Desktop, you can actually look at the memoryblock and there original RGB values are still there.)

Just a little extra info.

In the Desktop version, we actually convert the Picture to bitmap first as this get the correct pixel values
(That transalation is not available on iOS BitmapImage)

    dim mb1 as MemoryBlock
    dim mb2 as MemoryBlock
    dim mp as Ptr
    mb = self.image.GetData(Picture.FormatBMP)
    mb2 = mb.StringValue(54,(height)*(width) * 4) // this is a nifty shift of where to read the actual bytes.
    mp = mb

Courtesy of Alwyn Bester and Alain Bailleul Optimize speed of Picture to RGBA Memory…

Just some background

@Jason King Here you go:
https://www.dropbox.com/s/v5otcg1lhxcka9r/color%20at%20pixel.xojo_binary_project?dl=0

Are you not yet usable at 64 bits?

Are there other methods?