BinaryImage display from codebehind

4 posts, 1 answers
  1. Thomas Frohe
    Thomas Frohe avatar
    6 posts
    Member since:
    Nov 2009

    Posted 28 Jan 2010 Link to this post

    I have BinaryImage working in a grid flawlessly. Now I want to display the binary image on another page in a asp:placeholder control. I have been unable to find any examples of RadBinaryImage being created and made to display from the codebehind. All my attempts have failed. the original images that were uploaded are jpeg.  I have been getting the missing image placeholder in IE when i attempt to add the BinaryImage control to the placeholder control collection. I'm just looking for a simple working example of this done in the codebehind. the only existing control on the page is the placeholder. If anyone can help, I would be grateful. Thank you
  2. Answer
    Rosen
    Admin
    Rosen avatar
    3234 posts

    Posted 29 Jan 2010 Link to this post

    Hi Thomas,

    I have attached a small sample app which demonstrates how to achieve the programmatic creation of RadBinaryImage control.

    Greetings,
    Rosen
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Thomas Frohe
    Thomas Frohe avatar
    6 posts
    Member since:
    Nov 2009

    Posted 30 Jan 2010 Link to this post

    Thank you Telerik. This works fine and I don't want to seem ungrateful, but I'm afraid I may not have been specific enough in my original request. I have not had any problems with physical image files located on disk, It is binary image data stored in a DB that I cannot get to display. I only get the missing image placeholder.

    Here is what I've tried so far to make this work.

    DataSet ds = PhotoProvider.GetBinaryPhotos(Device.DeviceNumber.Trim()); 
     
    ... 
    DataRow dr = ds.Tables[0].Rows[0]; 
    ... 
     
    biPhoto = new RadBinaryImage(); 
    biPhoto.ID = Guid.NewGuid().ToString(); 
    biPhoto.DataValue = GetImageData((Byte[])dr["FrontPhoto"]); 
    biPhoto.AutoAdjustImageControlSize = false
    biPhoto.Width = Unit.Pixel(150); 
    biPhoto.Height = Unit.Pixel(100); 
    PhotosPlaceHolder.Controls.Add(biPhoto); 
     
     
    private byte[] GetImageData(byte[] bImage) 
          using (System.Drawing.Image image = System.Drawing.Image.FromStream(new MemoryStream(bImage))) 
                { 
                    { 
                        image.Save(memoryStream, ImageFormat.Jpeg); 
                        return memoryStream.ToArray(); 
                    } 
                } 
            } 

    It's still giving me the missing image placeholder. Again, the images are stored in a DB Table and display fine in the grid on another page. I added a watch on biPhoto and placed a braekpoint just after the GetImageData() call and I see that biPhoto.DataValue has {Dimensions:[26900]} which is correct for the image I am loading from the db.
  5. Thomas Frohe
    Thomas Frohe avatar
    6 posts
    Member since:
    Nov 2009

    Posted 30 Jan 2010 Link to this post

    I'm not sure how it happened but I haven't made any more changes since the last post and it just started working. Anyway, Thanks Telerik. you did get me pointed in the right direction.
Back to Top