[Gambas-user] Picture.ToString() ?

Bruce Steers bsteers4 at gmail.com
Sat Dec 30 14:01:52 CET 2023


aah yes i guess that could work.  at the other end i'd just need size info,
say width, then the image height is String.Len / 4 / width

  Public Sub PictureToString(Pic As Picture) As String

    Dim s As String = Str(Pic.W) & "\n"

    For Each i As Integer In pc.Image.Pixels
      s &= MkInt(i)
    Next

    Return s

  End

How do you convert a 4 char string block back to integer though?
CInt didn't work (i tried a few different things)

Dim s As String = MkInt(Color.Red)
Print CInt(s)

Type mismatch: wanted Integer, got String instead

Respects
BruceS


On Sat, 30 Dec 2023 at 12:20, vuott--- via User <user at lists.gambas-basic.org>
wrote:

> Hello,
> if you want to send "pure" image data, "perhaps" you could do this:
>
> - To send blocks of "Integer" data converted to memory representation as a
> 4-character string:
>
>   Public Sub PictureToString(Pic As Picture) As String
>
>     Dim s As String
>
>     For Each i As Integer In pc.Image.Pixels
>       s &= MkInt(i)
>     Next
>
>     Return s
>
>   End
>
>
> - To send blocks of individual "Byte "data converted to memory
> representation as a 1-character string:
>
>   Public Sub PictureToString(Pic As Picture) As String
>
>     Dim s As String
>
>     For i As Integer = 0 To (pc.Image.Pixels.Max * (pc.Depth / 8))
>       s &= MkByte(Byte@(pc.Image.Data + i))
>     Next
>
>     Return s
>
>   End
>
>
>
>
>
>
> 30 dic 2023, 01:46 da bsteers4 at gmail.com:
>
> 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
>
>
>
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20231230/b93eb1dc/attachment-0001.htm>


More information about the User mailing list