Display Images from Database in Windows Phone 7 (WP7) using WCF service

Posted by: Mahesh Sabnis , on 10/4/2010, in Category Windows Phone
Views: 67567
Abstract: The Windows Phone 7 (WP7) Developer Toolkit RTW provides an excellent mechanism to built Rich UX applications on mobile devices (phone). One of the interesting aspect of WP7 programming is that it provides the Silverlight platform for application development.
The Windows Phone 7 (WP7) Developer Toolkit RTW provides an excellent mechanism to built Rich UX applications on mobile devices (phone). One of the interesting aspect of WP7 programming is that it provides the Silverlight platform for application development. I am a great fan of Silverlight and WPF development and I am going to adopt a similar programming mechanism with WP7, for consuming WCF service and perform the data communication.
Update: VB.NET developers take note that there is a Visual Basic CTP for Windows Phone Developer Tools now available. Read the annoucement here.
In this article, I have designed a WCF service which makes a call to a Database and reads data from the table. This table contains Images stored in binary form and through the WCF service, we make the byte array data available to the WP7 application. 
I am using SQL Server 2008 and the Table schema is as below: The name of the table is ‘ImageEmployee’:
image_2
Creating a WCF Service
 
Step 1: Open VS2010 and create a blank solution, name it as ‘WP7_FIrstApp’. In the solution add a WCF service application, name it as ‘WCF_DataServiceApp’.
Step 2: Open IService1.cs and define the following Interface and DataContract:
C#
[ServiceContract]
public interface IService
{
    [OperationContract]
    ImageEmployee GetEmpByEmpNo(int EmpNo);
}
[DataContract]
public class ImageEmployee
{
    [DataMember]
    public int EmpNo { get; set; }
    [DataMember]
    public string EmpName { get; set; }
    [DataMember]
    public decimal Salary { get; set; }
    [DataMember]
    public int DeptNo { get; set; }
    [DataMember]
    public byte[] EmpImage { get; set; }
}
 
VB.NET (Converted Code)
<ServiceContract>
Public Interface IService
            <OperationContract>
            Function GetEmpByEmpNo(ByVal EmpNo As Integer) As ImageEmployee
End Interface
<DataContract>
Public Class ImageEmployee
            <DataMember>
            Public Property EmpNo() As Integer
            <DataMember>
            Public Property EmpName() As String
            <DataMember>
            Public Property Salary() As Decimal
            <DataMember>
            Public Property DeptNo() As Integer
            <DataMember>
            Public Property EmpImage() As Byte()
End Class
 
Step 3: Open Service1.Svc and implement the above service contract, ‘IService’ interface as shown below:
C#
using System;
using System.Collections.Generic;
 
using System.Data.SqlClient;
 
namespace WCF_DataServiceApp
{
    public class Service : IService
    {
        public ImageEmployee GetEmpByEmpNo(int EmpNo)
        {
            var Conn = new SqlConnection("Data Source=.;Initial Catalog=Company;Integrated Security=SSPI");
            Conn.Open();
            var Cmd = new SqlCommand();
            Cmd.Connection = Conn;
            Cmd.CommandText = "Select * from ImageEmployee where EmpNo=@EmpNo";
            Cmd.Parameters.AddWithValue("@EmpNo", EmpNo);
 
            var Reader = Cmd.ExecuteReader();
 
            ImageEmployee objImgEmp = new ImageEmployee();
 
            while (Reader.Read())
            {
                objImgEmp.EmpNo = Convert.ToInt32(Reader["EmpNo"]);
                objImgEmp.EmpName = Reader["EmpName"].ToString();
                objImgEmp.Salary = Convert.ToInt32(Reader["Salary"]);
                objImgEmp.DeptNo = Convert.ToInt32(Reader["DeptNo"]);
                objImgEmp.EmpImage = (byte[])Reader["EmpImage"];
            }
            Reader.Close();
            Conn.Close();
            return objImgEmp;
        }
    }
}
 
VB.NET (Converted Code)
Imports System
Imports System.Collections.Generic
 
Imports System.Data.SqlClient
 
