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 » U++ Library support » RichText,QTF,RTF... » Loading Image into qtf
Loading Image into qtf [message #9913] Fri, 08 June 2007 12:18 Go to next message
guido is currently offline  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 Go to previous messageGo to next message
mirek is currently offline  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 Go to previous messageGo to next message
guido is currently offline  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 Rolling Eyes
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 #9929 is a reply to message #9925] Sat, 09 June 2007 18:54 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Hard to say what the problem with JPG is, I would check whether it gets stored into DB correctly first.

E.g. LOGHEXDUMP image date before they go to the database, then LOGHEXDUMP again what you get from it. Or better use SaveFile in both cases and use some image viewer to check the results.

Mirek
Re: Loading Image into qtf [message #11211 is a reply to message #9925] Mon, 27 August 2007 19:32 Go to previous messageGo to next message
forlano is currently offline  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 Go to previous messageGo to next message
forlano is currently offline  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 Go to previous messageGo to next message
forlano is currently offline  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 #11230 is a reply to message #9913] Tue, 28 August 2007 12:58 Go to previous messageGo to next message
dmcgeoch is currently offline  dmcgeoch
Messages: 52
Registered: November 2006
Location: New Jersey
Member
Hi,

I had a similiar problem when I was working with images stored in a database. What I ended up doing was using the Encode64 and Decode64 funtions on the string. Apparently there are characters in the string generated by the Image.ToString() command that are not stored properly.

Dave
Re: Loading Image into qtf [message #11231 is a reply to message #11218] Tue, 28 August 2007 13:10 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Sorry for the confusion there...

The problem is caused by the fact that for performance reasons, QtfRichObject creates only a temporary reference to the real RichObject. You need to call ParseQTF while both QtfRichObject and RichObject exist, otherwise you are in trouble... (a dangling pointer).

In your case, if you insist on immediate Save to disk of resulting .qtf, you can just use AsQTF(ParseQTF(text))....

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
Re: Loading Image into qtf [message #11237 is a reply to message #11230] Tue, 28 August 2007 16:31 Go to previous messageGo to next message
guido is currently offline  guido
Messages: 169
Registered: April 2006
Experienced Member
dmcgeoch wrote on Tue, 28 August 2007 12:58

Hi,

I had a similiar problem when I was working with images stored in a database. What I ended up doing was using the Encode64 and Decode64 funtions on the string. Apparently there are characters in the string generated by the Image.ToString() command that are not stored properly.

Dave


I was considering that too, when couldn't figure out the BLOB stuff. But I learned from googling this adds a 30% overhead, so I tried harder.
I'm using the sqlite3 C-API directly, because I find that easier and know I am never going to need a "real" client/server database.
sqlite3 encodes BLOBS with a mere 1% overhead. I finally figured out how it works, so I'm using that now.

Guido
Re: Loading Image into qtf [message #11253 is a reply to message #11231] Wed, 29 August 2007 00:23 Go to previous messageGo to next message
forlano is currently offline  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. Confused

Luigi
Re: Loading Image into qtf [message #11266 is a reply to message #11253] Wed, 29 August 2007 11:26 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Actually, it should make your code much more simple:

QtfRichObject pict(CreateImageObject(StreamRaster::LoadFileAny("C:\\MyApps\\qtfimage\\ita.png")));


CreateDrawingObject is rather useful when you want to draw something to be displayed in QTF (like graph).

Mirek
Re: Loading Image into qtf [message #11269 is a reply to message #11266] Wed, 29 August 2007 12:21 Go to previous message
forlano is currently offline  forlano
Messages: 1182
Registered: March 2006
Location: Italy
Senior Contributor
luzr wrote on Wed, 29 August 2007 11:26

Actually, it should make your code much more simple:

QtfRichObject pict(CreateImageObject(StreamRaster::LoadFileAny("C:\\MyApps\\qtfimage\\ita.png")));


CreateDrawingObject is rather useful when you want to draw something to be displayed in QTF (like graph).

Mirek


Surprised Very nice.
All these functions connected with QTF are extraodinary useful to make professional report without pain...
Maybe the previous code can become a reference case.

Thanks,
Luigi
Previous Topic: Rendering qtf into a window: horrible flicker
Next Topic: Failed to set String format in report from SQLite3
Goto Forum:
  


Current Time: Thu Mar 28 20:35:47 CET 2024

Total time taken to generate the page: 0.02271 seconds