Click here to Skip to main content
15,880,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have data of an image in the form of streambytes in my database with image data type, i want to display the image, please help how can i do this?

Actually iam using the Web based application and want to show the image as a background to a
ex:

<table><tbody><tr><td style="background-image:removed('the image');"></td></tr></tbody></table>


sorry for not giving the complete problem
Posted
Updated 30-Jan-11 23:55pm
v2

This[^] link provides some information that might help you.
 
Share this answer
 
Comments
JF2015 31-Jan-11 3:44am    
Good find.
Abhinav S 31-Jan-11 3:47am    
Thanks.
Search Google[^], and you'll get a ton of answers.

Regards
Espen Harlinn
 
Share this answer
 
Comments
JF2015 31-Jan-11 3:43am    
That's always the best advice for this kind of questions.
Sergey Alexandrovich Kryukov 31-Jan-11 16:14pm    
That's right (my 5), I should have mentioned array of bytes as a more universal presentation to expect.
--SA
A bit vague, I'll attempt a guess:

Read the data into a buffer and create a MemoryStream
byte[] buffer; // read data to this. omitted.
MemoryStream stream = new MemoryStream(buffer);


Create a Bitmap from the stream
Bitmap bitmap = new Bitmap(stream);


In the form's Paint event handler, draw the image thus:
C#
private void Form1_Paint(object sender, PaintEventArgs e)
{
    e.Graphics.DrawImage(bitmap, x, y);
}


x and y are the coordinates of the place where you draw the image.
(look up each method in MSDN for details)
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 31-Jan-11 15:51pm    
Indivara, this is a good clarification to my rather short answer - my 5.
I decided not to detail if memory stream should be used or not, because I was confused by OP mentioning of "streambytes". I though OP already might have a stream, in this case re-writing a stream to read from memory would be redundant. How do you think, what it was?
--SA
Indivara 31-Jan-11 19:37pm    
Thanks Sergey... you seem to be voting for most of my answers :)

Apparently I was completely off, the question's been updated. You were right, we should ignore this type of question
Sergey Alexandrovich Kryukov 31-Jan-11 20:12pm    
I do vote but not specifically for you answers. And I don't touch something I don't know well enough, like SQL.
--SA
Indivara 1-Feb-11 1:40am    
That came out backwards. I mean almost all my votes are from you...
Sergey Alexandrovich Kryukov 1-Feb-11 2:59am    
No, this is in historical order...
Assuming the question is about System.Drawing, you need to read your image from stream, see 3 overloaded methods System.Drawing.Image.FromStream. You can draw the image in Paint event:

C#
MyControl.Paint += delegate(object sender, PaintEventArgs eventArgs) {
    //...
    System.Drawing.Point imageOrigin = //...
    //...
    eventArgs.Graphics.DrawImage(myImage, imageOrigin);
} //Paint


In WPF, you don't need to render like this, you should use similar but quite different API for images... do you need help on WPF? (You should always indicate in question what UI library you want to use: System.Windows.Forms, WPF, ASP.NET or something else (Qt, etc.))

—SA
 
Share this answer
 
Comments
Espen Harlinn 31-Jan-11 15:08pm    
Good advice, 5+
You can see this links
Click
Click
Click
 
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