Namespace WCF_DataServiceApp
      Public Class Service
            Implements IService
            Public Function GetEmpByEmpNo(ByVal EmpNo As Integer) As ImageEmployee
                  Dim Conn = New SqlConnection("Data Source=.;Initial Catalog=Company;Integrated Security=SSPI")
                  Conn.Open()
                  Dim Cmd = New SqlCommand()
                  Cmd.Connection = Conn
                  Cmd.CommandText = "Select * from ImageEmployee where EmpNo=@EmpNo"
                  Cmd.Parameters.AddWithValue("@EmpNo", EmpNo)
 
                  Dim Reader = Cmd.ExecuteReader()
 
                  Dim objImgEmp As New ImageEmployee()
 
                  Do While Reader.Read()
                        objImgEmp.EmpNo = Convert.ToInt32(Reader("EmpNo"))
                        objImgEmp.EmpName = Reader("EmpName").ToString()
                        objImgEmp.Salary = Convert.ToInt32(Reader("Salary"))
                        objImgEmp.DeptNo = Convert.ToInt32(Reader("DeptNo"))
                        objImgEmp.EmpImage =CType(Reader("EmpImage"), Byte())
                  Loop
                  Reader.Close()
                  Conn.Close()
                  Return objImgEmp
            End Function
      End Class
End Namespace
 
The above method makes a call to the database table ‘ImageEmployee’ and by comparing EmpNo, the record for the employee is returned.
Step 4: Build the service and publish it on IIS.
 
Creating Windows Phone (WP7) application
 
In this task, we will create a WP7 client application. I am using VS2010 and WP7 RTW development environment.
Step 1: In the solution created above, add a new WP7 application as shown below in the  screenshot:
image_1 
The template for ‘Silverlight for Windows Phone’ will appear after downloading WP7 Developer Toolkit RTW and installing it on your machines
Step 2: Since WP7 provides Silverlight development platform, you can design the UI using XAML. By default, the MainPage.Xaml provides Grid with name ‘LayoutRoot’ which contains StackPanel of name ‘TitlePanel’. The XAML elements in the StackPanel is as shown below:
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
    <TextBlock x:Name="ApplicationTitle" Text="Received Form WCF" Style="{StaticResource PhoneTextNormalStyle}"/>
    <TextBlock x:Name="PageTitle" Text="Employee Information" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}" FontSize="48" FontWeight="ExtraBold" />
</StackPanel>
 
Step 3: The Grid ‘LayoutRoot’ also contains one more Grid as child element of name ‘ContentPanle’. Put the following XAML elements in this grid.
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
 
    <Grid.RowDefinitions>
        <RowDefinition Height="71*" />
        <RowDefinition Height="67*" />
        <RowDefinition Height="64*" />
        <RowDefinition Height="70*" />
        <RowDefinition Height="170*" />
        <RowDefinition Height="197*" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="221*" />
        <ColumnDefinition Width="235*" />
    </Grid.ColumnDefinitions>
    <TextBlock Height="30" HorizontalAlignment="Left" Margin="29,23,0,0" Name="textBlock1" Text="EmpNo" VerticalAlignment="Top" Width="151" />
 
    <TextBox  Grid.Column="1" Grid.RowSpan="2" Height="72" HorizontalAlignment="Left" Margin="5,6,0,0" Name="txteno"
                      Text="{Binding EmpNo}" VerticalAlignment="Top" Width="229" />
    <TextBox Grid.RowSpan="3" Height="72" HorizontalAlignment="Left" Margin="6,68,0,0" Name="txtename"
                     Text="{Binding EmpName}" VerticalAlignment="Top" Width="229" Grid.Column="1" />
    <TextBox Grid.RowSpan="3" Height="72" HorizontalAlignment="Left" Margin="3,65,0,0" Name="txtsal"
                     Text="{Binding Salary}" VerticalAlignment="Top" Width="229" Grid.Column="1" Grid.Row="1" />
    <TextBox Grid.RowSpan="2" Height="72" HorizontalAlignment="Left" Margin="6,0,0,0" Name="txtdno"
                     Text="{Binding DeptNo}" VerticalAlignment="Top" Width="229" Grid.Column="1" Grid.Row="3" />
 
    <TextBlock Height="30" HorizontalAlignment="Left" Margin="29,20,0,0" Name="textBlock2" Text="EmpName" VerticalAlignment="Top" Width="151" Grid.Row="1" />
    <TextBlock Height="30" HorizontalAlignment="Left" Margin="29,18,0,0" Name="textBlock3" Text="Salary" VerticalAlignment="Top" Width="151" Grid.Row="2" />
    <TextBlock Height="30" HorizontalAlignment="Left" Margin="29,21,0,0" Name="textBlock4" Text="DeptNo" VerticalAlignment="Top" Width="151" Grid.Row="3" />
    <TextBlock Height="30" HorizontalAlignment="Left" Margin="29,37,0,0" Name="textBlock5" Text="Image" VerticalAlignment="Top" Width="151" Grid.Row="4" />
    <Image Grid.Column="1" Grid.Row="4" Height="136" HorizontalAlignment="Left"
                   Margin="16,16,0,0" Name="imgEmp" Stretch="Fill"
                   VerticalAlignment="Top" Width="200"
                    Source="{Binding EmpImage}"/>
    <Button Content="Emp Details" Grid.Column="1" Grid.Row="5" Height="72" HorizontalAlignment="Left" Margin="16,29,0,0" Name="btnGetEmpDetails" VerticalAlignment="Top" Width="160" FontSize="20" Click="btnGetEmpDetails_Click" />
