Page 1 of 1

How to read a point() from catchimage (from datasection) in startdrawing?

Posted: Sun Mar 10, 2024 11:33 am
by T4r4ntul4
I probably miss something crucial here, but i cant see what. Iam trying now for hours, with no progress.

I make a image: #test_image1 and try to draw a image from datasection in it. Then i try to debug the color from a chosen point, for some reason i dont understand, gives it 0 back. While the color is red.

my goal here is to read all the points (colors) from the image and put it in a array.

(i found some forum posts from 2012, but that didnt work for me)

Any help is appreciated!


schuinestreep.png:
Image

code:

Code: Select all

Enumeration
  #test_image1
  #Image_Schuinestreep
EndEnumeration

DataSection
  schuinestreep:
  IncludeBinary "Data_ImageTools/acties/polygon/fillins/schuinestreep.png"
EndDataSection


Dim image_pixel_data.l(29, 29)

CreateImage(#test_image1, 30, 30, 32, #PB_Image_Transparent)


If StartDrawing(ImageOutput(#test_image1))
    
  DrawImage(ImageID(CatchImage(#Image_Schuinestreep, ?schuinestreep)), 0, 0)
  
  x = 0
  y = 0
    
  Debug Red(Point(x, y))
  Debug Green(Point(x, y))
  Debug Blue(Point(x, y))
  Debug Alpha(Point(x, y))
    
;   For x = 0 To 29
;     For y = 0 To 29
;       image_pixel_data(x, y) = Point(x, y)
;     Next y
;   Next x
    
  StopDrawing()
EndIf


Re: How to read a point() from catchimage (from datasection) in startdrawing?

Posted: Sun Mar 10, 2024 11:58 am
by STARGĂ…TE
  1. If you want to load a PNG image, you need UsePNGImageDecoder()
  2. If you use CatchImage() with a static constant, it returns already the ImageID, an additional ImageID() is not needed.
  3. Alternatively, you can first catch the image, and later use the ImageID:

    Code: Select all

    CatchImage(#Image_Schuinestreep, ?schuinestreep)
    DrawImage(ImageID(#Image_Schuinestreep), 0, 0)
    

Code: Select all

Enumeration
  #test_image1
  #Image_Schuinestreep
EndEnumeration

DataSection
  schuinestreep:
  IncludeBinary "Data_ImageTools/acties/polygon/fillins/schuinestreep.png"
EndDataSection

UsePNGImageDecoder()

Dim image_pixel_data.l(29, 29)

CreateImage(#test_image1, 30, 30, 32, #PB_Image_Transparent)
CatchImage(#Image_Schuinestreep, ?schuinestreep)

If StartDrawing(ImageOutput(#test_image1))
    
  DrawImage(ImageID(#Image_Schuinestreep), 0, 0)
  
  x = 0
  y = 0
    
  Debug Red(Point(x, y))
  Debug Green(Point(x, y))
  Debug Blue(Point(x, y))
  Debug Alpha(Point(x, y))
    
;   For x = 0 To 29
;     For y = 0 To 29
;       image_pixel_data(x, y) = Point(x, y)
;     Next y
;   Next x
    
  StopDrawing()
EndIf

Re: How to read a point() from catchimage (from datasection) in startdrawing?

Posted: Sun Mar 10, 2024 12:07 pm
by T4r4ntul4
Thank you for your fast reply, it works!

Re: How to read a point() from catchimage (from datasection) in startdrawing?

Posted: Sun Mar 10, 2024 12:17 pm
by infratec
You should always:

1. Check the return values of procedures
2. Use EnableExplicit

Than you would have noticed, that already your CatchImage() failed.