# String to Picture

**URL:** <https://forum.xojo.com/t/string-to-picture/72879>\
**Category:** Databases\
**Created:** [October 26, 2022, 12:01pm UTC](https://forum.xojo.com/t/string-to-picture/72879 "2022-10-26T12:01:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexander\_van\_der\_Linden](https://forum.xojo.com/user_avatar/forum.xojo.com/alexander_van_der_linden/32/323_2.png) [@Alexander\_van\_der\_Linden](https://forum.xojo.com/u/Alexander_van_der_Linden)\
**Post date:** [October 26, 2022, 12:01pm UTC](https://forum.xojo.com/t/string-to-picture/72879/1 "2022-10-26T12:01:18Z")

</div>

I have a database with a String-type column which contains serialized data from a PNG. How do I construct a picture from this data?  
I tried:

```auto
var MB as memoryblock
var MyPicture as new Picture
MB = MyRowSet.Column("PicData").ToString
MyPicture.FromData(MB)

```

But MB is empty. I tried to put the PicData in a String var first and read that into a MB but it fails.

---

<div class="post-metadata">

**Author:** ![Jean-Yves\_Pochez](https://forum.xojo.com/user_avatar/forum.xojo.com/jean-yves_pochez/32/21769_2.png) [@Jean-Yves\_Pochez](https://forum.xojo.com/u/Jean-Yves_Pochez)\
**Post date:** [October 26, 2022, 2:50pm UTC](https://forum.xojo.com/t/string-to-picture/72879/2 "2022-10-26T14:50:01Z")

</div>

I use encodebase64 and decodebase64 to store pictures in a database  
because if you use strings, you can have characters that are filtered  
base64 ensure you only have ascii characters in the string.

---

<div class="post-metadata">

**Author:** ![Tim\_Hare](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_hare/32/176_2.png) [@Tim\_Hare](https://forum.xojo.com/u/Tim_Hare)\
**Post date:** [October 26, 2022, 11:32pm UTC](https://forum.xojo.com/t/string-to-picture/72879/3 "2022-10-26T23:32:10Z")

</div>

Don’t you want `MyRowSet.Column("PicData").StringValue`?  
MyRowset.Column() returns an object, so ToString isn’t going to do what you expect.

---

<div class="post-metadata">

**Author:** ![Alexander\_van\_der\_Linden](https://forum.xojo.com/user_avatar/forum.xojo.com/alexander_van_der_linden/32/323_2.png) [@Alexander\_van\_der\_Linden](https://forum.xojo.com/u/Alexander_van_der_Linden)\
**Post date:** [October 27, 2022, 7:15am UTC](https://forum.xojo.com/t/string-to-picture/72879/4 "2022-10-27T07:15:18Z")

</div>

Yes, typo. The thing is, I load a rowset into a String type multidim array. So far so good. The array element contains the PNG data. But when I try to convert it back into a Picture, the array won’t release the data.

```auto
MB = OrganisatiesArray(i,7) 'type string and holds data - verified
MapImage = Picture.FromData(MB)

```

MB is empty. When I do

```auto
var TempString as String
TempString = OrganisatiesArray(i,7) 
MB = TempString
MapImage = Picture.FromData(MB)

```

TempString is empty, so MB is empty too. It looks like the array won’t release the data (250kB).  
No idea why this is.

---

<div class="post-metadata">

**Author:** ![Tom\_Dixon](https://forum.xojo.com/user_avatar/forum.xojo.com/tom_dixon/32/605_2.png) [@Tom\_Dixon](https://forum.xojo.com/u/Tom_Dixon)\
**Post date:** [October 27, 2022, 11:00am UTC](https://forum.xojo.com/t/string-to-picture/72879/5 "2022-10-27T11:00:15Z")

</div>

I use PictureToJPEGStringMBS and JPEGStringToPictureMBS and it works great. Very fast and at 100% quality no quality loss. additionally a jpeg string take less db storage space. If you have the MBS plugins I’d recommed you try it.

```auto
// p is a picture, 100 is the jpeg quality
Var pstrng As String = PictureToJPEGStringMBS(p,100)
// Store the string into the DB
// convert the string back to a picture after retrieving it from the DB
Var p As Picture = JPEGStringToPictureMBS(dbstrng)
// Use the picture

```
