Loading a bitmap from USER partition to VC4

Hello,

I am trying to load a bitmap stored in a folder on the user partition to VC4. There may be a translation error in the help documentation for VA_LoadBitmap and VA_BlitBitmap because it says to use a pointer to a pointer of sVCBitmap. GUID fd1fd7c6-37db-46e9-8a47-2088277e8919

Notes:
The bitmap is stored on F:/Barcode/ and has the name Camera1.png. This image gets updated via FTP so it will need to be reloaded as needed.

When I set LoadBitmap to TRUE, i get an updated stVCBitmap1.vpInternalData. The other parts of the structure do not get updated. When setting ShowBitmap to TRUE, nothing happens on the HMI.

(Vars)
VAR CONSTANT
VISUALIZATION_NAME : STRING[80] := ‘FT50’;
DEV_BARCODE : STRING[16] := ‘Barcode’;//Assigned device in CPU config F:\Barcode
END_VAR

VAR
TestLoadBitmap : BOOL := 0;
strBitmap1 : STRING[80] := ‘’;
strBitmap1Path : STRING[80] := ‘’;
pBitmap : REFERENCE TO sVCBitmap;
stVCBitmap1 : {REDUND_UNREPLICABLE} sVCBitmap;
status_VA_LoadBitmap : UINT := 0;
TestShowBitmap : BOOL := 0;
status_VA_BlitBitmap : UINT := 0;
LoadBitmap : BOOL := 0;
ShowBitmap : BOOL := 0;
uiStatusAccess : UINT := 0;
uiStep : INT := 0;
uiStatus : UINT := 0;
END_VAR

IF (VC_HANDLE = 0) THEN
	VC_HANDLE := VA_Setup(1, VISUALIZATION_NAME);	
END_IF

IF (VC_HANDLE <> 0) THEN
	uiStatusAccess := VA_Saccess(1, VC_HANDLE);	
	IF (uiStatusAccess = 0) THEN
		
		CASE uiStep OF
			
			0: 	(* Wait State*)
				IF LoadBitmap THEN
					LoadBitmap := FALSE;
					strBitmap1 := 'Camera1.png';
					strBitmap1Path := 'Barcode/Camera1.png';
					stVCBitmap1.vpInternalData := 0;//Need to initialize to zero when loading
					//stVCBitmap1.vpData := 
					uiStep := 1;
				ELSIF ShowBitmap THEN
					ShowBitmap := FALSE;
					uiStep := 2;
				END_IF
			1://Load bitmap
				//uiStatus := VA_LoadBitmap(1,VC_HANDLE,DEV_BARCODE,strBitmap1,ADR(pBitmap ));
				uiStatus := VA_LoadBitmap(enable := 1,VCHandle := VC_HANDLE,ucDevice := DEV_BARCODE,ucPath := strBitmap1,ppBitmap := ADR(stVCBitmap1));
				IF (uiStatus = 0) THEN
					uiStep := 0;
				ELSIF (uiStatus = 7000) THEN
					(*Busy*)
				ELSE(*Go to Error Step*)
					uiStep := 10;
				END_IF
			2://Blit bitmap (show on HMI)
				//uiStatus := VA_BlitBitmap(1,VC_HANDLE,ADR(pBitmap), 100, 100, 0,0,0,0,0);
				uiStatus := VA_BlitBitmap(1,VC_HANDLE,ADR(stVCBitmap1), 100, 100,0,0,0,0,0);
				IF (uiStatus = 0) THEN
					uiStep := 0;
				ELSIF (uiStatus = 7000) THEN
					(*Busy*)
				ELSE(*Go to Error Step*)
					uiStep := 10;
				END_IF					
		END_CASE
		VA_Srelease(1, VC_HANDLE);
	END_IF
END_IF

Hi Curtis,
I reviewed a little bit your code and I was able to see a bitmap in my visualization:


____LOAD.zip (1.3 KB)

Ciao
Valerio

1 Like

Thank you Valerio,

I was able to get my image to load with your changes. I also changed to a bmp because the png colors didn’t match the VC profile. Here is my working test code.

strBitmap1 := ‘Camera1.bmp’;

IF (VC_HANDLE = 0) THEN
	VC_HANDLE := VA_Setup(1, VISUALIZATION_NAME);	
END_IF

IF (VC_HANDLE <> 0) THEN
	uiStatusAccess := VA_Saccess(1, VC_HANDLE);	
	IF (uiStatusAccess = 0) THEN
		
		CASE uiStep OF
			
			0: 	(* Wait State*)
				IF LoadBitmap THEN
					LoadBitmap := FALSE;
					strBitmap := strBitmap1;
					stVCBitmap1.vpInternalData := 0;//Need to initialize to zero when loading
					uiStep := 1;
				ELSIF ShowBitmap THEN
					ShowBitmap := FALSE;
					uiStep := 2;
				END_IF
			1://Load bitmap
				uiStatus := VA_LoadBitmap(enable := 1,VCHandle := VC_HANDLE,ucDevice := DEV_BARCODE,ucPath := strBitmap,ppBitmap := ADR(ppBitmap));
				IF (uiStatus = 0) THEN
					uiStep := 2;
				ELSIF (uiStatus = 7000) THEN
					(*Busy*)
				ELSE(*Go to Error Step*)
					uiStep := 10;
				END_IF
			2://Blit bitmap (show on HMI)
				uiStatus := VA_BlitBitmap(1,VC_HANDLE,ppBitmap, 0, 0,0,0,50,50,0);
				IF (uiStatus = 0) THEN
					uiStep := 3;
				ELSIF (uiStatus = 7000) THEN
					(*Busy*)
				ELSE(*Go to Error Step*)
					uiStep := 10;
				END_IF	
			3: //Free bitmap
				uiErrorBitmapFromFile := VA_FreeBitmap(1, VC_HANDLE, ADR(ppBitmap));
				IF (uiErrorBitmapFromFile = 0) THEN
					uiStep := 0;
					ppBitmap := ADR(pBitmap);(* Reinitialize ppBitmap to have the possibility to use it again *)
					//LoadBitmap := TRUE;
				END_IF				
		END_CASE
		VA_Srelease(1, VC_HANDLE);
	END_IF
END_IF