Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Is it possible to make this string an image?
Message
From
20/07/2017 07:06:11
John Baird
Coatesville, Pennsylvania, United States
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 10
Database:
MS SQL Server
Miscellaneous
Thread ID:
01652660
Message ID:
01652762
Views:
92
This message has been marked as a message which has helped to the initial question of the thread.
>>>Hi everybody,
>>>
>>>If I got this as a value, what is it and can this be transformed into an image somehow?
>>>
>>>
>>>ÿØÿà
>>
>>Just use that as .pictureVal property. It's a string containing an image, i.e. what you'd get by filetostr("some.jpg").
>
>
>I put that content into memo nocptrans. What should I do to get it as picture file now? The text starts with the
>
>
>OK :<birth_date>01/01/1975 00:00:00</birth_date><Gender>F</Gender><Height>64</Height><height_m>163</height_m><mug_shot>ffd8ffe000104a46494600010101007700770000ffdb004300080606070605080707070909080a0c140d0c0b0b0c1912130f141d1a1f1e1d1a1c1c20242e24549a9fffd9</mug_shot><Weight>151</Weight><weight_m>68</weight_m>
>
>
>
>I truncated the actual value to show here, it is much longer. So, I got this, but what am I supposed to do with that value to get it as a picture?
>
>Thanks in advance.
>
>
>The program I currently use to print the picture is the following (very old program, I tried to modify it). Assuming I got mug_shot as the string shown above, what should I do?
>
>
>case m.iType = 2   && Memo
>    LOCAL lcValue
>    lcValue = EVALUATE(ImageSource)
>	if !empty(m.lcValue) AND NOT ISNULL(m.lcValue)
>*Wait window type("&ImageSource")
>		if NOT ',' $ ImageSource AND inlist(type("&ImageSource"), "M","Q","W") and len(&ImageSource)>1
>			cOFile = GenOFile(".jpg",.t.)
>			copy MEMORY(m.ImageSource) to (m.cOFile)
>			cOFile = E0Resize(m.cOFile, dpi)
>		ENDIF
>		
>		IF ',' $ ImageSource
>			cOFile = GenOFile(".jpg",.t.)
>			STRTOFILE(m.lcValue, cOFile)
>*!*         if INLIST(type("&ImageSource"), "Q","W") && blob field
>*!*            cOFile = GenOFile(".jpg",.t.)
>*!*            strtofile(&ImageSource,m.cOFile)
>        	cOFile = E0Resize(m.cOFile, dpi)
>     	endif
>	endif
>
>My case is currently ',' in ImageSource (as I am now calling decryption function as opposed to just Table.Column)


Here are the extionsion I use in c# to accomplish this. First convert string to bytearray with ConvertStringToBytes() and then call ToBitMapImage() to get the image.
        #region Graphics extensions
        public static Bitmap ToBitMapImage(this byte[] array)
        {
            Bitmap bmp;
            using (var ms = new MemoryStream(array))
            {
                bmp = new Bitmap(ms);
            }

            return bmp;
        }
        #endregion

        public static byte[] ConvertStringToBytes(this string s)
        {
            MemoryStream stream = new MemoryStream();

            using (StreamWriter writer = new StreamWriter(stream))
            {
                writer.Write(s);
                writer.Flush();
            }

            return stream.ToArray();
        }

        public static string ConvertBytesToString(this byte[] b)
        {
            string output = String.Empty;

            MemoryStream stream = new MemoryStream(b)
            {
                Position = 0
            };
            using (StreamReader reader = new StreamReader(stream))
            {
                output = reader.ReadToEnd();
            }

            return output;

        }
Previous
Reply
Map
View

Click here to load this message in the networking platform