2

I have images in an SQL Server table that I want to display in a Dev Express ASPxImageZoom control.

This control has an ImageUrl property of type string.

I don't want to create lots of temporary files on my file server. Is there any way I can set the ImageUrl without creating a temporary file ?

I am writing a property editor for use in a Dev Express XAF application. It contains the code

protected override void ReadViewModeValueCore()
        {
            var zoom = (ASPxImageZoom)ZoomControl;  // where ZoomControl is a WebControl
            var bytes = (byte[])PropertyValue;
            if (bytes.Length <= 0)
            {
                return;
            }
            var base64String = Convert.ToBase64String(bytes, 0, bytes.Length);
            zoom.ImageUrl = "data:image/png;base64," + base64String; // fails if length is too long.
        }

If I have a large image I get an error.

The specified path, file name, or both are too long. The fully qualified file     name must be less than 260 characters, and the directory name must be less than 248 characters

The only way of setting the image for the control is via setting the ImageUrl which is a string.

Kirsten
  • 15,730
  • 41
  • 179
  • 318
  • This relates to my question http://stackoverflow.com/questions/34304258/how-do-i-set-the-contents-of-an-aspximagezoom-control – Kirsten Dec 18 '15 at 20:01
  • you can open up a servlet/service, get the image name as a parameter on that service, and print the image content to response output. then as your ImageUrl, use that service url with image name included as a parameter. take a look at this: http://stackoverflow.com/questions/6987433/display-image-from-database-in-asp-net-with-c-sharp – tt_emrah Dec 18 '15 at 20:03
  • How do I pass the byte array to the page load? – Kirsten Dec 18 '15 at 20:15
  • @kirsteng you don't need to pass the byte array to the page load. – tt_emrah Dec 18 '15 at 20:16
  • The image is coming from the database. I will add the code that converts it to a bytearray – Kirsten Dec 18 '15 at 20:18
  • @varocarbas OP says the images are already stored in db as blob? – tt_emrah Dec 18 '15 at 20:18
  • @kirsteng put only image name if you have, or even image id in ImageUrl. using the image name or id, read that whole binary data in a service and print that data to http response output. and still, take a look at the link i wrote in my initial comment. – tt_emrah Dec 18 '15 at 20:26
  • I don't have devexpress but you are facing the problem wrongly anyway. If you have the array of bytes, you should try to convert it directly into an image (for example: http://stackoverflow.com/questions/9173904/bytearray-to-image-conversion) and then associate this image with the given control in case of being possible (what I don't know). Otherwise, you would have to store it locally and pass the associated URL via ImageUrl. But your code doesn't make any sense, this is not an URL. In any case having temporary images is not an issue at all, you can delete them whenever you want. – varocarbas Dec 18 '15 at 20:28
  • @tt_emrah Thanks for the correction; I misread the description. In any case, why do you need a service here? You can convert an array of bytes into an image (assuming that they are forming a valid image) and then use this image as you please (and the given control allows you to). A service has nothing to do here. – varocarbas Dec 18 '15 at 20:31
  • @varocarbas if you don't want to iterate through every image and set their content on page load or whenever the page content is changed, you bind the image URL pattern you use to a service/servlet and don't care about the rest. so yes, technically you can do it without a service, but that way you have to track down every single image on the page. – tt_emrah Dec 18 '15 at 20:40
  • @tt_emrah So... you are saying that if "something takes care of it", you wouldn't need to take care of it. What is the difference between "service/servlet" (getting all the bytes; how? Good question) and the code which the OP has to write? You have X number of chunks of information which have to be converted into images (and then added to a control); there is no way to avoid iterating through all these chunks. As said from the start, the OP is unnecessarily overthinking what shouldn't a problem. Loop + bytes-to-image + control (+ deletion of temp. files if you wish), end of the story. – varocarbas Dec 18 '15 at 20:44
  • @varocarbas "What is the exact difference between "service/servlet" and the actual code that the OP has to write?" the answer is, it saves you from doing this: "there is no way to avoid iterating through all the images, you would have to do that." been there, done that. anyways, whatever your best practice is, proceed with that. i give up. – tt_emrah Dec 18 '15 at 20:48
  • @tt_emrah What I meant with my previous comment was that "service/servet" = program; the OP is asking about how she can write a program to perform certain action and your recommendation is "write a program". Anyway... very interesting conversation. Hopefully the OP (and future readers) has got the main idea of my comments; that is: don't waste too much time on over-thinking abstract concepts + this is just: bytes from database + bytes into image + into control (directly from the image if possible, or from the local URL/path), to be done N times (= via loop). You might remove temp files too. – varocarbas Dec 18 '15 at 20:58
  • I updated the question to show that the only way of setting the image in the control is to set ImageUrl which is a string. – Kirsten Dec 18 '15 at 21:55

1 Answers1

0

The problem was solved in this question

    string base64String = Convert.ToBase64String(bytes, 0, bytes.Length);
    ASPxImageZoom1.ImageUrl = "data:image/png;base64," + base64String;    
Community
  • 1
  • 1
Kirsten
  • 15,730
  • 41
  • 179
  • 318