Advice on image storing - c#

I am currently developing an app that will browse(and more things, but this is not relevant) youtube lists. Now whenever I get a video, I display it's corresponding image and show it in a listview (or gridview, again not relevant). Now here is the dilemma: is it better to store the images locally after they are downloaded, or do we download them every time we want them showed, i.e:
this._image = new BitmapImage(new Uri("http://domain.com/content/someImage.jpg"));

You're probably going to want to see what YouTube has to say on the matter; I'm sure it's got something regarding this in its developer API documentation to note their preferred approach to it.
That said, take this as general advice; when you're constantly querying another system, you generally want to limit how annoying you are. Now, YouTube's not going to notice the load of one app, of course, but it's still a good habit to keep. Generally speaking, I'd prefer to split the difference: cache the image based on video ID and hold it for X hours, so if the user pulls up the same video in a search 20 times you didn't request a thumbnail 20 times as well.
That way you keep the result relevant by updating the image every day or two (assuming they searched for the video again).
Edit: Right, app. Mobile. Bandwidth. Godawful data caps. My advice is more important then and you probably want to make it cache for a couple of days to be safe, but have a hard cap of how many video thumbnails you keep at a time so you're not the app taking up 100MB of space on some guy's 8GB phone.
If you want to be super user friendly, throw something in the settings somewhere to let people change the approach to query every time, or cache for a specific time.

