[Gambas-user] Picture.ToString() ?

Bruce Steers bsteers4 at gmail.com
Sat Dec 30 13:15:29 CET 2023


On Sat, 30 Dec 2023 at 01:01, BB <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
>
> What is the origin of the picture?
>
> I do a similar thing but I have the path of the picture and just load it
> as a string via
>
> sPicString = File.Load(picPath)
>
> when I originally load the picture.
>
> As you have already seen, the File.Load does load it as a string (as .png
> is just a flat file).
>
> I haven't tried just assigning the picture to a string variable but I
> guess it does not work.
>
> Otherwise I can't see any faster way.
>

The Task reads /usr/share/applications dir to get it's own list of all
applications with all their icons.
It's something that happens at program start and is kinda cpu greedy as it
has to search for the theme icons.
if not a background task the program freezes for a bit while it's
processing all the files and getting all their icons/building a menu.

So my aim was to get as much of the process away from the application and
into the background task as possible.
I found using the task to just send the image paths then loading the images
in the application was more work for the application and the task sends a
list of paths so fast that the application still freezes for a bit.
Now the background task is also sending the image data it's a bit slower,
and that's better as the foreground application works better.

I just wondered if there was already a function that compliments/mirrors
Picture.FromString as I see uses for that. Or could I do it better using
Stream.class but in memory, not using a physical file so it would be faster.
I'm not that experienced at opening/writing/reading memory streams.

Respects
BruceS
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20231230/b761fbb7/attachment.htm>


More information about the User mailing list