.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

linq to sql varbinary assign to image source

Posted By:      Posted Date: September 11, 2010    Points: 0   Category :WPF
Hi All, can you please tell me why this doesnt work:   <Grid> <Image Source="{Binding Path=currentUser.userStatus.icon.bm}" Width="89" Height="90" Margin="309,140,270,99" Name="im" /> </Grid>   where as if I assign the image source via the code behind it does? im.Source = currentUser.userStatus.icon.bm; The currentUser.userStatus.icon.bm object is a BitmapImage type generated from a database varbinary field using linq to sql partial methods like this:   public partial class icon { public BitmapImage bm = new BitmapImage(); public System.Drawing.Icon ic; public System.Drawing.Image img; partial void OnLoaded() { byte[] data = (byte[])this.imageBinary.ToArray(); MemoryStream strm = new MemoryStream(); strm.Write(data, 0, data.Length); strm.Position = 0; img = System.Drawing.Image.FromStream(strm); System.Drawing.Bitmap b = (System.Drawing.Bitmap)img; ic = System.Drawing.Icon.FromHandle(b.GetHicon()); //string imagePath = "Icons/go-down-8.ico"; //System.Drawing.Image img = System.Drawing.Image.FromFile(imagePath); //BitmapImage bi = new BitmapImage(); bm.BeginInit(); bm.DecodePixelWidth = 128; MemoryStream ms = new MemoryStream(); if (this.ext

View Complete Post

More Related Resource Links

How to retrieve image from DB with Linq and diplay in Image Control


Hi all-


I'm using the file upload to let the user upload a single file.  Here's the code I'm using to then upload to the DB.  How do I reverse this process and dowload the image into the control for it to display on a different page?

Here's my code for the upload - which I think works but can't confirm until I can see the download since all I see in the DB is "binary data"

'update DB with new Image 
        If FileUpload1.HasFile AndAlso FileUpload1.PostedFile.ContentLength > 0 Then
            'Read the file in to a byte Array.
            Dim filebyte As Byte() = FileUpload1.FileBytes
            Dim fileBinary As New System.Data.Linq.Binary(filebyte)
                Dim c3 = (From c In dc.ProductImages _
                          Where c.userID = userGuid _
                          Select c).FirstOrDefault

                c3.productImage = fileBinary

            Catch ex As Exception
                Throw ex
            End Try
Here's my attempt at the retrieval, which isn't working:
                    Dim currentImage = F

ssis sql 2000 image to 2008 varbinary Failed to retrieve long data for column

Hi, I have a task that to migrate the image type column from sql 2000 to varbinary type in sql 2008. The source column having 3812353 max datalength size for the column. The package always failed with following error message. [OLE DB Source [13177]] Error: Failed to retrieve long data for column "attch_file_content_t". [OLE DB Source [13177]] Error: There was an error with output column "attch_file_content_t" (13209) on output "OLE DB Source Output" (13187). The column status returned was: "DBSTATUS_UNAVAILABLE". [OLE DB Source [13177]] Error: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR. The "output column "attch_file_content_t" (13209)" failed because error code 0xC0209071 occurred, and the error row disposition on "output column "attch_file_content_t" (13209)" specifies failure on error. An error occurred on the specified object of the specified component. There may be error messages posted before this with more information about the failure. Meng Chew

Failed to set image source with string resource

User can set image source property like this: <Image Source="pack://application:,,,/MyResource;component/Images/1.ico" /> I think the source string is a little bit longer, so I want to make it as string resource: <sys:String x:Key="StringSourceKey">pack://application:,,,/MyResource;component/Images/1.ico</sys:String> After define the string resource, I use it to set image source, like this: <Image Source="{StaticResource StringSourceKey}" /> But, this time, it failed. It doesn't work. I think it is a contert error. Anybody know what's wrong?  Or any method to make the resource uri path shorter? Thanks.

assign style to image in codebehind

how can i assign the style declared in <window.resources> in xaml to the image dynamically created in the codebehind like : Image img=new Image(); img.Style=?? thanks

How convert bitmap to Image.source ?

I hold some bitmap object in the memory  ( simple System.Drawing.Bitmap ). I want to make some wpf image control to show this bitmap. I dont want to save the bitmap to the disk and then load it as URI to the wpf image control So, How can i do this simple action ?   Thanks.

CollectionViewSource Source = Linq to SQL

Hi, I am trying to bind data in my WPF Application using CollectionViewSource and LINQ to SQL. I have the following code in my XAML Where dbml:VendorsDataContext is my dbml file. In the code behind i have written the following code: addressViewSource.Source = bpo.GetVendorAddrTable(_vendorID); Where GetVendorAddrTable has the following code: var addr = from a in vendorsDC.tblVendor_Addresses where a.vendorID == _vendorID select new BussinessHelper.AddressContacts { VendorID = a.vendorID, Address1 = a.address1, Address2 = a.address2, City = a.tblVendor_City.cityName, State = a.tblVendor_State.stateName, Country = a.tblVendor_Country.countryName, VendorAddrID = a.vendorAddressID, CompleteAddr = a.address1 + a.address2 + a.tblVendor_City.cityName + a.tblVendor_State.stateName + a.tblVendor_Country.countryName                        };                  return addr;  When i run my application there is no data being bound. The CollectionViewSource source is null when i checked with code behind. Any ideas how to correct this?

Urgent How to Create it ,Object Data Source ,Linq and sql or other any way


my query is



my data is

HR    HR    Rec    Records    Leave    Leave Records    HRL.0001    Policy and Process for leave record.    27.06.2010    30.06.2010    WIP    Edlink
HR    HR    Rec    Records    Leave    Leave Records    HRL.0002    Quarterly Review    01.07.2010    04.07.2010    Planned    Edlink
HR    HR    DB    Database    SAL    Salary    DDS.0001    Calculation of Monthly salary    08.08.2010    09.08.2010    WIP    Edlink
HR    HR    Rec    Records    Ind    Induction Records    HRI.0001    Completion of dossiers.    08.07.2010    10.07.2010  

Value Converter Without Binding On Image Source


I need to get the path of an image through a value converter. However I can't find any examples of using a value converter without binding.

I would be looking to do something along these lines:

<Image source="{Value=Image1, Converter={ImageConverter}}" />

The image converter will then go check an image folder and return the correct file path.

Set Image Source to DIB in Memory?


Hello all.

I have a piece of hardware saving image data to memory which I would like to retrieve and set as the source to an Image element.  I am able to ask the hardware for a DIB handle to the image -- the return value is documented as "a long, which should be cast to a HBITMAP".  How can I do this in WPF?

I'm currently reading up on BitmapSource.Create(), which takes an IntPtr to memory, but I'm not sure it is expecting a DIB or not.  Also, the function asks for "stride" which I am unfamiliar with computing.  This appears to be the most promising though, since I can set it straight to an Image.Source parameter.

The hardware I have also has a function to grab a LPPICTUREDISP handle, which is documented as being compatible with the "Picture Object" of Visual Basic and C++.  From my reading so far it doesn't sound like this is something that is better suited for my needs, but I'm not sure.

Thanks for any help

How to change wpf image source on runtime ?


I get new bitmap from some other component ( dont have any control on the other component ) every 5 seconds and i need to update my wpf image control with the new bitmap ( every 5 seconds ... ).


[ i cant save the bitmap to the disk and then load it as file ]

I cant find any way to update this wpf image control in run-time.

How can i do it ?


Can't update image.source at runtime ( ??? )

I change wpf image.source dynamically during runtime.
Its seen everything is find - the image is not empty ( i saving it to my disk )...
but on the "image.source = ... " i dont see any image on the Image controler.
Actually - i dont see any image on the image controler.

I check if the Image controler can have some hard code image ( not change on runtime ) and its look fine also. Just update the image.source is not update the right image on the runtime.

The code is simple 3 line ... function name that get argument of BitmapImage and then call => image.source = BitmapImage - that it ===> image is the x:Name of the Image object on the xaml.

Any suggestion? what to check ... ? what is wrong ?


Scaling an image source

I have an image in which I set the image.Source to a writeableBitmap - I want to know how to scale the image.Source so the whole writeableBitmap fits into the image control initially, to avoid having to scroll.

How do i assign an image to a button ?


What is the correct syntax

i can size the button, and display it but for some reason i can't add an image

i am using VB 2010 and .Net 4



LINQ data source control and db connection string


I have designed a few pages which use LINQ datasources and Gridviews to maintain data.

I have built a data layer which happily uses System.Web.Configuration.WebConfigurationManager.ConnectionStrings("myConnectionString").ConnectionString

However, the LINQ data source controls use Settings.designer.vb MySettings class definition which is auto generated and doesn't except the above Connection string.

Any ideas?

Image Source equivalent in c#


I am building a class library project.  I have embedded images into this library and have several controls that use the following XAML:


Code Snippet


<Image Source="./Resources/Images/myImage.png"/>




What is the equivalent run time C# code to create an Image (or set the Image property of an existing control) with myImage.png?


I am currently trying:


Code Snippet


BitmapImage bi = new BitmapImage

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"
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