var path = "/Sys/Img/Hello.png"
var array, img;
function OnStart()
{
img = app.CreateImage(path);
var str = GetImageString(img);
// when str retrieved from database
var data = JSON.parse( str )
var newImg = app.CreateImage( null, data.width, data.height, "px" );
newImg.SetPixelData( data.png64,data.width,data.height,"px" );
var lay = app.CreateLayout( "Linear", "VCenter,FillXY" );
alert( newImg.GetWidth());
lay.AddChild( newImg );
app.AddLayout( lay );
}
function GetImageString(img)
{
var w = img.GetAbsWidth();
var h = img.GetAbsHeight();
var png = img.GetPixelData("pngBase64", 0, 0, w, h);
var ret = { };
ret.width = w;
ret.height = h;
ret.png64 = png;
return JSON.stringify(ret);
}
pngBase64 is just the way it it encoded from the img control.
I chose it because it is lossless and the new image should be identical to the old.