XAML event for background image rendered off screen - xaml

I am setting a background image on my XAML Grid with a Uri. The Uri points off to a HTTP url, where it will fetch, and then render the image as a background for a Win8 metro app.
I've been trying to figure out if there is an event or something I can hook into to let me know that WPF has loaded it into memory, AND finished rendering it out of view.
Currently, a small image will load fast enough, and smoothly fade in. However, if I load a larger, slower image, it will take 100s of ms to show up as the background, which means it either pops up mid-fade, or after the fade effect has completed. This looks quite poor.
The goal is to have a fade transition between app pages (I already have this), without the inconsistency of the background image popping up whenever it's done.
Any suggestions would be welcomed.

You don't say exactly how you're loading the image but there's a DownloadCompleted event on BitmapImage, e.g.
BitmapImage bmp = new BitmapImage(imageUri);
bmp.DownloadCompleted += ReadyToDisplay;

Like Phil said, but then for Windows Store apps:
BitmapImage bmp = new BitmapImage(imageUri);
bmp.ImageOpened += ReadyToDisplay;
ImageOpened Occurs when the image source is downloaded and decoded
with no failure. You can use this event to determine the size of an
image before rendering it.
source: MSDN

Related

Clear preview window in media foundation

Is it possible to clear a preview window after preview from camera is done? I am using MFCaptureEngine, calling m_pPreview->SetRenderHandle(m_hwnd) to render the video. But when I stop the video I am not able to draw on the window. There remains a last frame from the camera. I need to fill the window by black brush and draw some text, but the image from the camera cannot be overdrawn.
It is not clear understand from you answer what is it MFCaptureManager, but by code SetRenderHandle(m_hwnd) I see that you use IMFCapturePreviewSink::SetRenderHandle. So, I can say that I had faced with similar problem some time ago, and it is related with difference between of the old window system which exist from WinXP and current window system from Vista. Code sets window context to the renderer by calling IMFCapturePreviewSink::SetRenderHandle - for IMFCapturePreviewSink it is DirectX11 - and DirectX11 has got FULL access to the window and it is switched to current window system. As a result, any calling fill the window by black brush and draw some text which is done by old Windows API from Win95-XP generation do nothing - because window handler context is LOCKED by DirectX11.
There are three ways for resolving of this problem:
Write the new UI by the new Microsoft DirectComposition GUI API which is based on DirectX11 and set it to IMFCapturePreviewSink::SetRenderSurface.
Create EVR Media Sink by MFCreateVideoRenderer - it creates DirectX9 video renderer which is compatible with old Windows API from Win95-XP generation, and set this IMFMediaSink in IMFCapturePreviewSink::SetCustomSink.
Create code of the video renderer on DirectX9 base - for example MFCaptureD3D/device.cpp, and draw raw IMFSample from callback IMFCapturePreviewSink::SetSampleCallback.
Regards.
I've implemented it this way:
// Sink
CComPtr<IMFCaptureSink> pSink;
m_pEngine->GetSink(MF_CAPTURE_ENGINE_SINK_TYPE_PREVIEW, &pSink);
CComPtr<IMFMediaSink> pCustomSink;
::MFCreateVideoRenderer(IID_IMFMediaSink, (void**)&pCustomSink);
CComPtr<IMFCapturePreviewSink> pPreviewSink;
pSink.QueryInterface(&pPreviewSink);
pPreviewSink->SetCustomSink(pCustomSink);
// preview
pSink.QueryInterface(&m_pPreview); // or pPreviewSink.QueryInterface(&m_pPreview)
m_pPreview->SetRenderHandle(m_hwndPreview);
But the behaviour is still the same (the screen cannot be redrawn after the preview is stopped).

Images flash upon loading

Description
Upon loading an image (gif/jpg/webp/png) the image flashes the background color then loads the image. I expect that the image would just load and only have a placeholder when the image takes a while to load.
This problem is irrelevant to the size of the image (img size 10kb). Even if the image loads immediately the background color flashes.
Reproduction
Essentially just load an image and replace it with another image on the same scene.
I have a git project with the issue where it flashes red:
https://github.com/dnam50/gifTry.git
A gif demonstrating https://user-images.githubusercontent.com/28775204/32446378-5eb5926e-c311-11e7-9afe-6c689a4280af.gif
Additional Information
Fresco version: [1.5.0]
Platform version: [nexus 6 api 25] but has been tried on numerous android devices.
I am aware of White Flash inbetween Re-rendering Image Views which is the same issue but I have added a code example and gif example.
Thanks

SDL Window shows final frame from the last time the program was run in the background of a new window when I start up a new instance

I'm making a simple game and just messing around with SDL. I have two images currently, and I am practicing making them the background. I make one the background by calling RenderCopy, the DestroyTexture to clear it from memory, and then I present it. I changed the file path from one image to the other to change the background. I ran the program, and now the new image is layered on top of the other. I can fix this problem if I manually do a clean of my computer's memory, and it renders properly. For some reason, SDL is not clearing the image called previously. There is no mention of the old image anywhere else in the code, and all the Destroy functions are called. What is going on?
Edit: I did a little bit of snooping and its not that it even loads the old image; whatever the final render displayed on any program running SDL was before it was run, it will be the background. It is literally like a TV burning an image into the screen; its always there.
The problem was fixed by simply clearing the frame between frames. Didn't have any performance impact.

how to make the images downloading from web fastly?

i'm having array of image urls (say count=10), i have to display the images in NSCollectionView. but the images were took lot of time to display. what is lazy loading? i'm searching for mac osx not IOS.
If your images are not downloaded you can still show your view. You just display some placeholder, or an activityIndicator instead of each image, and when each of your images finishes downloading, you replace your placeholder with the correct image. Just make sure to download your images on an background thread and perform the replacing on the main thread. I recommend using NSOperationQueue for downloading on an background thread.
Download files asynchronously .So that it wont affect the main thread.
Lazy loading is a design pattern commonly used in computer programming to defer initialization of an object until the point at which it is needed.
that is when the image is visible only it needs to be loaded.So do it that way.Collectionview and tableview populates in such a way itself

Titanium Images Wrong Size

I have a Titanium app where I am using the same ImageView for alot of different images. I am changing the image in the image view by setting it's image property.
The problem is some of the images are not showing at their full size sometimes, it is kinda random, but sometimes they show full size sometimes not.
I have width and height set to "auto" on the image view.
Anyone come across this issue.
A potentially more reliable way would be too dynamically resize the image before handing it off to the ImageView by using Titanium.Blob.imageAsReized.
Try to integrate this in your code, first you have to load the image as a blob though.
// Get the blob of your image first, then call this method
imageView.image = imageBlob.imageAsResized(newWidth, newHeight);