498 views
in GUI Development by
Hi gents,

 I'm using your PNGDecoder library. Trying to remember.. if I dynamically load a .png is there a way to find out its x,y size?

1 Answer

0 votes
by
Oh, it's working except for PngDecoder::externBitmap.LoadWebGL():

 

$if !$prototyper && ( $platform == *.WebGL.* )
var string name   = pure Name;
var handle handle = null;
var int32 frameX = RequestedFrameSize.x;
var int32 frameY = RequestedFrameSize.y;
var int32 format = (int32)pure Format;

FreeBitmap();

if ( name != "" )
{
  native ( name, handle, frameX, frameY, format )
  {
    if ( frameX > 0 && frameY > 0 )
    {
      // For frame sets an internal resource is created to allow the standard resource loading process.
      var bitmapRes = {};
      var res = {};

      if ( format === _unit.BitmapFormat.Alpha8 )
        res.Format = _app._PIXEL_FORMAT_ALPHA8;
      else
        res.Format = _app._PIXEL_FORMAT_NATIVE;
      res.FileName = name;
      res.NoOfFrames = this.RequestedNoOfFrames;
      res.FrameSize = this.RequestedFrameSize;
      res.FrameDelay = this.FrameDelay;
      res._this = null;

      bitmapRes._class = function() { return _app.Resources.Bitmap; };
      bitmapRes[0] = res;

      handle = _app._LoadBitmap( res, this );
    }
    else
    {
      handle = _app._LoadExternBitmap( name, this );
    }
  }
}

bitmap = handle;

// Ask the attributes of the loaded bitmap
if ( bitmap != null )
{
  var int32  noOfFrames = 1;
  var point  frameSize  = <0,0>;
  var int32  frameDelay = 0;

  handle = bitmap;

  native ( handle, noOfFrames, frameSize, frameDelay )
  {
    noOfFrames = handle.NoOfFrames;
    frameSize  = handle.FrameSize;
    frameDelay = handle.FrameDelay;
  }

  /* Copy the bitmap attributes into the bitmap object */
  pure FrameSize = frameSize;
  pure NoOfFrames = noOfFrames;
  pure FrameDelay = frameDelay;

  // Can the bitmap run an animation sequence?
  SetAnimated( ( pure FrameDelay > 0 ) && ( pure NoOfFrames > 1 ) );
}
else if ( DefaultBitmap != null )
{
  defaultBitmapUsed = true;
  bitmap = DefaultBitmap.bitmap;

  pure FrameSize = DefaultBitmap.FrameSize;
  pure NoOfFrames = DefaultBitmap.NoOfFrames;
  pure FrameDelay = DefaultBitmap.FrameDelay;
}

$else
trace "Method 'loadWebGL()' is called on a non WebGL profile!";
$endif

// Force all affected views to update their aspect
notifyobservers this;
by
I'm not specifying a frameSize. So "handle = _app._LoadExternBitmap( name, this );" must be where things are going wrong...?
by
Hi Mike,
for the PngDecoder you can set a RequestedFrameSize. This is used if you want to define a multi-frame bitmap. When the bitmap is loaded the real size is read from the image source and stored within FrameSize.
This works fine for the target devices where the PngDecoder is used. On WebGL the Browser is doing this job. So here this mechanism is not implemented.
Regards,
Rudolf
by
Hi Rudolf,
 Well I need to have functional equivalence between build types. How can I customize LoadExternBitmap() to return the PNG's dimensions?
by

Hi Mike,
did you trace the FrameSize of a bitmap after loading is done?
You can assign a slot to the OnUpdate property of the PngDecoder::ExternBitmap and add a trace here. Please let me know if you see the correct size?

by
I see it's part of emwi_9_30.js. Can you provide a modified CodeGenerator.wmw (?). Or can does this .js remain the same build after build, and I can modify it directly?
by
I am, both when I prototype and when I run on iMXRT1062. It's only WebGL not returning the values.

[6.12.2021  9:26:08] Trace Application::Help_Contextual.onUpdate (2:1) : trace: <700,1072>.
by
On WebGL the processing of the bitmap loading is handled by the browser async. So here you have to wait until the decoding job is done.
What you can do is to attach an observer on the ExternBitmap object. As soon as the attached slot is called, you can read the FrameSize from the bitmap.
by

What should I be observing on ExternBitmap? I tried FrameSize to no avail...

 

by

Please directly attach to the object by the statement:
attachobserver slot‑expression, object‑expression;

by
That worked! Thank you so much :)

Ask Embedded Wizard

Welcome to the question and answer site for Embedded Wizard users and UI developers.

Ask your question and receive answers from the Embedded Wizard support team or from other members of the community!

Embedded Wizard Website | Privacy Policy | Imprint

...