WPF display image stored in database not file

  • Thread starter Thread starter Lloyd Sheen
  • Start date Start date
L

Lloyd Sheen

Once again I ask for help. Another couple of days on a "simple" problem.
Is there a way to display an image without a file. IE get the image from
SQL Server and then display???

Thanks
Lloyd Sheen

PS. it is so dificult to find things on either Google or Bing since all
sites now list every tech so an attempt to restrict the question to WPF is
pretty much mute.
 
Lloyd said:
Once again I ask for help. Another couple of days on a "simple"
problem. Is there a way to display an image without a file. IE get
the image from SQL Server and then display???

For example,
http://www.xoc.net/works/tips/graphic.asp

(just one I quickly looked at for the principle of serving images without a
file).
PS. it is so dificult to find things on either Google or Bing since
all sites now list every tech so an attempt to restrict the question
to WPF is pretty much mute.

http://www.google.com/#hl=en&source=hp&q=asp.net+graphics+on+the+fly
http://www.google.com/#hl=en&q=asp.net+image+from+sql+server

HTH,

Andrew
 
Andrew Morton said:

Thanks but it is a bit much to have to run IIS. I doubt that anyone I give
my app to will be running that software. I just found the following for
anyone with the same problem:

First you create a new class derived from IValueConverter:

Public Class CustomImageConverter
Implements IValueConverter

'''<summary>
''' Converts System.Drawing.Bitmap to BitmapSource
'''</summary>

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
'No conversion to be done if value is null
If value Is Nothing Then
Return Nothing
End If

'Validate object being converted
If TypeOf value Is System.Drawing.Bitmap Then
'Use existing Interop functionality to perform conversion
Dim HBitmap As IntPtr = DirectCast(value,
System.Drawing.Bitmap).GetHbitmap()

Dim sizeOptions As System.Windows.Media.Imaging.BitmapSizeOptions =
System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions()


Return
System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(HBitmap,
IntPtr.Zero, Int32Rect.Empty, sizeOptions)
Else
'We don't want the conversion to fail if it's not valid
Return Nothing
End If
End Function

Public Function ConvertBack(ByVal value As Object, ByVal targetType As
System.Type, ByVal parameter As Object, ByVal culture As
System.Globalization.CultureInfo) As Object Implements
System.Windows.Data.IValueConverter.ConvertBack
Throw New NotImplementedException()
End Function
End Class


This gets called using the following XAML for the Image tag:

<Image Source="{Binding Path=Photo, Converter={StaticResource ImgConv}}"
Height="24" Width="24" ></Image>

Thanks for the help
Lloyd Sheen
 
Lloyd said:
Thanks but it is a bit much to have to run IIS. I doubt that anyone
I give my app to will be running that software. I just found the
following for anyone with the same problem:

Well, I think it's entirely reasonable for me to expect IIS to be running if
I get confused about which newsgroup I'm reading. Oops!

Glad you found an answer despite my confusion,

Andrew
 
Back
Top