[Gambas-user] Picture.ToString() ?

Bruce Steers bsteers4 at gmail.com
Sun Dec 31 14:46:03 CET 2023


On Sun, 31 Dec 2023 at 12:49, Bruce Steers <bsteers4 at gmail.com> wrote:

>
>
> On Sun, 31 Dec 2023 at 12:07, Claus Dietrich <claus.dietrich at freenet.de>
> wrote:
>
>> Am 30.12.23 um 19:40 schrieb Bruce Steers:
>> > The initial objective was to avoid having to use a real file for speed.
>> > Just send picture data as a string, without having to save to a
>> > physical file then re-read it with File.Load.
>> >
>> > It seems logical that if there is Picture.FromString then there may be
>> > a ToString alternative.
>>
>> Hi
>>
>> I agree and also think of a Picture.ToString-method which provides a
>> string representation of a bitmap file. The conversion routines proposed
>> so far do something different. The following function is based on the
>> one used by Bruce, but it utilizes a virtual file system located in the
>> RAM instead of the physical hard-drive:
>>
>> Public Sub PictureToString(Pic As Picture, sFormat as String, Optional
>> iQuality as Integer = 100) As String
>>
>>       Dim sPath As String
>>
>>       Shell "echo $XDG_RUNTIME_DIR" Wait To sPath
>>       sPath = Trim(sPath) & "/tmppic." & sFormat
>>       Pic.Save(sPath, iQuality)
>>       Return File.Load(sPath)
>>
>> End
>>
>
I like this, great idea Claus , It can be shortened a bit by using Env[]
instead of the first Shell call to get XDG_RUNTIME_DIR
It's gotta be better than using Temp()

Public Sub PictureToString(Pic As Picture,Optional sFormat as String =
"png", iQuality as Integer = 100) As String

  Dim sPath As String = Env["XDG_RUNTIME_DIR"] &/ "tmp-pic." & sFormat
  Pic.Save(sPath, iQuality)
  Return File.Load(sPath)

End

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


More information about the User mailing list