|
|
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??)
|
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   |
Oblivion
Messages: 1200 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
Github page: https://github.com/ismail-yilmaz
upp-components: https://github.com/ismail-yilmaz/upp-components
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[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 #52689 is a reply to message #52688] |
Mon, 11 November 2019 12:06   |
 |
koldo
Messages: 3432 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 #52692 is a reply to message #52685] |
Mon, 11 November 2019 22:02   |
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
#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();
}
|
|
|
|
|
|
Goto Forum:
Current Time: Mon Apr 21 17:08:11 CEST 2025
Total time taken to generate the page: 0.02787 seconds
|
|
|