</Grid>
</Grid>
 
All textboxes are bound to properties defined in the DataContract class of the WCF service.
The UI design of the application we are building is as shown below:
image_2
New Picture1
   
Step 4: Now we will add the WCF service reference in the WP7 application. After installing WP7, you will get the utility ‘SlSvcUtil.exe’ in the following path:
C:\Program Files (x86)\Microsoft SDKs\Windows Phone\v7.0\Tools
This tool helps to generate the WCF proxy class and configuration file as shown below:
image_3
Copy the generated files from the above folder and paste it in the WP7 project.
Step 5: Since the WCF service returns ‘EmpImage’ as ‘Byte[]’ array, it needs to be converted to an image. To do this, I have added a converter class in the WP7 project as shown below.
C#
using System;
using System.Windows.Data;
using System.IO;
using System.Windows.Media.Imaging;
 
namespace WP7_ClientApp
{
    public class ImageConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            MemoryStream memStream = new MemoryStream((byte[])value);
            memStream.Seek(0, SeekOrigin.Begin);
            BitmapImage empImage = new BitmapImage();
            empImage.SetSource(memStream);
            return empImage;
        }
 
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
 
VB.NET (Converted Code)
Imports System
Imports System.Windows.Data
Imports System.IO
Imports System.Windows.Media.Imaging
 
Namespace WP7_ClientApp
      Public Class ImageConverter
            Implements IValueConverter
            Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert
                  Dim memStream As New MemoryStream(CType(value, Byte()))
                  memStream.Seek(0, SeekOrigin.Begin)
                  Dim empImage As New BitmapImage()
                  empImage.SetSource(memStream)
                  Return empImage
            End Function
 
            Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
                  Throw New NotImplementedException()
            End Function
      End Class
End Namespace
 
Step 6: This converter class needs to be used in the MainPage.xaml. To do this open ‘MainPage.xaml’ and declare an object on the converter class in the resources of the Grid ‘ContentPanel’ as shown below:
<Grid.Resources>
    <src:ImageConverter x:Key="imgConverter"></src:ImageConverter>
</Grid.Resources>
 
Step 7: Now bind the above object in the image element in MainPage.xaml as shown below:
<Image Grid.Column="1" Grid.Row="4" Height="136" HorizontalAlignment="Left"
                   Margin="16,16,0,0" Name="imgEmp" Stretch="Fill"
                   VerticalAlignment="Top" Width="200"
                    Source="{Binding EmpImage,Converter={StaticResource imgConverter}}"/>
 
Step 8: Open MainPage.xaml.cs and write the following code:
At the class level declare the WCF proxy reference as shown below:
C#
ServiceClient Proxy;
 
VB.NET (Converted Code)
Dim Proxy As ServiceClient
 
Declare the WCF proxy object on the loaded event as below:
C#
public MainPage()
{
      InitializeComponent();
      this.Loaded += new RoutedEventHandler(MainPage_Loaded);
}
 
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
    Proxy = new ServiceClient();
}
 
VB.NET (Converted Code)
Public Sub New()
      InitializeComponent()
      AddHandler Loaded, AddressOf MainPage_Loaded
End Sub
 
Private Sub MainPage_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
      Proxy = New ServiceClient()
End Sub
 
On the ‘Emp Details’ button click event, write the following code:
C#
private void btnGetEmpDetails_Click(object sender, RoutedEventArgs e)
        {
            Proxy.GetEmpByEmpNoCompleted += new EventHandler<GetEmpByEmpNoCompletedEventArgs>(Proxy_GetEmpByEmpNoCompleted);
            Proxy.GetEmpByEmpNoAsync(Convert.ToInt32(txteno.Text)); 
        }
 
        void Proxy_GetEmpByEmpNoCompleted(object sender, GetEmpByEmpNoCompletedEventArgs e)
        {
            if (e.Result != null)
            {
                ImageEmployee objImgEmp = e.Result;
 
                ContentPanel.DataContext = objImgEmp;           
            }
        }
 
