Efficient way to show Google images in C# desktop application - c#

So I'm working on a project that requires being able to bring up google images pertaining to the selected item.
Right now I'm using the Google Custom Search API to make an image search and getting the results back as a json. I then parse out the first FIVE image paths provided and add these as images to a wrap panel.
Quick snippet of what this looks like
BitmapImage bmi = new BitmapImage(new Uri(url, UriKind.Absolute));
image.Source = bmi;
The problem is that this takes on average 20-40 seconds. While the google search takes less than 1.
I initially assumed this is because google is just loading thumbnails while I'm downloading the complete image, but I checked out all the sizes and none of them are larger than 30kb, and all download instantaneously through a web browser.
So I think I'm just approaching this the wrong way.
What would be the right way to load in previews and then allow the user to select one to actually save locally.
Regards.
John W.

Related

How to display svg from url's as image source in WPF

In WPF I'm using uri's as ImageSource for items in a list and it works fine except for url's thats is a .svg url.
I've tried using Svg. It works but the images are messed up and I had to download the file locally.
I also tried using SharpVectors didn't understand how to get it to work and got nowhere using the documentation.
This is my original code and it works for png, gif and jpg:
return new BitmapImage(new Uri(url, UriKind.Absolute));
If would also like to have a solution that does not require me to download files locally first but using Stream or the uri directly.
I can recommend CefSharp.Wpf for displaying SVG's images. It is chromium engine wrapped as WPF or Windows control.
I'm using it successfully to even play quite complex SVG animations.
This would give you possibility to show online image without downloading it.
For more details and samples please refer:
GitHub CefSharp
It is available as NuGet package. The only drawback might be memory footprint and necessity of maintaining browser engine process but beside this it is perfect.

Preload image from URL for KenBurnsView Xamarin.Android

I am using https://components.xamarin.com/view/KenBurnsView
I have several image URL-s by which I want to show them via KenBurnsView
after setting src of KenBurnsView to the first imageURL, at the TransitionEnd I want to replace src with new image URL and restart animation, but I want the image to be preloaded to make everything smooth.
I would preload next image at the TransitionStart event so at the end image could be loaded, but I dont know how to do it.
Image caching is what I mean maybe but I dont know how to cache it very first time
For image caching you can do it yourself, saving the image in the FileSystem when downloaded from internet and next time you need to load the image you check if it's already local and if it's not you just hit the web and save it. There's of course a little more to do like deleting the images in file system after certain period but just wanted to give you the main idea.
For my projects I use this library FFImageLoading. It's well maintained and its use is so simple.
ImageService.Instance.LoadUrl(urlToImage).Into(_imageView);
When the image is loaded from internet the image is cached on disk (by default 30 days but there is an optional TimeSpan so you can choose yours).
Android documentation.

How to Extract Larger Images from an HTML Page to Make Thumbnails (Like Facebook Does)

In my application, I post articles and the entire document is stored as html in the database. In different places in the articles I use images. (By uploading it or just placing img urls).
On the homepage I want to make thumbnails of my desired size, so that I can place some recent articles along with their preview images there.
So, how can I extract larger images from any html document? (So that only relevant images are selected, not any other images)
And from the list of images, how to determine and select image which occurred at first?
I want to use that "one" image to make thumbnail programatically on the server. I
will cache it and then display it on the page.
Like a wordpress application or any other CMS does.
Currently, I use the following approach which is I think is not correct:
At the time of posting an article when I upload images in the editor, I keep the imageId of the of the last uploaded image and store it into the database along with the article. So I have a separate column for imageId for each article I post.
Problem starts when I do not upload any image, then I have to insert a default imageId automatically to avoid problems. This process is annoying. Please help me out. Please guide me the most practiced and the easiest solution available.
The site where I implement all this is http://disneyduniya.in
You can use demo of below code: Generate Web Page Thumbnail Screenshot Image:
Demo link Its working : http://pietschsoft.com/post/2008/07/C-Generate-WebPage-Thumbmail-Screenshot-Image
It will create image file ,save this file As and customize height and width
.

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. :)

Combining URL text box with FileUpload control

I'm developing a web app which allows users to upload images. Instead of forcing them to first download an image I also want to allow them to provide a URL of the image elsewhere on the web.
I've got the code to do this, my question is how can I combine these into one text box that will allow the user to enter either the location of the image on their hard drive or the location of the image on the web.
I'm aware of the ASP File Upload control - but how could I leverage it to do this?
Let them choose like you can here at StackOverflow? (try to add an image to an answer; you get the same option).

Categories

Resources