Force Image control to re-download the image - xaml

I have an Image control on Page1.xaml that is pointing at a URL: http://www.example.com/blah.jpg
I navigate to Page2.xaml and upload a new image to that url using my WebAPI. I call Frame.GoBack() to navigate back to Page1.xaml.
The old image is still displayed in the Image control. How can I make sure that Image control re-downloads the image even though its at the same URL?

The only way I found was to append a query string to the end of the image. It's a bit of a hack and it can interfere with Save operations but it is effective.
Just to be clear, I set the property with the image url with a value like this:
"http://www.example.com/blah.jpg?id=" + Guid.NewGuid()
That triggers the RaisePropertyChanged event and the Image control is tricked into thinking the image changed.

Set the BitmapImage.CreateOptions property to IgnoreImageCache.
From MSDN:
The other possible value for CreateOptions is
BitmapCreateOptions.IgnoreImageCache. You should only use
BitmapCreateOptions.IgnoreImageCache in cases where you know that the
source image file as retrieved by URI has the potential to change over
time. Otherwise, setting CreateOptions to use
BitmapCreateOptions.IgnoreImageCache causes all newly retrieved image
sources to be decoded again, which can negatively impact performance.
...

Related

Overwrite IpReflection

I want to change Avatar, but I want to use ipReflection() too.
when I upload first image it works but when I change it stays the same, I tried to unbind then bind again same image but it doesn't work.
ipUnbindFile($image, 'UserModuleLogo', ipUser()->userId(), 'file/repository/UserFiles/');
ipBindFile($image, 'UserModuleLogo', ipUser()->userId(), 'file/repository/UserFiles/');
Binding the file is inserting its data to a database. There could be two issues, why changes aren't visible instantly:
Browser cache. You save a new file with the same file name and browser thinks nothing has changed.
Reflection cache. If filename is the same and options are the same, ImpressPages pulls image from the reflections without touching a new file.
To fix the first issue, always change filename or add random parameter and the end of the file, i.e. "image.jpg?1029231230".
To fix the second issue, always delete all reflection before replacing the file.

Databinding uri source of imagebrush

In my application i am binding several properties to a custom user control, and everything works fine, except the images are not showing. For binding i have used the following codes:
Categories.Add(new Models.Category { Name = "Pizza", Count= 4, ImageUri = new Uri("Images/pizza.png", UriKind.Relative) });
I have also tried with different urikinds but the images are never showing.
what could go wrong? The images are in my solutions Images folder.
Use the ms-appx URI scheme:
ImageUri = new Uri("ms-appx:///Images/pizza.png");
Take care to really write ///.
Also make sure that the Build Action of the image file is set to Content, as pointed out in the other answer. Setting Copy to Output Directory does however not seem to be necessary.
Be sure you set the properties of the image so that it is available during runtime. Sometimes if employing Design Time data in Blend, you will see the images in Design Time, but then nothing during run time. The reason is that the images were never deployed with the rest of the solution. Be sure the Build Action on each image is set to Content and I usually set the Copy to Output Directory to Copy if Newer.

Resizing in Dropzone.js?

Is there an example of the resize function for dropzone.js? I don't really understand how it works, it says:
"Resize is the function that gets called to create the resize information. It gets the file as first parameter and must return an object with srcX, srcY, srcWidth and srcHeight and the same for trg*. Those values are going to be used by ctx.drawImage()."
But I don't really get how to use it. So far I'm resizing the images on server-side, but I'd like to do it client-side and I think this might help. Any other solutions using dropzone.js if not this one?
I believe the built-in resize function in dropzoneJS is what is used to create the thumbnail, not resize the photo client-side, per se. There might be some way you could leverage it by setting the thumbnail dimensions to what you want to save to the server, and overwriting the file being saved with the thumbnail, but I'd have to hack about for a spell to offer you any code suggestions for that.

How to save Image Control to local file in Windows 8?

I'm writing Client-Server application, in which I get item with Image Url. This Url is binded with Image control:
<Image Source{Binding ImageUrl} x:Name="img_avatar" Stretch="UniformToFill" Width="48" Height="48"/>
I want to save the image from Image.Source to the local folder without any methods which are using download operations.
Please help m someone !!!
There is no way to do what you ask about. When you set an Image control's source to a Uri - it gets converted to a BitmapImage which doesn't expose any API that would let you save the file or even extract a bitmap. If you want to avoid multiple downloads of the image you can download it as a file once and load a BitmapImage from the file instead of Uri.
I believe with a little bit of reflection hackery, it should be doable. But a lot better solutions exist, so yeah..
Either subclass Image or write attached property to handle logic. All you have to do, is just load image yourself into MemoryStream and create BitmapImage manually(behind subclassed Image or attached proeprty).
This way you can expose new property that gives direct access to MemoryStream, and from there you can save file to HDD without wasting precious memory.
Bonus points if you can also keep the Source="{Binding}" syntax while providing this functionality.

How do you assign a default Image to the Blob object in Play framework?

I followed this nice article
http://www.lunatech-research.com/playframework-file-upload-blob
and have a perfectly working image upload solution
My questions is, if the user doesn't select any image, how do I assign a default image during save (probably stored in the server)?
if (!user.photo)
user.photo= ?;
user.save();
The one-hack that I can think of is upload the default image and see which UID "Play" stores in the /tmp directory and assign that above. Is there an elegant named* solution to this?
when I say named, I mean I want the code to look like (which means I know what I'm doing and I can also write elegant automated code if there are more than one picture)
user.photo= "images/default/male.jpg"
rather than (which means I'm just hacking and I can't extend it elegantly for a list of pictures)
user.photo= "c0109891-8c9f-4b8e-a533-62341e713a21"
Thanks in advance
The approach I have always taken is to not change the model for empty images, but instead do something in the view to show a default image, if the image does not exist. This I think is a better approach because your are corrupting your model for display purposes, which is bad practice (as you may want to be able to see all those who have not selected an image, for example).
To achieve this, in your view you can simply use the exists() method on the Blob field. The code would look like
#{if user.photo.exists()}
<img src="#{userPhoto(user.id)}">
#{/if}
#{else}
<img src="#{'public/images/defaultUserImage.jpg'}">
#{/else}
I have assumed in the above code that you are rendering the image using the action userPhoto as described in the Lunatech article.
I'd assume you can store the default image somewhere in your applications source folder and use
user.photo.set(new FileInputStream(photo), MimeTypes.getContentType(photo.getName()));
to save the data. Photo is just a File object, so you can get the reference of your default image and use it.