[Gambas-user] Picture.ToString() ?

Bruce Steers bsteers4 at gmail.com
Mon Jan 1 20:51:25 CET 2024


On Mon, 1 Jan 2024 at 17:49, Benoît Minisini <
benoit.minisini at gambas-basic.org> wrote:

> Le 01/01/2024 à 15:02, BB a écrit :
> >
> > 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
>

Dang it, why can't things just be simple? !!

To be fair Claus's solution of using $XDG_RUNTIME_DIR to get the
/run/user/1000 virtual dir is great and works around my issue of not
wanting to involve a physical disk file, (I did not know of this virtual
folder)
Now my ToString function tries to use Env["XDG_RUNTIME_DIR"] or
"/run/user/1000" or finally Temp()



> I'm currently adding the 'ToString()' methods for both toolkits and both
> Picture and Image classes. But it's not finished.
>
> Regards,
>
> --
> Benoît Minisini.
>

Fantastic , even better , thank you Benoit  :)
Happy new year
BruceS
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20240101/ee0d144a/attachment.htm>


More information about the User mailing list