Using a Downloaded PNG in a Form Image Component

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
User avatar
aburnette
Posts: 7
Joined: Wed Dec 07, 2022 1:03 am
Location: Grocery Supply Company
Contact:

Using a Downloaded PNG in a Form Image Component

Post by aburnette »

I'm trying to get a downloaded image to load in a native local windows form without any additional web components.
I confirmed it downloads to my local tmp folder. Usually named something like swm.0, swm.1, etc. It is a PNG image.
Attempts to read the bitmap into a field or directly into the #ImageChart component are failing because the bitmap read is failing.
I'm not sure if it is expecting the path to be on the iSeries or something.
I commented out various things I've tried. Any idea what I'm doing wrong with the Bitmap loading from file?

SUBROUTINE name(REQUEST_CHART)
#LabelDebug.Caption := "Requesting chart for data."
#ImageRefresh.Visible := false
#ImageChart.Visible := true
#Request.DoGet( #W_CHART_URL )

IF (#Request.Response.IsSuccessfulRequest.isFalse) /* Request Failure */
#LabelDebug.Caption := "Failed with status code: " + #Request.Response.HttpStatusCode.AsString
#ImageChart.Visible := false
#ImageRefresh.Visible := true
RETURN
ENDIF

#STD_BLOB := #Request.Response.AsFile /* Stores to file in TMP folder */
#STD_STRNG := #STD_BLOB.FileName /* The Path to Where it was Stored */

* #W_CHART_BLOB := #STD_BLOB
* #ImageChart.FileName := #STD_STRNG
* #ImageChart.Image <= #SYS_APPLN.CreateBitmap( #STD_STRNG )
* #ImageChart.Image.FileName := #STD_BLOB.FileName
* #ImageChart.Image.StandardImage := #SYS_APPLN.CreateBitmap( #STD_STRNG )
* #Binary.FromFile Path(#STD_STRNG)
* #ImageChart.Image <= #SYS_APPLN.CreateBitmap( #STD_STRNG )
* #LabelDebug.Caption := #STD_STRNG + " W: " + #ImageChart.Image.Width.AsString + ", H: " + #ImageChart.Image.Height.AsString
* #ImageChart.UpdateDisplay
#Bitmap <= #Sys_Appln.CreateBitmap( #STD_BLOB )
#LabelDebug.Caption := #STD_STRNG + " W: " + #Bitmap.Width.AsString + ", H: " + #Bitmap.Height.AsString

ENDROUTINE
User avatar
aburnette
Posts: 7
Joined: Wed Dec 07, 2022 1:03 am
Location: Grocery Supply Company
Contact:

Re: Using a Downloaded PNG in a Form Image Component

Post by aburnette »

In regular Non-LANSA windows forms you have PictureBox and you can load an image from a URL using
pictureBox.Load(url)

In the LANSA RDML the Load function doesn't seem to be pulled though so
#ImageChart.Load( #W_CHART_URL )
Gives the "Feature name Load is not a member of component type PRIM_IMAG"

So that's why I'm downloading the image locally through XPRIM_HttpRequest (which works).
MarkDale
Posts: 116
Joined: Wed Dec 02, 2015 10:06 am

Re: Using a Downloaded PNG in a Form Image Component

Post by MarkDale »

Try:
#Bitmap.Image <= #Sys_Appln.CreateBitmap( #STD_BLOB )

Assuming #Bitmap is defined as a #Prim_IMAG
User avatar
Dino
Posts: 472
Joined: Fri Jul 19, 2019 7:49 am
Location: Robbinsville, NC
Contact:

Re: Using a Downloaded PNG in a Form Image Component

Post by Dino »

Just note a small comment in the guide:
https://docs.lansa.com/15/en/lansa016/c ... M_IMAG.htm

The PRIM_IMAG control will be used by default when dragging and dropping an image control from the Controls view in the IDE, unless the target render type is Win32.
NOTE: If your application is to execute SOLELY in Win32, you should use the image control: PRIM_IMGE.


Win32 refers to Windows in this case. So this code will work in a form/reusable part for windows:

Code: Select all

Function Options(*DIRECT)
Begin_Com Role(*EXTENDS #PRIM_FORM) ClientWidth(600) ClientHeight(600) ComponentVersion(2) Left(406) Top(176)
Define_Com Class(#Prim_Imge) Name(#ImageWin32) Parent(#COM_OWNER) DisplayPosition(1) TabPosition(1) Height(501) Left(6) Top(6) Width(609)

Evtroutine Handling(#com_owner.CreateInstance)
Fetch Fields(#xEmployeeImage) From_File(xEmployeeImages)
* or use a blob to take a file from disk... #xEmployeeImage := 'c:\temp\lansa1.jpg'
#ImageWin32.FileName := #xEmployeeImage
Endroutine
End_Com
to have this result:
prim_imgewindows.jpg
prim_imgewindows.jpg (281.54 KiB) Viewed 6760 times
Post Reply