VB.NET (Converted Code)
Private Sub btnGetEmpDetails_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
                  AddHandler Proxy.GetEmpByEmpNoCompleted, AddressOf Proxy_GetEmpByEmpNoCompleted
                  Proxy.GetEmpByEmpNoAsync(Convert.ToInt32(txteno.Text))
End Sub
 
Private Sub Proxy_GetEmpByEmpNoCompleted(ByVal sender As Object, ByVal e As GetEmpByEmpNoCompletedEventArgs)
      If e.Result IsNot Nothing Then
            Dim objImgEmp As ImageEmployee = e.Result
            ContentPanel.DataContext = objImgEmp
      End If
End Sub
 
The above code makes an async call to the WCF service and get the Employee object. This object using ‘DataContext’ is bound with the ‘ContentPanel’ grid.
Step 9: Run the application, you will get the WP7 Emulator with UI as shown below:
When you click on the ‘EmpNo’ textbox, the keypad will be displayed as shown below:
image_4
image_5
 
Click on ‘&123’ button you will get the numeric keypad as shown above in column 2.
Type 101 in the textbox and click on any other part of the Emulator; the keypad will disappear. Now click on ‘Emp Details’ button and the following results will be displayed.
image_1
Give me a +1 if you think it was a good article. Thanks!
Recommended Articles


Page copy protected against web site content infringement by Copyscape


User Feedback
Comment posted by Carpet Cleaning Denver on Tuesday, October 5, 2010 1:51 AM
I am very much pleased with the contents you have mentioned.I wanted to thank you for this great article!!

Thanks
Comment posted by Bill on Friday, November 5, 2010 1:13 PM
Did you forget a step? I am getting an error in Step 6 of the WP7 application stating that "src is an undeclared prefix".
Comment posted by Bill on Friday, November 5, 2010 1:17 PM
Also, I am getting the following error: "The type 'src:ImageConverter' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built."<br/><br/>ImageConverter is in the same project/namespace as MainPage, so I am a little confused as to why I would need an assembly reference.
Comment posted by Bill on Friday, November 5, 2010 5:51 PM
UPDATE: I added xmlns:src="clr-namespace:Wp7Client", which took care of the source error. I am now getting "Invalid type" for imgConverter in  <Image Grid.Column="1" Grid.Row="4" Height="136" HorizontalAlignment="Left" Margin="16,16,0,0" Name="imgEmp" Stretch="Fill" VerticalAlignment="Top" Width="200" Source="{Binding EmpImage, Converter={StaticResource imgConverter}}"/>
Comment posted by Bill on Monday, November 8, 2010 11:50 AM
UPDATE: I added xmlns:src="clr-namespace:Wp7Client", which took care of the source error. I am now getting "Invalid type" for imgConverter in  <Image Grid.Column="1" Grid.Row="4" Height="136" HorizontalAlignment="Left" Margin="16,16,0,0" Name="imgEmp" Stretch="Fill" VerticalAlignment="Top" Width="200" Source="{Binding EmpImage, Converter={StaticResource imgConverter}}"/>
Comment posted by Mahesh Sabnis on Tuesday, November 23, 2010 2:06 AM
Hi,
  Thanks a lot Carpet Cleaning Denver

Mahesh Sabnis
Comment posted by Mahesh Sabnis on Tuesday, November 23, 2010 2:08 AM
Hi,
  Have you downloaded the complete code for the article, I have put the class in the uploaded code.

Thanks
MAhesh Sabnis
Comment posted by Enrique Serra Zamora on Sunday, December 26, 2010 4:12 AM
Hi
I'm coding your VB version. First of all, the line
Implements IService
        Public Function GetEmpByEmpNo(ByVal EmpNo As Integer) As ImageEmployee
is
Implements IService
        Public Function GetEmpByEmpNo(ByVal EmpNo As Integer) As ImageEmployee Implements IService.GetEmpByEmpNo

When I right click on Service.svc and click on View on Explorer i'm getting an error

"Server error on Application /"

