Today Emerson Reed, the OutlookBar guy, posted a question on UT:
"I'm testing PictureVal property and found a strange behavior...
I have an image with height = 8 and width = 1 and an image control with height = 8, width = 91 and stretch = 2.
If I place this image in the control using Picture property, the image is showed correctly, but if I use FileToStr or LoadPicture functions to get the image and set PictureVal property with value returned from one of these functions, the left side is displayed correctly, but it goes gradually more transparent close to the right side!
I've tried this with SP2 and with a lot of image formats: PNG, BMP, GIF and JPEG and the same problem occurs."
So, this is the original image that Emerson wants to stretch using the Image object, enhanced 48 times.
He wanted to send a 8x1 pixel image to an Image object using the PictureVal property. Something simple like that:
Thisform.Image1.Stretch = 2 && Stretch
Thisform.image1.PictureVal = FILETOSTR(lcImageFile)
The image object had the property Stretch = 2, because he expected that VFP would stretch the original 1 pixel wide image to the image control width.
But to our surprise the final result was different from the expected:
Note that the Image rendered using PictureVal became gradient, with a transparent color at the right side ! When he used the original Picture property, pointing to the path of the desired picture, VFP renders the image as desired. This test was made using PNG, GIF, JPEG and BMP. Note that the PNG was not rendered because of a known bug that PictureVal does not recognize PNG's, that seems to have been fixed in SP2 CTP.
You can download the sample above and test this problem from here:
http://www.foxite.com/uploads/ddaa36cc-b759-47de-88c9-734aa52a233c.zip
Just in case you still don't know Emerson's work, he's the author of the very cool and useful Outlook2003 bar, that you can see in the picture below. He's improving this control in order to obtain a better performance, and to make it compatible with OFFICE 2007 style. That's the reason for the vertical gradients.

In GdiPlus-X, we use the Image Canvas a lot in our samples.
This control basically saves the desired images to streams, retrieves the binaries and stores these contents at the PictureVal property of the image control.
Me and Bo noticed that the image rendered by Picture and PictureVal are different too.
The image in PictureVal appears "blurred", even when we don't want, it seems to use always an ANTI-ALIAS smoothing mode.
Note that the original image, from the Top Left appears perfect in the 3 cases when the Picture Property is used. When using PictureVal, if Stretch is set to 0 - Clip - the image is clipped to fit the control. (Default for the control), the image rendered by Picture is EXACTLY THE SAME from the one rendered using PictureVal.
The problem occurs only when we switch Stretch mode to either 1 - Isometric (the image resizes to fit the control while maintaining its original proportions) or 2 - Stretch (the image resizes to fit the control, but does not maintain its original proportions). In this case, the image rendered using PictureVal becomes really blurred
Below is a piece of the above image enhanced. Note how blurred the edges have become !
From that I can presume that when VFP stretches images that are using the PictureVal property instead of the original picture property is uses an Anti-Alias SmoothingMode.
Antialiasing = smoothing line edges in computer images: smoothing the jagged edges of diagonal lines in computer-generated images by varying the color or shades of gray at the edges
Microsoft® Encarta® Reference Library 2003. © 1993-2002 Microsoft Corporation. All rights reserved.
If you still haven't used the PictureVal property yet, you can create a simple form, add a command button, command1, and two image objects, Image1 and Image2. In Command1.Click add this simple code:
LOCAL lcPict
lcPict = GETPICT()
IF EMPTY(lcPict)
RETURN
ENDIF
Thisform.Image1.Picture = lcPict
Thisform.Image2.Stretch = 2 && Stretch
Thisform.Image2.PictureVal = FILETOSTR(lcPict)
Test it using some small pictures, that are much smaller than the image object
In the case of Emerson, as his original image is just one pixel wide, and he expected the image object to repeat the drawing multiple times, till the control is filled, VFP seems to be using always the last pixel rendered and copies for the next column. This is why it seems to be changing the image, creating a new ugly and undesired gradient.
The only solutions that I can think for this case are:
1 - Don't use PictureVal if you need to stretch a very small image, use the Picture property instead. Even if the binaries of the image are stored in a variable, or inside the VCX (using Bernard Bout's amazing tip), I'd recommend to store the image to a temporary file on the disk using STRTOFILE() - and pointing the Picture property to it. Have in mind that using the disk is not that bad. VFP uses disk a lot, creating many temp files for cursors too. And nobody notices that. And in many cases, using the disk access is faster than using streams.
2 - If you really need to stretch an image and want to use PictureVal, then you can stretch your image using Gdi+, save it to a stream, retrieve the binaries from the stream and store in PictureVal property. This process was still not shown in this blog. I hope to show that soon. But frankly, the first suggestion is more recommended and simple.
This problem was found also by Bernard Bout, as he commented in Craig Boyd's blog:
http://www.sweetpotatosoftware.com/SPSBlog/CommentView,guid,94b58210-456a-4fc5-84c9-39db7dcde478.aspx#commentstart
This was already reported to Microsoft earlier today by Emerson Reed, https://connect.microsoft.com/feedback/viewfeedback.aspx?FeedbackID=269606&wa=wsignin1.0&siteid=210
Me, the GdiPlusX team and Emerson have a great interest in solving this problem, because we make a lot of use of this feature in the ImageCanvas object, providing Direct Draw possibilities, allowing VFP programmers to forget Windows Painting problems. For that we really need to have the correct control of the image.
The correct is that PictureVal renders exactly the same way that Picture property does. MS should leave for us, users, to chose when we want to use Smoothing mode Antialias, and the best Interpolation mode. As we all know that SP2 will be released very soon, we ask you all to visit this link and provide your feedback to MS. https://connect.microsoft.com/feedback/viewfeedback.aspx?FeedbackID=269606&wa=wsignin1.0&siteid=210
Please rate and validate it, maybe our friends from MSFT can spend some time fixing this to us.
Another very cool feature would be if they also added the PictureVal property to any object that contains the picture property, like: Image, CommandButton, Container, Form, Header, etc. If you agree with this too, you can vote here: https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=240030
Thanks in advance !
Technorati tags:
FoxPro,
PictureVal