WPF中的图像问题。 [英] Problem with image in WPF.

查看:70
本文介绍了WPF中的图像问题。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



我有一个WPF应用程序,我想看一个图像到图像框。

我用这个代码来赢取表格来执行此操作

Hi guys

I have a WPF application and I want to see an image to image box.
I used this code to win forms to do this

 Public Sub picshow()
        Using cmd As New SqlCommand("Select * From Staff where StaffID='" & txtAA.Text & "'", GlobalClass.con)
            Using dr As SqlDataReader = cmd.ExecuteReader()
                Using dt As New DataTable
                    dt.Load(dr)
                    Try
                        Dim row As DataRow = dt.Rows(0)
                        Using ms As New MemoryStream(CType(row("Photo"), Byte()))
                            Dim img As Image = Image.FromStream(ms)
                            PictBox.Image = img '<-- Here is the problem "with Image"
                        End Using
                    Catch ex As Exception
                        GoTo err
                    End Try
                    Exit Sub
                End Using
            End Using
        End Using
        GlobalClass.con.Close()
err:
    End Sub





但它在WPF中不起作用

有人可以帮忙吗?



提前致谢



but it doesn't work in WPF
Can anyone help?

Thanks in advance

推荐答案

在WPF中使用图片



< Image Height = 305Horizo​​ntalAlignment =LeftMargin =14,53,0,0

Name =ImageControlStretch =FillVerticalAlignment =TopWidth =390/>



请看看进入下面的链接,知道如何从字节数组中获取BitmapImage



http://stackoverflow.com/questions/9564174/convert-byte-array-to-image-in-wpf [ ^ ]



设置位图图像如下



ImageViewer1.Source = bitmap;





如果你有兴趣在WPF中使用WinForm控件,请看看这个



http://msdn.microsoft.com/en-us/library/ms751761.aspx [ ^ ]



其他参考文献 - http://www.c-sharpcorner.com/uploadfile/mahesh/image-viewer-in-wpf/ [ ^ ]
Using Image in WPF

<Image Height="305" HorizontalAlignment="Left" Margin="14,53,0,0"
Name="ImageControl" Stretch="Fill" VerticalAlignment="Top" Width="390" />

Please have a look into the below link to know how to get BitmapImage from byte array

http://stackoverflow.com/questions/9564174/convert-byte-array-to-image-in-wpf[^]

Set the bitmap image as below

ImageViewer1.Source = bitmap;


Have a look into this if you are interested in using WinForm controls in WPF

http://msdn.microsoft.com/en-us/library/ms751761.aspx[^]

Other References - http://www.c-sharpcorner.com/uploadfile/mahesh/image-viewer-in-wpf/[^]


这篇关于WPF中的图像问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