This is a migrated thread and some comments may be shown as answers.

BinaryImage display from codebehind

3 Answers 212 Views
BinaryImage
This is a migrated thread and some comments may be shown as answers.
Thomas Frohe
Top achievements
Rank 1
Thomas Frohe asked on 28 Jan 2010, 04:18 PM
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

3 Answers, 1 is accepted

Sort by
0
Accepted
Rosen
Telerik team
answered on 29 Jan 2010, 01:03 PM
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.
0
Thomas Frohe
Top achievements
Rank 1
answered on 30 Jan 2010, 01:17 PM
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.
0
Thomas Frohe
Top achievements
Rank 1
answered on 30 Jan 2010, 07:28 PM
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.
Tags
BinaryImage
Asked by
Thomas Frohe
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Thomas Frohe
Top achievements
Rank 1
Share this question
or