[ServiceActivationException:Service '/Service1.svc' can't be activated due to an exceptión during the compilation.
The exception message was : WCF_DataServiceApp.Service1 type can't be found supplied as an attribute value of Service on  directive ServiceHost, or supplied on configuration item system.serviceModel/serviceHostingEnvironment/serviceActivations..]

I tried to translate it from spanish to english

Please help me

THANKS
Comment posted by Enrique Serra Zamora on Sunday, December 26, 2010 4:20 AM
Hi
I'm coding your VB version. First of all, the line
Implements IService
        Public Function GetEmpByEmpNo(ByVal EmpNo As Integer) As ImageEmployee
is
Implements IService
        Public Function GetEmpByEmpNo(ByVal EmpNo As Integer) As ImageEmployee Implements IService.GetEmpByEmpNo

When I right click on Service.svc and click on View on Explorer i'm getting an error

"Server error on Application /"

[ServiceActivationException:Service '/Service1.svc' can't be activated due to an exceptión during the compilation.
The exception message was : WCF_DataServiceApp.Service1 type can't be found supplied as an attribute value of Service on  directive ServiceHost, or supplied on configuration item system.serviceModel/serviceHostingEnvironment/serviceActivations..]

I tried to translate it from spanish to english

Please help me

THANKS
Comment posted by Enrique Serra Zamora on Sunday, December 26, 2010 3:00 PM
Solved in this post

http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/1f52439a-7ac1-4a56-a6cb-2b21dacc1269
Comment posted by Enrique Serra Zamora on Sunday, December 26, 2010 5:47 PM
Solved in this post

http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/1f52439a-7ac1-4a56-a6cb-2b21dacc1269
Comment posted by Mahesh Sabnis on Monday, December 27, 2010 1:52 AM
Hi Enrique Serra Zamora
All your problems regarding article are solved.
Regards
Mahesh Sabnis
Comment posted by Jacky on Wednesday, February 16, 2011 1:50 PM
I am getting the following error:
System.InvalidOperationException was unhandled
  Message=Could not find default endpoint element that references contract 'ServiceReference1.IService1' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
  StackTrace:
       at System.ServiceModel.DiagnosticUtility.ExceptionUtility.BuildMessage(Exception x)
       at System.ServiceModel.DiagnosticUtility.ExceptionUtility.LogException(Exception x)
       at System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(Exception e)
       at System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint serviceEndpoint, String configurationName)
       at System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName)
       at System.ServiceModel.ChannelFactory.InitializeEndpoint(String configurationName, EndpointAddress address)
       at System.ServiceModel.ChannelFactory`1..ctor(String endpointConfigurationName, EndpointAddress remoteAddress)
       at System.ServiceModel.ChannelFactory`1..ctor(String endpointConfigurationName)
       at System.ServiceModel.EndpointTrait`1.CreateSimplexFactory()
       at System.ServiceModel.EndpointTrait`1.CreateChannelFactory()
       at System.ServiceModel.ClientBase`1.CreateChannelFactoryRef(EndpointTrait`1 endpointTrait)
       at System.ServiceModel.ClientBase`1.InitializeChannelFactoryRef()
       at System.ServiceModel.ClientBase`1..ctor()
       at Cou.ServiceReference1.Service1Client..ctor()
       at Cou.MainPage.MainPage_Loaded(Object sender, RoutedEventArgs e)
       at System.Windows.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
       at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)
Comment posted by Dibin dev on Saturday, April 16, 2011 5:03 AM
i coding your c# version . i am getting an unspecified error when 'bitmap.SetSource(memmorystearm);'
If you have a solution for that please help me .
Comment posted by ramu paideti on Saturday, July 30, 2011 8:12 AM
Hi Mahesh,

Really this is very useful code for us.

For retrieving and display the image is we are using converter class.

Now my requirement is how to store the captured image/isolated storage image into the same database.

i.e how to insert a new record from windowsphone7.

Please send me the solution, really i required it as urgent one.

Thanks in advance.

Comment posted by richie12200 on Saturday, August 20, 2011 2:13 AM
Hi can you sent the complete code for me??
Comment posted by richie12200 on Saturday, August 20, 2011 2:15 AM
Hi can you sent the complete code for me??
Comment posted by richie12200 on Saturday, August 20, 2011 2:48 AM
Hi Mahesh ! i got this Error message
The server was unable to process the request due to an internal error.  For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.

and i use the SQL 2008 R2 Express for my database how can i handle this problem?
Comment posted by richie12200 on Saturday, August 20, 2011 2:58 AM
Hi Mahesh ! i got this Error message
The server was unable to process the request due to an internal error.  For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.

