[Gambas-user] Picture.ToString() ?

BB adamnt42 at gmail.com
Mon Jan 1 15:02:47 CET 2024


On 1/1/24 11:26 pm, Bruce Steers wrote:
>
>
> On Mon, 1 Jan 2024 at 05:46, BB <adamnt42 at gmail.com 
> <mailto:adamnt42 at gmail.com>> wrote:
>
>     On 30/12/23 11:15 am, Bruce Steers wrote:
>>     If there any simpler (non-file) way to get the opposite of
>>     Picture.FromString()
>>     I wanted a way to transmit image data using Print in Task.class.
>>
>>     This works for me but wondered if there was a faster way than a
>>     physical file?
>>
>>     Public Sub PictureToString(Pic As Picture) As String
>>
>>       Dim sTmp As String = File.SetExt(Temp("tmp-pic"), "png")
>>       Pic.Save(sTmp)
>>       Return File.Load(sTmp)
>>
>>     End
>>
>>     Respects
>>     BruceS
>>
>     Ohohoo and a happy new year.
>
>     For something to do I have waded through the QT4 and GTK Picture
>     classes. It appears to me that adding a ToString() method for QT
>     would be a simple ("hahaha" said the so-called C expert) matter as
>     the underlying buffer into which the file is loaded does not
>     appear to be destroyed while the Picture exists and it is
>     essentially a byte array. Now for GTK, guess what?! The initial
>     buffer is released after it is loaded and converted to a picture!
>     So it is not going to be so simple to create a way to develop a
>     simple ToString().
>
>     I accept that this does not advance towards a solution but it may
>     relieve some of your angst about the implied "Why isn't?
>
>     cheers
>
>     b
>
>
> I see , cheers :)
> It seems we already have the code though for all toolkits. just only 
> with a file save/load.
> Either Picture.Save() (and Image.Save()) or File.Load() is already 
> doing the job of converting to string.
>
> So could whatever method it is that's doing the conversion be exposed 
> as a function we could all use? to get the string data rather than 
> saving it to a file.
>
> Respects
> (and happy new year all :) )
>
> BruceS
>
Not quite. Both toolkits "load" a picture via a simple file read i.e 
initially they are both in for want of a better word, a contiguous 
memory gob of bytes. The conversion is quite different in both cases. 
It's just that the QT libraries "keep" the gob available while the 
picture exists, as a Qsomething (I forget and its late) whereas in gtk 
after the gob is converted it is lost. I suppose , if you were using QT 
you could write the appropriate low level interface (and go bonkers in 
the process) but it is already there in the gb.qt4 CPicture. But in the 
gtk CPicture it aint.

b


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20240102/63321e06/attachment.htm>


More information about the User mailing list