How to imbed image on form

Windows specific forum
dchisholm
New User
New User
Posts: 7
Joined: Tue Mar 31, 2015 9:44 pm
Location: Ottawa, ON Canada
Contact:

How to imbed image on form

Post by dchisholm »

Folks,

I have a fairly simple form on which I want to drop the company logo as .PNG file. The problem is that when I compile the program and give the .EXE to the customer it references the original location of the image and so it appears as a blank image on the form.

Is there some way I could encapsulate an image file within the form so that it travels with the .EXE. I can covert the image to any other format.

Here's the code:

Code: Select all

;
; This code is automatically generated by the FormDesigner.
; Manual modification is possible to adjust existing commands, but anything else will be dropped when the code is compiled.
; Event procedures needs to be put in another source file.
;

Global Window_0

Global Image_0, Text_0, Start_Button, Status_Window, Text_1, Text_2

Global Img_Window_0_0

UsePNGImageDecoder()

Img_Window_0_0 = LoadImage(#PB_Any,"C:\Users\CA039461\Documents\PB\PFP\ba_logo.png")

Enumeration FormFont
  #Font_Window_0_0
  #Font_Window_0_1
EndEnumeration

LoadFont(#Font_Window_0_0,"Arial", 18, #PB_Font_Bold)
LoadFont(#Font_Window_0_1,"Arial", 12, #PB_Font_Bold)


Procedure OpenWindow_0(x = 0, y = 0, width = 590, height = 770)
  Window_0 = OpenWindow(#PB_Any, x, y, width, height, "Prepare for Print", #PB_Window_SystemMenu)
  SetWindowColor(Window_0, RGB(255,255,255))
  Image_0 = ImageGadget(#PB_Any, 60, 10, 470, 120, ImageID(Img_Window_0_0))
  Text_0 = TextGadget(#PB_Any, 70, 140, 450, 40, "Prepare for Print", #PB_Text_Center)
  SetGadgetColor(Text_0, #PB_Gadget_FrontColor,RGB(17,98,165))
  SetGadgetColor(Text_0, #PB_Gadget_BackColor,RGB(255,255,255))
  SetGadgetFont(Text_0, FontID(#Font_Window_0_0))
  Start_Button = ButtonGadget(#PB_Any, 230, 190, 100, 40, "Start")
  Status_Window = EditorGadget(#PB_Any, 20, 270, 550, 430)
  SetGadgetColor(Status_Window, #PB_Gadget_BackColor,RGB(255,255,255))
  Text_1 = TextGadget(#PB_Any, 20, 250, 550, 20, "Processing Status", #PB_Text_Center)
  SetGadgetColor(Text_1, #PB_Gadget_FrontColor,RGB(17,98,165))
  SetGadgetColor(Text_1, #PB_Gadget_BackColor,RGB(255,255,255))
  SetGadgetFont(Text_1, FontID(#Font_Window_0_1))
  Text_2 = TextGadget(#PB_Any, 20, 730, 550, 25, "", #PB_Text_Center)
  SetGadgetColor(Text_2, #PB_Gadget_FrontColor,RGB(0,0,0))
  SetGadgetColor(Text_2, #PB_Gadget_BackColor,RGB(255,255,255))
EndProcedure
Thanks.

/Dave
User avatar
chi
Addict
Addict
Posts: 1087
Joined: Sat May 05, 2007 5:31 pm
Location: Austria

Re: How to imbed image on form

Post by chi »

Take a closer look on CatchImage and IncludeBinary. They do exactly what you need!
Et cetera is my worst enemy
User avatar
spikey
Enthusiast
Enthusiast
Posts: 750
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: How to imbed image on form

Post by spikey »

Something like this in your case. However note that you will actually need to put the CatchImage line and the DataSection into a different file in order to prevent the form designer from breaking the code further down the line...

Code: Select all

;
; This code is automatically generated by the FormDesigner.
; Manual modification is possible to adjust existing commands, but anything else will be dropped when the code is compiled.
; Event procedures needs to be put in another source file.
;

Global Window_0

Global Image_0, Text_0, Start_Button, Status_Window, Text_1, Text_2

Global Img_Window_0_0

UsePNGImageDecoder()

Img_Window_0_0 = CatchImage(#PB_Any, ?ba_logo)

Enumeration FormFont
  #Font_Window_0_0
  #Font_Window_0_1
EndEnumeration

LoadFont(#Font_Window_0_0,"Arial", 18, #PB_Font_Bold)
LoadFont(#Font_Window_0_1,"Arial", 12, #PB_Font_Bold)


Procedure OpenWindow_0(x = 0, y = 0, width = 590, height = 770)
  Window_0 = OpenWindow(#PB_Any, x, y, width, height, "Prepare for Print", #PB_Window_SystemMenu)
  SetWindowColor(Window_0, RGB(255,255,255))
  Image_0 = ImageGadget(#PB_Any, 60, 10, 470, 120, ImageID(Img_Window_0_0))
  Text_0 = TextGadget(#PB_Any, 70, 140, 450, 40, "Prepare for Print", #PB_Text_Center)
  SetGadgetColor(Text_0, #PB_Gadget_FrontColor,RGB(17,98,165))
  SetGadgetColor(Text_0, #PB_Gadget_BackColor,RGB(255,255,255))
  SetGadgetFont(Text_0, FontID(#Font_Window_0_0))
  Start_Button = ButtonGadget(#PB_Any, 230, 190, 100, 40, "Start")
  Status_Window = EditorGadget(#PB_Any, 20, 270, 550, 430)
  SetGadgetColor(Status_Window, #PB_Gadget_BackColor,RGB(255,255,255))
  Text_1 = TextGadget(#PB_Any, 20, 250, 550, 20, "Processing Status", #PB_Text_Center)
  SetGadgetColor(Text_1, #PB_Gadget_FrontColor,RGB(17,98,165))
  SetGadgetColor(Text_1, #PB_Gadget_BackColor,RGB(255,255,255))
  SetGadgetFont(Text_1, FontID(#Font_Window_0_1))
  Text_2 = TextGadget(#PB_Any, 20, 730, 550, 25, "", #PB_Text_Center)
  SetGadgetColor(Text_2, #PB_Gadget_FrontColor,RGB(0,0,0))
  SetGadgetColor(Text_2, #PB_Gadget_BackColor,RGB(255,255,255))
EndProcedure


DataSection
  ba_logo:
  IncludeBinary "C:\Users\CA039461\Documents\PB\PFP\ba_logo.png"
EndDataSection
dchisholm
New User
New User
Posts: 7
Joined: Tue Mar 31, 2015 9:44 pm
Location: Ottawa, ON Canada
Contact:

Re: How to imbed image on form

Post by dchisholm »

Folks,

Thank you very much. That did the trick. I am coming from the VB5 world and so it takes a little getting used to the ways PureBasic does it stuff.

I am really enjoying working with the new compiler.

/Dave
User avatar
TI-994A
Addict
Addict
Posts: 2705
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: How to imbed image on form

Post by TI-994A »

spikey wrote:...you will actually need to put the CatchImage line and the DataSection into a different file in order to prevent the form designer from breaking the code further down the line...
Hi spikey. You're quite right about that.

However, Form Designer offers a method to include the CatchImage() directly into the form file, without having to include any separate files expressly for this purpose.

From the design view window, select the appropriate image gadget, then from its properties window, select the desired image. This would automatically insert a LoadImage() line into the form code.

Then, from the FORM menu, select IMAGE MANAGER, and from the dialog window that opens, select the CATCHIMAGE? checkbox of the image to be embedded. This would then legally insert the relevant CatchImage(), DataSection, and IncludeBinary commands directly into the form code.

Hope it helps. :D
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
spikey
Enthusiast
Enthusiast
Posts: 750
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: How to imbed image on form

Post by spikey »

TI-994A wrote: However, Form Designer offers a method to include the CatchImage() directly into the form file, without having to include any separate files expressly for this purpose.
I did know that once, but had forgotten, sigh... Perhaps I should have said that you will need to take steps to make sure that the default Form designer behaviour doesn't break your code further down the line...
Post Reply