It really depends on your usage model. The correct term would be 'cache' image locally 'or' fetch from servers each time you want to show image. If user experience is of higher priority than showing the latest image snapshot of youtube videos (which very likely isn't going to change for same video) - then cache the images locally, with an expiry time. This would be helpful in having a faster user experience and also save some network bandwidth. Caching with expiry would ensure you are not filling up memory on device with too many unnecessary images and also as images get old, they will be less relevant and removed and you can fetch new ones.
Caching policy (the way you determine when an image is not of high importance and how long it should remain) will be an interesting problem and can have significant impact on the user experience

Related

how to optimize performance of longlistselector with images on windows phone?

I have a page with a pivot containing about 10 items, each pivot item contains a longlistselector with 30 items each.
Each longlistselector item contains an image.
When I'm browsing the page and I flip to the next pivot item, the app crashes at the 4th pivot item with a memory exception.
Is there anyway to unload undisplayed images in the longlistselector?
i suggest rethinking your app layout, 10 pivot items is a tad too many for normal user navigation, why not have a main page with a longlistselector of "categories" follow by a details page of 30 images.
But if you absolutely have to do it this way, take a look at microsoft's photohub source
I'm using it personally and have no problem loading hundreds of images in a panoramaItem.
Better still if you can afford the time, do a memory profile and look exactly where the bloat is, sometimes it might be some part of your application that is hogging on to the memory.
Last of all, wp itself caches the images automagically, but not everyone likes it this way (i'm sure you don't)
take a look at this:
Image Caching
This is an important one, and MSDN is currently fairly silent about it. If you were ever wondering why your image memory didn't get released after clearing the Source and removing the Image from the tree, you were most likely seeing Image caching in action. This is an intended performance optimization, to avoid (down)loading and decoding the same image over and over again. Instead we keep a cache in memory that we can easily and quickly reuse. This is not to confuse with the browser cache for downloaded files.
While this is a nice and free performance optimization, at times it can blow your memory unnecessarily, especially when you cycle through many images that you will never come back to. Their cache will use up memory for the lifetime of your app. The good news is that you can delete the cache when you decided that you no longer need it:
BitmapImage bitmapImage = image.Source as BitmapImage;
bitmapImage.UriSource = null;
image.Source = null;
Being smart about this can save you quite a bit of memory usage, which is a precious resource on a phone device. In the sample app, go to the "Caching" page and monitor the memory usage as you show/clear the image. Then check the box and try again. You will see a difference of ~3MB in the example case.
You can get the full article here

Good realtime display perfomance and input processing for .NET desktop application approach

I am tasked to write a .NET application that displays a slide-show with some information (words or images) and when the user sees certain items, s/he must immediately press space and the time of the key press must be recorded. The items will be displayed one after the other, for about 50ms. I need then to evaluate the difference between the timestamp of the keypress and and the one when the slideshow started (so I will know how long it took the user to react on the presented item). Edit: I must also record the time of the occurence of the special item.
I need to reduce any unpredictable lags that may occur as the application is running, so that the input processing is as realistic as possible, as well as to reduce any lags between the slides. Currently I am thinking of 3 approaches:
Write a standard Windows Forms (GDI+) application.
Write a WPF application
Write a DirectX-enabled windows forms application that utilizes the Tom Miller's Render loop concept (it is praised as effective in terms of performance).
Something else that you might suggest
I must clarify that I will not use advanced display techniques, special effects or designed for the purpose 3D environments - just plain text slides in different fonts and colours, or images. Unfortunately I cannot cite my sources, but I have read that Windows Forms and GDI+ cannot provide me with the desired accuracy. So, is WPF going to provide me with a better solution? Do I need to use the render loop, or some other approach. I am not experienced in such type of performance requirements for desktop applications, and all advices will be appreciated greatly.
I personally love WPF, but I would be very wary of using it for this application. It is not going to have the same time precision as GDI+ or DirectX. There are all sorts things you'll have to work with like the DispatchTimer and it just wasn't build for something like this. WPF is a whole set of gigantic abstractions on top of graphics and the farther you get away from the metal, you're introducing potential problems. If you want to put a video projected on top of a 3D sphere inside a combobox then WPF is the way to go, but if you need accuracy/precision on the scale you're talking, WPF is not the answer. I don't know where you read that WPF will provide you with better accuracy, I can practically guarantee that it will not.
DirectX would most likely be the most accurate in ensuring that a picture is only displayed for 50ms at a time. But GDI+ would be a decent alternative solution because it will make it easier to deal with text from a programming perspective.
Another consideration, screen refresh rates. yikes. if you do the math most LCDs have a 5ms response rate which is 10% of your allotted time. That and they only display at 60Hz. If you're displaying 20 pictures per second (50ms per picture) it is only going to be on the screen for 3 refresh cycles.
I hope this helps.
50 msec isn't long. Maybe encode and play the slideshow as a video?

Sharing/storing video

I need a way to show a grid of videos, where if you hover over one, it will show a 3 second preview. This is all written in ASP.Net using C# and SQL Server 2008.
Questions I have to ask myself -
Would these be stored in a database or on the file system?
How to show these videos? - this is the easy part, just looking for opinions.
Any help would be greatly appreciated.
Storage: there are so many aspects to that decision. Many will say to put the files on the file system but then again that depends on whether you want easy disaster recovery, how you scale, whether your file system or DB supports better caching, etc.
How to show the videos: If your UI is in Flash, that's probably the easiest. If not, you'd probably need to generate a GIF with 3 seconds of video as a preview for each video, which you then load dynamically when the cursor hovers over the still thumbnail.

Why my images are taking too much time to load?

I've read about the LowProfileImageLoader. It will only load the image when the user can see it and will avoid blocking the UI thread.
I added it and tested on my application. All 25 images are from the exact same URL. With the default image it took a little to load but all other images were cached, and the scroll got super fast.
With the LowProfileImageLoader the images were not cached, it was loading 1 by 1 even though it was the exact same image. And when I scrolled down then up it would load the image all over again. And it takes a long time to load them.
Do I have to configure something to keep the images on cache? How do I configure this LowProfileImageLoader?
From what I understood by looking at a windows phone mango video presentation, images are automatically cached without you doing anything.
Video I'm talking about: http://www.wpcentral.com/multitasking-mango-demoed-detail

Is there's a way to protect my slideshow images

I don't want to use flash because it won't allow me to dynamically modify (add, remove) the pictures through my application so I thought about javascript (JQuery Plugins). but the problem is visitors can save the pictures and I don't want that to happen! .. so any ideas ?
Edit
I really appreciate your help and honesty but is JavaScript to have a dynamic modifiable SlideShow for my websites ? .. I don't care about screenshots, what's important is the original picture that I think will be downloaded to the visitor temp files!
The best you can do is a mild deterrent. I've written an HTML5 slideshow used by many. It offers right-click warning to those using it, but it is best referred to as a warning rather than a protection.
First off, if a browser can display an image, any viewer can get them too - no matter what you do - that's just the way the web works. If you really need them protected, then you need to use a significant semi-transparent watermark that touches important parts of the image or limit the viewing only to people who you trust.
If you're interested in a mild deterrent that can still be bypassed quickly by anyone who understands how a browser works, but might slow down non-sophisticated users, then you can implement a couple forms of click protection that make it harder to right-click save your images. Right click protection works best when the actual image you are displaying is not the top level image. This can be done by displaying a transparent image over the top of your slides. This will not be seen, but if a viewer succeeds in getting to a right-click-save menu, all they will succeed in saving is the empty transparent image on top. You can literally use a 1x1 transparent gif image which is tiny and then scale it up to the size of your image to cover it. It will not be seen, but it will defeat right-click save.
It is also common to also put in some javascript that attempts to intercept the right-click operation to prevent that, though this protection is blocked by more and more browsers now (like Firefox 4+) and is far from foolproof. It should not be relied upon.
In the end, these extra steps are only a mild deterrent and will only work with non-sophisticated viewers who aren't very determined. Because, even with the maximum protection in place, one can still look at the media list in the browser and see all the image URLs in the web page or look at the source or DOM or network trace of the web page to see what the URL is of the images that are being displayed. Once the URLs are known, the images can be saved easily. The danger of this kind of protection is that content owners believe it's real protection and they put images at risk that they shouldn't (without good watermarks on them). But, if you fully understand what you're getting (and not getting), you can do it.
It is impossible to Really protect them. If the user can see the image, then the user's browser has downloaded it. So the user has the image on their computer and can do anything they want with it.
There are lots of ways of making it harder for the user though. Disabling right clicking is one way.
If you really need to hide them badly you could use the data uri scheme too, but it really won't stop someone who really wants to get it:
http://en.wikipedia.org/wiki/Data_URI_scheme
You will not be able to protect your images unless you use a watermark which not what you're looking for as I understand you.
You need to remember that the user will always have his printscreen button and many tools that can do the job and that you can't control anyway
Break up your images into pieces, or possibly even embed them in larger junk images. Then use CSS to display the multiple overlapping divs with appropriate background styles to position the pieces where they need to be so to the user they look like one image, kinda like how google maps looks like one large image but is actually made up of many small ones. The user won't know the difference, but if they try to save them locally they'll just get one piece at a time.
Of course, that only works until they realize they can do a print-screen, but it's something. :-)
It is impossible to completely protect your images.
Seriously, if the user can see it in their browser they can save it to their computer.
You are fighting a losing battle here.
Even if you watermark your images, a good graphics program can countact that.
The best thing to do is only display small, low quality images that people wouldn't want to keep anyway.

Categories