Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » [SOLVED]How I can put an image in a form like a splash screen?? ([SOLVED]How I can put an image in a form like a splash screen??)
[SOLVED]How I can put an image in a form like a splash screen?? [message #52685] Sun, 10 November 2019 22:56 Go to next message
fasasoftware is currently offline  fasasoftware
Messages: 15
Registered: July 2019
Location: Italy
Promising Member
How I can put an image in a form like a splash screen??

i'm trying to load an image into a form but without success....

i'm using TheIde 13664 version on macos x 10.13.6

Can somebody help me with a little example...???


Best regards,

Lestroso Embarassed

[Updated on: Tue, 12 November 2019 18:07]

Report message to a moderator

Re: How I can put an image in a form like a splash screen?? [message #52686 is a reply to message #52685] Sun, 10 November 2019 23:16 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 1091
Registered: August 2007
Senior Contributor
Hello Lestroso,

Welcome to the U++ forums.

There are several ways, but the simplest and IMO most robust way to display static images is using the StreamRaster interface.
U++ is using a "plugin" system to decode registered raster files. By default it can decode and display png and bmp files but
by adding plugin packages (in plugin/ folser) to your application can decode other formats such as jpg too:

Here is an example. An image viewer (png, bmp, jpg)

#include <CtrlLib/CtrlLib.h>

#include <plugin/jpg/jpg.h> // <- Also add plugin/jpg to your package if you want jpg support.

using namespace Upp;

struct ImageViewer : TopWindow {
	Image img;
	void Paint(Draw& w) override
	{
		if(!IsNull(img)) w.DrawImage(0, 0, img);
	}

	ImageViewer()
	{
		Title(t_("Image viewer (Press CTRL + O to open an image file)"));
		Sizeable().Zoomable().CenterScreen().SetRect(0, 0, 640, 200);
	}
	
	bool Key(dword key, int count) override
	{
		if(key == K_CTRL_O) {
			img = StreamRaster::LoadFileAny(SelectFileOpen("*.jpg *.png *.bmp"));
			if(!IsNull(img))
				SetRect(Rect(GetRect().TopLeft(), img.GetSize()));
		}
		return true;
	}
};

GUI_APP_MAIN
{
	ImageViewer().Run();
}




Best regards,
Oblivion


[Updated on: Sun, 10 November 2019 23:17]

Report message to a moderator

Re: How I can put an image in a form like a splash screen?? [message #52687 is a reply to message #52686] Mon, 11 November 2019 07:47 Go to previous messageGo to next message
fasasoftware is currently offline  fasasoftware
Messages: 15
Registered: July 2019
Location: Italy
Promising Member
Thank you Oblivion....but i would like to know how i can call an image directly, without opening via a choice menu or button.....for example this instruction: draw image "pippo.jpg" ...i cant see also in the form designer...best regards lestroso
Re: How I can put an image in a form like a splash screen?? [message #52688 is a reply to message #52687] Mon, 11 November 2019 08:15 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 1091
Registered: August 2007
Senior Contributor
The idea is same.

struct SplashScreen : TopWindow {
	Image img;
	void Paint(Draw& w) override
	{
		if(!IsNull(img)) w.DrawImage(0, 0, img);
	}

	SplashScreen()
	{
		img = StreamRaster::LoadFileAny("/home/user/mypicture.png");
		CenterScreen().SetRect(img.GetSize());
	}
};


The problem is if you are calling the system draw (via Ctrl::Paint) then the image should better be opened elsewhere, as I did above, otherwise it will hurt performance (on every single refresh the file will be reloaded, and decoded.

Best regards,
Oblivion



Re: How I can put an image in a form like a splash screen?? [message #52689 is a reply to message #52688] Mon, 11 November 2019 12:06 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
In addition you can embed the image in your exe, using the BRC feature.
You just creat a .brc file that you add to your project, just with this, for example ("MyImages.brc"):
BINARY(MyImage, "myimagefile.jpg")


And in your .cpp code, put this:
#include "MyImages.brc"
...
img = StreamRaster::OpenAny(String(MyImage, MyImage_length));


Best regards
Iñaki

[Updated on: Mon, 11 November 2019 12:07]

Report message to a moderator

Re: How I can put an image in a form like a splash screen?? [message #52691 is a reply to message #52685] Mon, 11 November 2019 17:17 Go to previous messageGo to next message
fasasoftware is currently offline  fasasoftware
Messages: 15
Registered: July 2019
Location: Italy
Promising Member
Dear Oblivion and Koldo....Thanks a lot for your help and answers..

Now, i'll try to make your ideas suggestions...in action...

I thank you a lot again.. i appriciate a lot your time dedicated to me....

Best regards,

Lestroso Razz

Re: How I can put an image in a form like a splash screen?? [message #52692 is a reply to message #52685] Mon, 11 November 2019 22:02 Go to previous messageGo to next message
fasasoftware is currently offline  fasasoftware
Messages: 15
Registered: July 2019
Location: Italy
Promising Member
Dear Koldo,

i have tryed your suggestion idea...but without success...

i have try to follow that you tell me but i cant include my image in the exe or app...or better my mac give an error... i enclose here the list of code and the error screenshot...

Can you bemore prececise please???' Thanks a lot...Lestroso Smile

#include <CtrlLib/CtrlLib.h>

#include "MyImage.brc"


using namespace Upp;

struct SplashScreen : TopWindow {
	Image img;
	void Paint(Draw& w) override
	{
		if(!IsNull(img)) w.DrawImage(0, 0, img);
	}

	SplashScreen()
	{
	img = StreamRaster::OpenAny(String(MyImage, MyImage_length));
		CenterScreen().SetRect(img.GetSize());
	}
};

GUI_APP_MAIN
{
	SplashScreen().Run();
}






And also dear Oblivion,
i have had success after a lot of time that i'm trying to follow your code...this works fine for me:
but i have had to include in the pack manager :Core,CtrlCore,CtrlLib,Draw,Painter,PdfDraw,Richtext,plugin/ bmp,plugin/jpg,plugin/png.


#include <CtrlLib/CtrlLib.h>

using namespace Upp;

struct SplashScreen : TopWindow {
	Image img;
	void Paint(Draw& w) override
	{
		if(!IsNull(img)) w.DrawImage(0, 0, img);
	}

	SplashScreen()
	{
		img = StreamRaster::LoadFileAny("/Users/pippo/Desktop/SplashScreenFasa/FasaSplash.jpg");
		CenterScreen().SetRect(img.GetSize());
	}
};

GUI_APP_MAIN
{
	SplashScreen().Run();
}
Re: How I can put an image in a form like a splash screen?? [message #52694 is a reply to message #52692] Tue, 12 November 2019 08:38 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hi Lestroso

Here I enclose you the demo ready. The code uses LoadStringAny() instead of OpenAny() (my fault).
  • Attachment: Lestroso.7z
    (Size: 5.43KB, Downloaded 184 times)


Best regards
Iñaki
Re: [SOLVED]How I can put an image in a form like a splash screen?? [message #52698 is a reply to message #52685] Tue, 12 November 2019 18:10 Go to previous messageGo to next message
fasasoftware is currently offline  fasasoftware
Messages: 15
Registered: July 2019
Location: Italy
Promising Member
THOUSAND THANKS KOLDO!!!!

You solved my problem...ok now it's clear..but i'm a newbie..i must study again this beautiful tool...

I have succeded to compile your example!

Thanks again,

Lestroso Laughing Laughing Laughing
Re: [SOLVED]How I can put an image in a form like a splash screen?? [message #52703 is a reply to message #52698] Wed, 13 November 2019 07:47 Go to previous message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Cool Smile

Best regards
Iñaki
Previous Topic: How to include files .h or .cpp as external library?
Next Topic: How I can load inside Utimate++ RayLib For MacOs And Win?
Goto Forum:
  


Current Time: Thu Mar 28 21:07:25 CET 2024

Total time taken to generate the page: 0.01426 seconds