.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

bind image with byte

Posted By:      Posted Date: October 11, 2010    Points: 0   Category :ASP.Net


i save picture as image in sql database for user profile

now i have a page that sow user profile information an im this page i have a image control to show user avatar with.

in code behind with Userprofile.Avatar code i got the image as byte

can you please tel me how can i  bind the image with this code?


View Complete Post

More Related Resource Links

Binding byte[] to image control in navigation application leaks

Hi there, I have a (minimal) navigation application with two pages. Page1 contains an image. Switching between pages is done via a buttonhandler in code behind, for instance, (this.NavigationService.Navigate(new Page2())) The image is loaded in code behind via: private void LoadImage() { string fileName = "./images/image.bmp"; if (!new FileInfo(fileName).Exists) throw new Exception("File name doesn't exist"); using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read)) { this.ImageData2 = new byte[fs.Length]; fs.Read(this.ImageData2, 0, System.Convert.ToInt32(fs.Length)); fs.Close(); } } ImageData2 is a byte[] property that sends a propertychange event on changing. ImageData2 is bound to an image in xaml: <Image Grid.Row="1" Source="{Binding Path=ImageData2, Mode=OneTime}"/> When we unload Page1 the following clean up code is executed private void Page_Unloaded(object sender, RoutedEventArgs e) { this.ImageData2 = null; GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); } Now, when I start changing pages, I expect the Page we leave to unload, so the GC removes the byte array. However, it doesn't. Am I missing something? Binding the image to a BitmapImage (ImageData1, as you might have guessed:-) ) doesn't leak.

Converting a System.Windows.Control.Image object to byte array.

Hi i need to convert a specific System.Windows.Control.Image object into an (int) array, because i'm trying to convert a silverlight application into a wpf project. private void createGi02GradBrush()<br/> {<br/> WriteableBitmap oWriteableBitmap = new WriteableBitmap(256, 256);<br/> Image oImage = new Image();<br/> oImage.Arrange(new Rect(0, 0, 256, 256));<br/> oImage.Measure(new Size(256, 256));<br/> oImage.Source = new WriteableBitmap(256, 256);<br/> Gi02GradShaderEffect oGi02GradShaderEffect = new Gi02GradShaderEffect();<br/> oGi02GradShaderEffect.pArray = oPImageBrush;<br/> oGi02GradShaderEffect.gi1GradArray = oGi1GradImageBrush;<br/> oImage.Effect = oGi02GradShaderEffect;<br/> oWriteableBitmap.Render(oImage, null);//here<br/> oWriteableBitmap.Invalidate(); <br/> this.oGi02GradImageBrush = new ImageBrush();<br/> this.oGi02GradImageBrush.ImageSource = oWriteableBitmap;<br/> } I've found some similar topics however Image object is not the same and most of its methods aren't available. Here I'm rendering a writablebitmap with a given Image object, but in wpf we need an array. oWriteableBitmap.Render(oImage, null); Any idea? Thanks. Joseph.  

Exporting image byte stream to Excel



I am working on implementing exporting data to Excel functionality in ASP.Net and as part of that an image stored in the database has to be exported to Excel along with some other content. I am able to write the content to Excel by referring to the required cells. Is it possible to write the image byte stream read from the database which is in the form of byte[] directly to Excel sheet without saving that to physical disk?

Please suggest how to write image byte stream to Excel without saving the image to physical disk?

Thank you,


How to Convert System.Drawing.Image Variable to Byte variable



I got a variable of type System.Drawing.Image and need to convert it to a variable of type byte so I can store the image in the database. Can someone show me how to do that in VB.NET code.

Thanks alot

Converting an Image/BitmapImage object into Byte Array and vice versa

Hi,  I have an requirement of developing an application (WPF) that recevies image object from WCF service.

my approch is to convert the image object into stream of bytes (Byte array) in WCF part and then send to  client application. Then client application converts the byte array back to image object.

I am not able to find right sample for my approach.

would you give me guidance and would be gr8 if you provide some samples.


Resize image and get new byte size without saving it


Hi Guys,

I'm making an application that needs to be able to take a user specified image file and upload it into a database that only accepts images of 10 KB or less. So I want to let the user select an image and then have the option of resizing it and if possible also decreasing the quality - I'm sure I can figure out how to do both of these things on my own but the thing I'm not sure about is how I can tell what size the resulting image will be without actually writing it to disk. I thought the SourceStream property of the BitmapSource class would be useful but when I try to access it I just get told that the stream has been closed. Any ideas?




My website: www.cjwdev.co.uk My blog: cjwdev.wordpress.com

How to convert image class object to byte type in order to insert database


