setStroke() and BitmapTexture

Dear devs,

I am struggling with setStroke() and setFill() in combination with a BitmapTexture. I am tryong to apply a striped pattern to my graphics.

I have generated a png which I load from resources as "diagmask". It looks like:

Then I generate a new BitmapTexture from it. I Draw a red line and then over the red line I draw the same line with the texture:

dc.setColor( Gfx.COLOR_RED, Gfx.COLOR_TRANSPARENT );
dc.setPenWidth(20);
dc.drawLine(0, 218, 218, 218);
var options = {
    :bitmap => diagmask,
    :offsetX => 0,
    :offsetY => 0
};
var myMask = new Gfx.BitmapTexture(options);
dc.setStroke(myMask);
dc.drawLine(0, 218, 218, 218);

The result ist:

Which confuses me. I also tried using transparency in the png which didn't help much either. Why are the stripes light red? I feel like I have not understood the concept of this texturing at all. Can someone help?

Thank y'all so much!

  • Hi and thanks for your reply Slight smile

    I was expecting the white parts to be fully white, and the rest to remain red (as it did).

    I thought i can make a kind of pattern that i can draw. All I seem to get is a half transparent pixel for every white pixel in the texture and nothing for the rest (I tried gradients, too).

    setBlendMode also doesn't change anything here.

    What is the inteded use for this?

    Thank you so mich!

  • Are you doing this in the sim or on a real device?  These calls are only for CIQ 4 devices, which have a GPU, so there could be a bug someplace.  I for one am not sure what they are supposed to do.  Not sure but maybe has played with them a bit,

  • Hi! Well you're right I haven't tried it on my epix-2 yet (which should be capable). I'll see if the results are the same as in the sim and report back.

    So far these features seem to be rarely used... I was trying to implement a shutter effect (stripes) and thought that would be the easiest way... 

  • Hi BobMiles.

    From what I can see, you're drawing 2 lines. The first is a 20px thick red line, then you are drawing a bitmap textured line over the top of it.

    Here's an example I've put together using this attached 20px "checkboard" texture, half white and half transparent.

          var dw = dc.getWidth();
          var dh = dc.getHeight();
          var dw_h = dw/2;
          var dh_h = dh/2;
    
          // define our texture
          var texture = new Graphics.BitmapTexture({
            :bitmap => b_checkerboard,
            :offsetX => 5,
            :offsetY => 5
          });
    
          // set a side width
          var side_width = (count%20)*10;
    
          // draw a red box
          dc.setColor( Gfx.COLOR_RED, Gfx.COLOR_TRANSPARENT );
          dc.setPenWidth(2);
          dc.drawRectangle(dw_h-(side_width/2),dh_h-(side_width/2),side_width,side_width);
    
          // draw the textured box
          dc.setStroke(texture);
          dc.drawRectangle(dw_h-(side_width/2),dh_h-(side_width/2),side_width,side_width);
    
          count++;
    

    This is a 2px red rectangle, with a second 2px textured rectangle rendered over the top. The transparent part of the texture shows the underlying red rectangle;

    This is only the second textured rectangle, you'll notice that the transparent part of the texture shows the underlying background;

    Hope that helps! Let me know if you need further explaination.

  • Hi and thank you so much for your detailed answer.

    This is exactly what I inteded to do - and I think I'm doing the same as you do but with different result.

    Could you maybe attach your texture file?

    I have attached mine here (diag52x52.png) this one has white stripes and transparent stripes diag52x52.zip

    I load it from drawables with:

    <bitmap id="DIAG" filename="diag52x52.png" />

    and then

    diagmask = UI.loadResource( Rez.Drawables.DIAG );

    Then I draw a rectangle in red and over it with the texture:

    var texture = new Gfx.BitmapTexture({
        :bitmap => diagmask,
        :offsetX => 5,
        :offsetY => 5
    }); 
    dc.setColor( Gfx.COLOR_RED, Gfx.COLOR_TRANSPARENT );
    dc.setPenWidth(2);
    dc.drawRectangle(100,100,100,100);
    dc.setStroke(texture);
    dc.drawRectangle(100,100,100,100);

    But contrary to yours, it results in:

    Maybe I'm doing something wrong generating the texture in Gimp?

    Thank you so much,

    Bob

  • Hi Bob,

    You should define the packing format for the resource. I believe that without the packing format, there is a problem with utilising the resource as a bitmap texture, ie;

    <bitmap id="resource_id" filename="bitmaps/diag52x52.png" packingFormat="png"/>

    This seems to be a bug, which I have raised. Here's what it looks like with your texture file when utilising the correct packing format;

    Let me know if this fixes your issue.

  • Thank you so much! That was it! Now everything is working as expected! I would not have found that on my own! 

    Thanks again for your time and work!! 

  • What SDK were you using when you first encountered this?