and i use the SQL 2008 R2 Express for my database how can i handle this problem?
Comment posted by Edo on Saturday, September 24, 2011 12:31 PM
How can i find the sample code for this example because i have try so many times and it doesn't work. Please help me
Comment posted by DonDi on Sunday, September 25, 2011 2:04 PM
Hellooo, can anyone send to me this sample because it doesn't work. My email is edon.bajrami7@gmail.com
Comment posted by DonDi on Monday, September 26, 2011 5:26 PM
Hi, i try this code and i have some problems with the Converter class part it doesn't work for me. I change this part and i use the following code:

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            byte[] buffer=value as byte[];
            Stream memStream = new MemoryStream(buffer);
            WriteableBitmap wbimg = PictureDecoder.DecodeJpeg(memStream);
            return wbimg;
        }
and it works for me. Bye
Comment posted by Stefano on Thursday, November 10, 2011 4:26 AM
Hi, i have your article very interesting, but i get an error if i try to display the image.
I get this exception:

   at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
   at MS.Internal.XcpImports.UIElement_Measure_WithDesiredSize(UIElement element, Size availableSize)
   at System.Windows.UIElement.Measure_WithDesiredSize(Size availableSize)
   at System.Windows.Controls.VirtualizingStackPanel.MeasureChild(UIElement child, Size layoutSlotSize)
   at System.Windows.Controls.VirtualizingStackPanel.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Double inWidth, Double inHeight, Double& outWidth, Double& outHeight)

What am i wrong ??
Could you help me ??
Thanks in advance
Comment posted by Misi Moisei on Wednesday, January 25, 2012 10:44 AM
Great article.
Could you put a link to the source code ?
Thank you.
Comment posted by Misi Moisei on Wednesday, January 25, 2012 10:44 AM
Great article.
Could you put a link to the source code ?
Thank you.
Comment posted by hueikar on Sunday, June 3, 2012 5:14 AM
Could you put a link to the source code? i can't find it..
Comment posted by hueikar on Tuesday, June 5, 2012 12:41 PM
I start facing error since step 6..any solution??
Comment posted by gopikrishna on Wednesday, June 6, 2012 1:02 AM
Could you put a link to the source code?
Comment posted by gopikrishna on Wednesday, June 6, 2012 1:10 AM
Hellooo, can anyone send to me this sample because it doesn't work. My email is gopikrishna412@gmail.com
Comment posted by hueikar on Wednesday, June 6, 2012 4:06 AM
Please send the example to me too..really need this sample coding..My email is hueikar1013@yahoo.com.Thank you..
Comment posted by Timothy on Wednesday, June 13, 2012 3:04 AM
This is the reference for the error i facing.
http://forums.create.msdn.com/forums/p/65575/401237.aspx
Well,It worked for me..
Comment posted by Paresh on Thursday, December 13, 2012 11:35 PM
Sir, how can we implement Asynchronous image loading in ListBox? You know i have just started with WP7 app development so. Yes having been involved in Android app development since more than 2 years so i know about Asynchronous  term. Looking forward for your help for implementing Asynchronous image loading in ListBox.
Comment posted by avin jalal on Thursday, April 4, 2013 9:53 PM
hello,
I am getting the same error in step 6 and i am using c# please help me
Comment posted by avin jalal on Thursday, April 4, 2013 10:11 PM
i read that comment about that error but i dont understand
and i dont have any idea about how to solve the error
i am beginner :(
please please help me
Comment posted by BalaKrishnan on Monday, May 13, 2013 9:04 AM
Hai i new to windows phone 7. so i need help.how to insert image in to data base in (wp7) using wcf service in vb.net
Comment posted by william hoffmann on Saturday, November 30, 2013 4:45 PM
please send the VB sln file .. i tires to get all the paramaters in a project file but failed on the   <src:ImageConverter x:Key="imgconverter" />  into the xaml page. thx in advance
Comment posted by carol on Sunday, December 8, 2013 5:38 AM
i tires to get all the paramaters in a project file but failed on the   <src:ImageConverter x:Key="imgconverter" />  into the xaml page. thx in advance
Comment posted by ranjit on Friday, January 17, 2014 5:16 AM
Hi Mahesh,
I appriciate for this good article, i was looking for this simce a week. Many Thanks!! Please keep up the good work!!

Can you please also help me to browse appropriate photo of the employee while create/add any record into database. Mainly how to save image into database while creating/ adding emplyee record.
Your help would be really appriciated.  Many thanks in advance!!

Post your comment
Name:  
E-mail: (Will not be displayed)
Comment:
Insert Cancel