I am trying to resize images after uploading and than inserting them into my database.

Dim newMainImage As System.IO.Stream = System.IO.Stream.Null
resizedMainImage.Save(newMainImage, jgpEncoder, myEncoderParameters)
Dim newMain As Image = Image.FromStream(newMainImage)

I was able to resize it however I couldnt find a way to convert image object to byte() in order to

I need something like

Dim ImageContent(newMain.ContentLength - 1) As Byte

newMain.InputStream.Read(ImageContent, 0 , newMain.ContentLength)

I need to convert image object to a file type in order to get its contentlenght and use .inputStream.Read function. Or is there any other way?

Save byte array to Image with transparent background to client machine


I have an asp.net website and am exporting an image from the Report Viewer.  I have created my byte array to get the data from the report viewer and now I need to save an image with transparency to the client machine using the response headers.  I was able to do this by saving the array to the server as a bmp and then adding transparency and saving to the client as a GIF; however, the requirement has changed and now I need to do this without saving the file to the server and even though I have found several solutions using unsafe code these will not work for us because we are not allowed to use unsafe code in our environment. 


So in short I need a way to go from an array of bytes to a transparent gif and save to the client machine without using unsafe code and without saving a file to the server. 

I have got a byte array and want to convert it into a image

Byte[] photo = Convert.FromBase64String(value);
//old 1
MemoryStream ms = new MemoryStream(photo, 0, photo.Length);
ms.Position = 0;
ms.Write(photo, 0, photo.Length);
System.Drawing.Image image = System.Drawing.Image.FromStream(ms, true);// this line giving exception parameter not valid


Is it possible to bind a xaml control's image source directly from the resource file ?


Hi all


Is it possible to bind a xaml control's image source directly from the resource file ?




Image with data source bind won't update on WPF Window


This is the WPF Window Class:

  public partial class MainWindow : Window
    public Bitmap image;
    public CaptureModel cm = CaptureModel.Instance;
    public MainWindow()
      image = cm.Image;
      DataContext = this.image;
      CaptureModel.Instance.PropertyChanged += new PropertyChangedEventHandler(Instance_PropertyChanged);


    void Instance_PropertyChanged(object sender, PropertyChangedEventArgs e)

      if (e.PropertyName == "ImageChanged")
        this.image = cm.Image;


And this is the .xaml for it:

<Window x:Class="TestApplication.MainWindow"

pdf byte array to image


ok ppl i'm using ItextSharp.dll which gives me the whole content of the pdf page in terms of byte array.

so i need a way to convert that pdf byte array to image

is it possible ?


how to bind image url when image is out of application


I've  to bind a image to image1 control and the image is out of the application area

if I ser Image1.ImageUrl="D://2.jpg"; It is working fine on server machine.

But when I run it on another machine

using IP address of server image not displayed


Please Help if any thank u...

Built-in Functions - Text and Image Functions in SQL Server

Text and image functions operate on TEXT, NTEXT and IMAGE data types. These data types are deprecated with SQL Server 2005 and should be replaced by VARCHAR(MAX), NVARCHAR(MAX) and VARBINARY(MAX) when possible. Alternatively you can also consider storing large string values using XML data type. Text and image functions are nondeterministic.

Future versions of SQL Server will not support TEXT, NTEXT and IMAGE data types. Columns with TEXT / NTEXT data type do not support commonly used string functions such as LEN, LEFT, RIGHT, etc. Furthermore, due to the large size of TEXT data you''re likely to see performance issues if you store such data in the database. However, at times you can''t help but use the TEXT / NTEXT / IMAGE data types (for example when supporting 3rd party databases when you cannot change the schema) - this is when text and image functions come in handy.

Program for Format Conversion of An Image

.NET provides extensive support for image conversion. Any image can be processed from one format to another. Most common formats to which .NET have support for are .BMP, .EMF, .GIF, .ICO, .JPG, .PNG, .TIF and .WMF.

Configuring Profile Image Export in SharePoint 2010

It's no secret that I am thrilled with the new social features of SharePoint 2010. I am most excited about the new Profile Picture handling. I strongly believe that the more we can show the faces of our colleagues to one another the more connected we will feel. Clearly Microsoft feels that way as witnessed by the many features that make use of the Profile Image like the Activity Feed and Colleagues list

Built-in Functions - Text and Image Functions

Text and image functions operate on TEXT, NTEXT and IMAGE data types. These data types are deprecated with SQL Server 2005 and should be replaced by VARCHAR(MAX), NVARCHAR(MAX) and VARBINARY(MAX) when possible. Alternatively you can also consider storing large string values using XML data type. Text and image functions are nondeterministic.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend