Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have this code (please see below) when the user is selecting an image
i'd like to display a preview of the image. It works well for standard formats
but since tiff is not supported by some of the browser it will show a broken image if
user is selecting a tiff image. I have no problem converting the image when i'm getting
it from the server my issue is on the client side.

The relevant javascript:
C#
$(function () {
    $(document).on('change', '#ImageData', function (evt) {
        try {
            var file = evt.target.files[0] || evt.srcElement.files[0]; // Read the first file from the list.
        }
        catch (e) {
            // Something went wrong or no file was chosen - 
            // remove current image and return.
            removeImg();
            return;
        }

        if (isImage(file)) { // Add only valid images
            var reader = new FileReader();
            reader.onloadend = (function () {
                return function (event) {
                    var img = document.getElementById('img-id');
                    img.src = event.target.result;
                };
            })(file);
            reader.readAsDataURL(file); // Read in the image file as a data URL.
        }
        else {
            removeImg(); // If there is already image remove it
        }
    });
});



XML
The relevant html:
@Html.ValidationMessageFor(model => model.imageFile, "", new { @class = "text-danger" })
@Html.TextBoxFor(model => model.imageFile, new { type = "file", name = "imageFile", id = "ImageData" })
<img id='img-id' style="height: 300px; width: auto;">
Posted
Updated 3-Mar-15 8:28am
v4

You can't show the tiff image on browser, because it is not render-able image format for browser.

Better you can convert the tiff image's stream into base64 string then put it into img tag's src attribute.
 
Share this answer
 
Comments
sbs21 3-Mar-15 4:12am    
Solai Raja thanks for your prompt answer. I know how to convert it on the server side, can you show me how to do this on the client side (probably using javascript)?
Solai Raja 3-Mar-15 4:32am    
i think, we could not do it in javascript side.
sbs21 3-Mar-15 14:27pm    
Thanks again Solai Raja. So there is no way to do this anybody???
Solai Raja 3-Mar-15 23:54pm    
I Guess so.! In future we may get this done by browser itself :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900