Home » U++ Library support » RichText,QTF,RTF... » Loading Image into qtf
Loading Image into qtf [message #9913] |
Fri, 08 June 2007 12:18 |
guido
Messages: 169 Registered: April 2006
|
Experienced Member |
|
|
#include <CtrlLib/CtrlLib.h>
using namespace Upp;
GUI_APP_MAIN
{
DrawingDraw dw(500, 500);
Image img = StreamRaster::LoadFileAny("/home/guido/work/panna_cotta_espresso_02.jpg");
dw.DrawImage(500, 500, img);
QtfRichObject pict(CreateDrawingObject(dw.GetResult(), Size(900, 600), Size(900, 600)));
String qtf;
qtf << pict;
PromptOK(qtf);
}
The above gives me nothing but a white square.
I checked in the debugger that img is created properly, so why is it not drawn into the DrawingDraw object?
Another question. How do I save images into a sql(lite) database - SaveImageAsString()?
Guido
|
|
|
Re: Loading Image into qtf [message #9918 is a reply to message #9913] |
Fri, 08 June 2007 15:58 |
|
mirek
Messages: 13975 Registered: November 2005
|
Ultimate Member |
|
|
try
dw.DrawImage(0, 0, img);
(You are drawing outside the area at 500, 500).
Or perhaps you really wanted
dw.DrawImage(0, 0, 500, 500, img)
- stretches the image to fill the area.
Anyway, that is still too ineffective, there is a nice function:
RichObject CreateImageObject(const Image& img, int cx = 0, int cy = 0);
which produces RichObject directly, without the need of ImageDraw.
For storing into DB, you can use what you suggest (which reperesents "internal" U++ image format), or you can use any StreamRasterEncoder and SaveString method.
See reference/ImageEncoders - just use SaveString to store to String instead of SaveFile (which stores to file).
|
|
|
Re: Loading Image into qtf [message #9925 is a reply to message #9918] |
Sat, 09 June 2007 14:18 |
guido
Messages: 169 Registered: April 2006
|
Experienced Member |
|
|
luzr wrote on Fri, 08 June 2007 15:58 | try
dw.DrawImage(0, 0, img);
(You are drawing outside the area at 500, 500).
Or perhaps you really wanted
dw.DrawImage(0, 0, 500, 500, img)
- stretches the image to fill the area.
Anyway, that is still too ineffective, there is a nice function:
RichObject CreateImageObject(const Image& img, int cx = 0, int cy = 0);
which produces RichObject directly, without the need of ImageDraw.
For storing into DB, you can use what you suggest (which reperesents "internal" U++ image format), or you can use any StreamRasterEncoder and SaveString method.
See reference/ImageEncoders - just use SaveString to store to String instead of SaveFile (which stores to file).
|
Playing with the sample code, I forgot to include jpg plugin
Wonder why there is no error in that case...
So, alright. That is working now.
But no success yet, getting an Image instance back from the sqlite BLOB string.
jpg.LoadString() returns an empty Image instance.
I get a string beginning with "\377" from the query, but the decoder doesn't seem to like it.
Btw. I'm using sqlite3 C-API directly now, since the abstraction layer only got in my way while learning SQL. Absence of upp documentation in this regard didn't help either.
PS:
Found a great online resource for learning SQL:
"Akeel Din, SQL - A Practical Introduction"
Guido
|
|
|
|
Re: Loading Image into qtf [message #11211 is a reply to message #9925] |
Mon, 27 August 2007 19:32 |
|
forlano
Messages: 1182 Registered: March 2006 Location: Italy
|
Senior Contributor |
|
|
[quote title=guido wrote on Sat, 09 June 2007 14:18]luzr wrote on Fri, 08 June 2007 15:58 | try
dw.DrawImage(0, 0, img);
(You are drawing outside the area at 500, 500).
Or perhaps you really wanted
dw.DrawImage(0, 0, 500, 500, img)
- stretches the image to fill the area.
Anyway, that is still too ineffective, there is a nice function:
RichObject CreateImageObject(const Image& img, int cx = 0, int cy = 0);
which produces RichObject directly, without the need of ImageDraw.
Guido
|
Hello Guido,
I am facing your same problem, that to load a file image in a qtf document. It seems you have resolved this problem.
If you have still the correct test case may I ask you to post it?
Many thanks,
Luigi
|
|
|
Re: Loading Image into qtf [message #11212 is a reply to message #11211] |
Mon, 27 August 2007 19:57 |
|
forlano
Messages: 1182 Registered: March 2006 Location: Italy
|
Senior Contributor |
|
|
[quote title=forlano wrote on Mon, 27 August 2007 19:32]guido wrote on Sat, 09 June 2007 14:18 |
luzr wrote on Fri, 08 June 2007 15:58 | try
dw.DrawImage(0, 0, img);
(You are drawing outside the area at 500, 500).
Or perhaps you really wanted
dw.DrawImage(0, 0, 500, 500, img)
- stretches the image to fill the area.
Anyway, that is still too ineffective, there is a nice function:
RichObject CreateImageObject(const Image& img, int cx = 0, int cy = 0);
which produces RichObject directly, without the need of ImageDraw.
Guido
|
Hello Guido,
I am facing your same problem, that to load a file image in a qtf document. It seems you have resolved this problem.
If you have still the correct test case may I ask you to post it?
Many thanks,
Luigi
|
No prob, I found the answer just in the reference:
#include <CtrlLib/CtrlLib.h>
using namespace Upp;
GUI_APP_MAIN
{
DrawingDraw dw(500, 500);
Image img = StreamRaster::LoadFileAny("C:\\MyApps\\qtfimage\\ita.png");
dw.DrawImage(0, 0, 500, 500, img);
QtfRichObject pict(CreateDrawingObject(dw.GetResult(), Size(500, 500), Size(500, 500)));
String qtf;
qtf << pict;
PromptOK(qtf);
}
that is practically your initial code (it didn't work at my first experiment). But still I have not uderstood the Mirek's suggestion about the use of
RichObject CreateImageObject(const Image& img, int cx = 0, int cy = 0);
luigi
|
|
|
Re: Loading Image into qtf [message #11218 is a reply to message #11212] |
Mon, 27 August 2007 23:38 |
|
forlano
Messages: 1182 Registered: March 2006 Location: Italy
|
Senior Contributor |
|
|
Here is a little variation of the previous code.
Now the qtf, that include the picture, needs to be saved on a file and then later opened with UWord.
#include <CtrlLib/CtrlLib.h>
using namespace Upp;
GUI_APP_MAIN
{ FileOut save("badge.qtf");
save << "[ $$0,0#00000000000000000000000000000000:Default]\n[{_}%EN-US [s0; &]\n";
DrawingDraw dw(500, 500);
Image img = StreamRaster::LoadFileAny("C:\\MyApps\\qtfimage\\ita.png");
dw.DrawImage(0, 0, 500, 500, img);
QtfRichObject pict(CreateDrawingObject(dw.GetResult(), Size(500, 500), Size(500, 500)));
save << "[ {{7008:2992>1440;h1; [s0;=* &]\n";
save << "[s0;=*+150 " << "Big Jim" << " &]\n";
save << "[s0;= USA &] [s0;= GM 2750 &]\n";
save << "[s0;= ] :: [s0;= " << pict.ToString() << " &][s0; ]}}&][s0; &]\n";
save.Close();
}
Unfortunately it doesn't work. The code
<< pict.ToString() <<
is wrong and I do not know how to save "pict" in some useful string format inside the document. Is it possible?... and how?
Thanks.
Luigi
|
|
|
|
|
|
Re: Loading Image into qtf [message #11253 is a reply to message #11231] |
Wed, 29 August 2007 00:23 |
|
forlano
Messages: 1182 Registered: March 2006 Location: Italy
|
Senior Contributor |
|
|
luzr wrote on Tue, 28 August 2007 13:10 |
In your case, if you insist on immediate Save to disk of resulting .qtf, you can just use AsQTF(ParseQTF(text))....
|
It works. Thanks.
Here is the test case for other users in my same situation:
#include <CtrlLib/CtrlLib.h>
#include <plugin/png/png.h>
using namespace Upp;
GUI_APP_MAIN
{ FileOut save("badge.qtf");
save << "[ $$0,0#00000000000000000000000000000000:Default]\n[{_}%EN-US [s0; &]\n";
DrawingDraw dw(200, 200);
Image img = StreamRaster::LoadFileAny("C:\\MyApps\\qtfimage\\ita.png");
dw.DrawImage(0, 0, 200, 200, img);
QtfRichObject pict(CreateDrawingObject(dw.GetResult(), Size(200, 200), Size(200, 200)));
save << "[ {{7008:2992>1440;h1; [s0;=* &]\n";
save << "[s0;=*+150 " << "Big Jim" << " &]\n";
save << "[s0;= USA &] [s0;= GM 2750 &]\n";
String text;
text << pict;
save << "[s0;= ] :: [s0;= " << AsQTF(ParseQTF(text)) << " &][s0; ]}}&][s0; &]\n";
save.Close();
}
Quote: |
Anyway, Drawing RichObjects do not have persistent storage representation, so I would also use
RichObject CreateImageObject(const Image& img, int cx = 0, int cy = 0);
instead here.
Mirek
|
Unfortunately I do not understand where/how to use the previous function.
Luigi
|
|
|
|
|
Goto Forum:
Current Time: Thu Mar 28 23:50:29 CET 2024
Total time taken to generate the page: 0.01264 seconds
|