GetThumbnailAsync() takes too long in Local Storage - c#

I was creating a Windows phone 8.1 (RT) app where I'm having a few images both in the LocalStorage and also in the Pictures Library where I'm loading the images using GetThumbnailAsync().
For a PNG image of size 6MB+ the GetThumbnailAsync() in PicturesLibrary takes a few msec while the same image when copied to LocalStorage in the App takes around 10 secs to get the thumbnail.
Also I used
getThumbnailAsync(ThumbnailMode.ListView,100,ThumbnailOptions.ResizeThumbnail)
Yet it takes a long time but returns the Thumbnail in the desired pixel size. Can anyone point out why it takes so much time in case of LocalStorage and if there are any alternatives to make it fast.

The system pre-caches thumbnails for images in the pictures library, whereas it can't do that for images in an app's isolated storage.
There are two workarounds here:
Move the picture to a public location where the system can pre-generate a thumbnail
Embed a thumbnail in the EXIF data for the image in your local storage. Then the system can do a fast extract and return a thumbnail more quickly. Currently it has to decode the entire 6+ MB file to generate a thumbnail, where a fast extract only needs to pop open the much smaller thumbnail

Related

AWS S3 Files how to properly store images and image compressing

I am building a mobile app similar to Instagram in terms of working with Images. I am using amazon s3 to store the images and Mysql for the file path. I'm trying to ensure users upload great quality pictures but also ensure the file size is reasonable, Should I compress the images? Does anyone have an idea and what is the acceptable size for an image?
The definition of "acceptable" is totally up to you!
You should certainly store a high-quality image (probably at the original resolution), but you would also want to have smaller images for thumbnails and web/app viewing. This will make it faster to serve images and will reduce bandwidth costs.
A common technique is to have Amazon S3 trigger an AWS Lambda function when a new image is uploaded. The Lambda function can then resize the image into multiple sizes. Later, when your app wishes to retrieve an image, it can point to a resized image rather than the original.
When resizing images, you can also consider image quality. This allows JPG files to reduce in size without needing to reduce in resolution.

SoftwareBitmap uses lot of memory

I am loading some JPEG and PNG images into GridView. I am using Software Bitmap to represent the images.
However, SoftwareBitmap stores an uncompressed form of the image. So the problem is, when loading multiple (many) images, my app eats lots of RAM, and I am concerned about high memory usage.
I have known that the GridView handles virtualization by itself.
While loading only about 150 images (90 MB as compressed image files on disk), the app's memory usage rises close to 500 MB!
How can I optimize? Do I need to use some SoftwareBitmap feature or it's alternative I am unaware of? Or will I have to do some kind of image processing to store compressed version in the RAM (I don't even know if that's possible).

Fast Image Loading from Network Drive in C#

I have a C# application that needs to load about 50 TIFF images from a network drive. Each of these images has a size of about 10-15 MByte. I have to load these images, resize them, and export them in a PDF file.
Currently, I am using the following method to load the images from the network drive
Image image = Bitmap.FromFile(path.LocalPath);
The problem is that loading the 50 images takes quite a lot time that is not tolerable for my application scenario. Is there a way to speed up the image loading process?
I suggest you copy them to a local drive first. I suspect that Bitmap.FromFile may seek around the file (possibly reading redundantly) in a way which isn't a good fit for network drives - whereas just copying the files locally and then using Bitmap.FromFile does the expensive part (the network transfer) once.

How to create a PNG image with the smallest size and good enough for web?

I have a png image of 172kb. Opening it on an image editor and saving as png-8 it becomes 39.3kb and if I set as gif it becomes 42.06kb.
In c# I tried to save as png and the size doesn't change at all. I tried to save as gif, the quality gets awful...
How can I get the same size with c# and keep a good quality to show on the web?
Check this site http://imageoptim.com/
The author says his solution will make your PNG 1/3 size average without loosing PNG compatibility. And it can be even smaller if you can afford lossy compression.
This link gained from QA thread here: What's the most optimal PNG internal format for iOS display can be generated from non-Apple platform?

Image resizing on the fly in asp.net

For simplicity lets say that I have a web page that needs to display thumbnails of images. The images locations are stored in a database(the images are stored on Amazon S3). Is it possible to have my web server scale down the large image before it is delivered to the client? This way I don't have to store thumbnails of every image and the client can download a smaller file.
Every tutorial on this topic over-simplifies the situation and nearly all of them leak memory. It's a long read, but you should know about the 29 image resizing pitfalls so you can avoid them.
I wrote a library to do server-side dynamic image resizing safely. It's not something that can be done properly in 1 tutorial or even 10. You can solve 80% of the bugs, but not 100%. And when you're doing something this resource-intensive, you can't tolerate bugs or memory leaks.
The core library is free and open-source, but the Amazon S3 plugin is part of the Performance edition, which has a $249 license fee. The Performance Edition comes with source, examples, and documentation for S3, MS SQL, Azure, MongoDB GridFS, and CloudFront integration, as well as terabyte-scale disk caching and memcaching.
From the statistics I have access to, it appears that imageresizing.net is the most widely-used library of its kind. It runs at least 5 social networks and is used with image collections as large as 20TB. Most large sites use the S3 plugin, as local storage (or even a SAN) isn't very scalable.
Sure, no problem. There's plenty of resources on the web that show how to dish up an image from a database. So I won't duplicate that here.
Once you've loaded the image, you can easily shrink it using .NET. There is an example at the following URL. It doesn't do exactly what you are doing, but it does generate thumbnails of an image.
http://blackbeltcoder.com/Articles/graphics/creating-website-thumbnails-in-asp-net
Using WebImage class that comes in System.Web.Helpers.WebImage you can achieve this.
You can use this great kid to output resized images on the fly.
Sample code:
public void GetPhotoThumbnail(int realtyId, int width, int height)
{
// Loading photos’ info from database for specific Realty...
var photos = DocumentSession.Query<File>().Where(f => f.RealtyId == realtyId);
if (photos.Any())
{
var photo = photos.First();
new WebImage(photo.Path)
.Resize(width, height, false, true) // Resizing the image to 100x100 px on the fly...
.Crop(1, 1) // Cropping it to remove 1px border at top and left sides (bug in WebImage)
.Write();
}
// Loading a default photo for realties that don't have a Photo
new WebImage(HostingEnvironment.MapPath(#"~/Content/images/no-photo100x100.png")).Write();
}
More about it here: Resize image on the fly with ASP.NET MVC
Here's a great tutorial that shows how to work with WebImage directly from the ASP.NET site:
Working with Images in an ASP.NET Web Pages (Razor) Site
Yes.
You make a ASP.Net page that does Response.Clear(), sets Content-Type-header in Response and sends the binary data of the image (also through Response). The image can be resized on-the-fly, but I'd recommend caching it for some time on disk or so. Then you reference the image from HTML as <img src="http://server/yourimagepage.aspx">. For storing image in memory before sending you can use MemStream.
I have sample code but not in front of me right now, sorry. :)

Categories

Resources