Images taking long time to load WinRT XAML - performance

In our WinRT app, we have provided image as a background to grid and buttons through XAML.
We observed that images taking long time to load, app showing only other text controls (like TextBlock) first, then after some duration, our images loaded. Till the time we only see text controls in page.
We are setting background as below
<ImageBrush ImageSource="ms-appx:////Images/image.png"/>
Please let me know, what can we do to resolve this issue.
Thanks.

You can
reduce the resolution of the image
wait for it to load before you show the page - either by starting that earlier somehow or by showing the page completely black and, say, fading in when the image loads
use a lower resolution image or other asset until the image loads
not use that image at all
I have a hunch that if the image source gets set early enough - WinRT will wait for a short time (a fraction of a second) before it shows a new page to give the image a chance to load before it starts running transition animations etc., so lowering the image resolution altogether or using a lower resolution before a higher resolution one loads is one approach.
one more option is to have a background be outside of the root frame - e.g. modify App.xaml.cs to have a grid as root visual and put the background image and the frame inside of it so you can change the image at any time.

This is a weird behaviour,
However you can try to opt for images with smaller size/resolution to optimize rendering time.
Also, try to set the background image in the Page's constructor - Since, Microsoft may(I am not sure though) handle XAML Parsing via Async Operations

Instead of ImageBrush try to use regular Image with CashMode property set to "BitmapCache":
<Grid>
<Image Source="ms-appx:////Images/image.png"
CacheMode="BitmapCache" />
<!-- Your other content above background image -->
</Grid>

Related

Best way to represent list with image(using url) in Xamarin.Forms?

I want to create List View. In this List View, I will have following fields.
StackPanel
1- Image with 300 x 400 size
2- Text-Label Controls
1 Screen will hardly cover 1 and Half ViewCell.
Images will have ImageURL. I want to load image smoothly. I also want to make smooth scroll up/down with image appearing.
Can anybody please suggest me which control I should use?
If List View, which CacheStrategy I should use?
Note: For one of such functionality, I had used List View with default CacheStrategy. In that, I just faced 1 major problem of image appearing. When page initialize first time, it show image properly. But as soon as I scroll down or scroll up, image disappear or misplace. In that case, I had suffered a lot and removed image finally.
Please suggest appropriate way for above functionality.
Thank you.
For the listview, you should definitely use RecycleElement as the CachingStrategy. See here https://developer.xamarin.com/api/type/Xamarin.Forms.ListViewCachingStrategy/#Remarks
And because the images are URLs, you can use FFImageLoading. It will fade-in the image after it is downloaded (as opposed to appearing instantly after downloaded), and you can even specify a placeholder image to use while the image is being downloaded.

how to make a bitmap to fit to the static picture control of a property sheet?

I am having a property sheet and added three pages.In the first page I added a picture control and in the properties of that picture control for "Image" property I am setting a bitmap.And was able to load very successfully.But,the problem here I faced when I run my exe then I am getting bitmap on the page header(which is some kind of banner for the page.)But what I noticed is there is some gap between the banner bitmap and the frame edge (which is occurring at the right top corner). And when I ran my xxx.exe on a Japanese machine then I had observed like the sheet is somewhat stretched and banner bitmap is not stretched completely till the edge of the sheet (top right corner)for Instance if we take a dialog on load a bitmap on it then we can observe that it is entirely got stretched till the edge.
So how can we avoid this issue like whatever the operating system it is and whatever the resolution it might be that banner should get stretched till the edge of the sheet.The gap has to be removed.
I am not loading the bitmap dynamically (setting in the properties.)
Can anyone please help me ti achieve this
The reason you get different results on different systems is that dialogs and controls are sized using "dialog units" which are based on the average size of the font, rather than an absolute number of pixels.
By default a static image control will resize itself to the size of the bitmap it's displaying. So if the dialog itself ends up bigger than normal (because the font is physically bigger), the picture control will appear to have shrunk, leaving a gap.
You could try setting the SS_REALSIZECONTROL style on the static control. The normal behavior of the static control (when displaying a picture) is to resize itself to the size of the bitmap, however the SS_REALSIZECONTROL style overrides that behavior and instead causes the bitmap to be resized to the size of the control. However the results of that may be less than optimal (e.g. the aspect ratio will probably be wrong), so instead you may want to look into scaling the bitmap yourself.

