Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat
RenderTarget probable issue - Gideros Forum

RenderTarget probable issue

tetnictetnic Member
edited July 5 in General questions
Hi all,

I'm trying to read the color values of a PNG, to do that I do the following:

- Load the image into a Bitmap
- Draw the bitmap inside a RenderTarget
- Then I read color values pixel by pixel

The problem is that RenderTarget seems to return wrong values for some pixels. Consider the following image



When calling RenderTarget:getPixel() on fully transparent pixels it returns the correct values for them (color = 0x000000, alpha = 0), but for other pixels that are "black" it returns again the previous values (color = 0x000000, alpha = 0).

Due to this fact I'm unable to distinguish between fully transparent pixels and opaque black ones.

Anyone have encountered the same issue and knows how to overcome this obstacle?

Thank you.
kisspng-pixel-art-naruto-minecraft-pixels-5aed419da73076.0677702115254982696848.png
1200 x 1200 - 11K

Comments

  • tetnictetnic Member
    Reading the sourcecode I also tried several values of "format" when loading the Texture, but nothing changed.
  • hgy29hgy29 Maintainer
    Take a look at PixelsClown example, it does what you are trying to do and it seems to work
  • tetnictetnic Member
    Ok, it is was due to a my fault when indexing the pixels inside a table.

    Thank you for your help.

    Likes: MoKaLux

    +1 -1 (+1 / -0 ) Share on Facebook
  • MoKaLuxMoKaLux Member
    edited July 2
    hello @tetnic as an exercise I tried to answer your question. I came up with this piece of code.

    Maybe that can help?
    local source = Bitmap.new(Texture.new("gfx/enemy01.png", true))
    local rt = RenderTarget.new(source:getWidth(), source:getHeight())
    local bmp = Bitmap.new(rt)
    bmp:setPosition(200, 0)
    stage:addChild(bmp)
    rt:draw(source)
     
    local pixels = {}
    local points = {}
     
    local t = 1
    for i = 1, bmp:getWidth() do
    	for j = 1, bmp:getHeight() do
    		local xcolor, xalpha = rt:getPixel(i, j)
    		table.insert(pixels, t, {color=xcolor, alpha=xalpha})
    		t += 1
    	end
    end
    for i = 1, #pixels do
    	local pixel = Pixel.new(pixels[i].color, pixels[i].alpha, 1, 1)
    	table.insert(points, #points + 1, pixel)
    end
     
    t = 1
    for i = 1, bmp:getWidth() do
    	for j = 1, bmp:getHeight() do
    		local point = points[t]
    		point:setPosition(i, j)
    		stage:addChild(point)
    		t += 1
    	end
    end

    PS: I don't know if it is clean code. Does it even answer your original question? I think I got lost here!

    Likes: antix

    +1 -1 (+1 / -0 ) Share on Facebook
  • tetnictetnic Member
    Hi @MoKaLux,

    Yes the code is clear and in general it is the same thing I do. Thank you for your help :smile:

    Mauro

    Likes: MoKaLux

    +1 -1 (+1 / -0 ) Share on Facebook
  • MoKaLuxMoKaLux Member
    edited July 2
    gideros is so much fun and I need to practice more so I went with some more: scaling.
    local source = Bitmap.new(Texture.new("gfx/enemy01.png", true))
    local rt = RenderTarget.new(source:getWidth(), source:getHeight())
    local bmp = Bitmap.new(rt)
    bmp:setPosition(200, 0)
    stage:addChild(bmp)
    rt:draw(source)
     
    local pixels = {}
    local points = {}
     
    local scale = 10
     
    local t = 1
    for i = 1, bmp:getWidth() do
    	for j = 1, bmp:getHeight() do
    		local xcolor, xalpha = rt:getPixel(i, j)
    		table.insert(pixels, t, {color=xcolor, alpha=xalpha})
    		t += 1
    	end
    end
    for i = 1, #pixels do
    	local pixel = Pixel.new(pixels[i].color, pixels[i].alpha, scale, scale)
    	table.insert(points, #points + 1, pixel)
    end
     
    t = 1
    for i = 1, bmp:getWidth() do
    	for j = 1, bmp:getHeight() do
    		local point = points[t]
    		point:setPosition(((i - 1) * scale) + 100, ((j - 1) * scale) + 100)
    		stage:addChild(point)
    		t += 1
    	end
    end

    Likes: antix

    image.png
    482 x 852 - 18K
    +1 -1 (+1 / -0 ) Share on Facebook
Sign In or Register to comment.