QLabel show image slowly

I develop a image browser to show image series with QSlider. I connncet valueChanged(int) of QSlider to a self-defined function:
QObject::connect(ui.imgIndexSlider, SIGNAL(valueChanged(int)), this,SLOT(onimgIndexSliderValueChanged(int)));
when I drag the slider, the image that QLabel shows will changed by the QSlider value.It works.But there is a problem that if you drag fast,the Application will not run acceptably.
Could you tell me how to slove this problem.
Thank you very much.
It is not clear much from your question, but I am assuming that you are showing images like a slideshow using the slider. When you slide it fast your application is getting choked i.e. freezes?
Qt is rendering the image in your GUI thread.
If the images are all high resolution then it will take much more time in rendering each image.
When you slide faster than Qt can render a single image you will experience problems.
So here is what I would ideally do if I were in your place:
Implement a custom algorithm which will read the image file and
create a preview image of much smaller size. Since you are only
generating a pixmap in memory, you can do this by multi threading.
You can do this when your application is launched.
Show all the preview's as scrollable tiles on left pane similar to
Powerpoint. You can reduce some coding here by letting Qt render
these preview's by using QLabel.
Have a central widget which occupies the major chunk of the window
which will render the images using your custom algorithm. Your
algorithm will be such that it will read the actual image if the
slider is not running. If slider is running fast enough then you simply need to
scale your preview images and display in the widget.
Feel free to ask questions if you find anything difficult to understand. :)

Showing a high resolution image in WP8?

In my Windows phone 8 app, I am binding web-URL to Image control.
I have two pages, on first page i am binding a low resolution image(I Have web-URL of multiple resolutions). On next page I have to show the same Image in full screen mode so I am binding high resolution image URL. But it takes some time to load.
Then I tried to bind the same low resolution image which I have on previous page to this Full screen Image Control and then binding the high resolution image.
So my problem is here, when I am adding a low res image, its getting displayed and then I am binding a high res image. so for some time no image is appear.
Please suggest, How can i show the continuous image, Image should not be disappear.
You should use the MultiScaleImage control or wait until your High-Res image completes downloading, then re-bind your control.
I would recommend using two Image solution. Place your lo-res image into visible Image control and place your hi-res image into hidden Image control. Once hi-res image is loaded you can hide lo-res image and show hires one. For extra smooth user experience you can use animations to cross-fade images.
Subscribe to ImageOpened event so you know then image is loaded.

Issue with Panorama Background Image Fade-In Animation?

Hi I was using the sample found here for fading in a background image. Everything is working fine its just that before the fade in animation starts the image shows briefly then the animation starts.
No Background => Full Image => Image Disappears => Animation Starts =>
Full Image
Note I did add the exact same code as him but I still get this result. I did notice that his sample was written for WP7 7.0 which I'm guessing is the reason it's not loading exactly like the example he provided.
Has anyone found a workaround for this?
Make your background initially hidden in xaml or by code in page constructor. Animation starts after page loaded, so background is shown from application start to Loaded event
I bet you have opacity for image set to 1, and when it's loaded then you start showing it - resulting in bizarre flickering. Set opacity to 0 in xaml and then run your Storyboard (that animates opacity from 0 to 1).
Well even though it takes about a second and a half extra to load, I finally got it to stop blinking. Basically I would save the file to isolated storage, and then load the file from isolated storage instead of loading the image directly to the background after it finished downloading.
I got the idea based on the fact that the sample of loading the background using a local image worked perfectly.
Like I said it takes a little longer to download because of the saving and loading from isolated storage, but it works well.

Resources