C# 显示图片框中的图像?
我有一个项目与C。我添加图片框控件显示图像来自数据库 我有一个DbComand,它从客户端执行select*;和一个数据读取器来读取结果:C# 显示图片框中的图像?,c#,sql-server,picturebox,C#,Sql Server,Picturebox,我有一个项目与C。我添加图片框控件显示图像来自数据库 我有一个DbComand,它从客户端执行select*;和一个数据读取器来读取结果: byte[] buffer = (byte[])dr[24]; if (buffer != null) { groupBox1.Visible = true; MemoryStream ms = new MemoryStream(buffer); pictureBox1.Image = Image.FromStream(ms
byte[] buffer = (byte[])dr[24];
if (buffer != null)
{
groupBox1.Visible = true;
MemoryStream ms = new MemoryStream(buffer);
pictureBox1.Image = Image.FromStream(ms);
}
如何使用图片框中显示的图像打开Windows Photo Viewer…您可以使用以下代码打开它:
Process.Start(@"C:\Picture.jpg");
如果你在论坛应用程序中工作,你可以使用工具箱添加一个picturebox,如果这样做了,请转到picturebox的属性,然后按属性中名称图像旁边的三个点。按local resource,您就在自己的文档中了。希望这对您有所帮助您可以将图像从Picturebox保存到一个临时文件,并通过运行PhotoViewer dll来显示。这可以通过rundll32助手使用类来完成。您的代码如下所示:
// get a tempfilename and store the image
var tempFileName = Path.GetTempFileName();
pictureBox1.Image.Save(tempFileName, ImageFormat.Png);
string path = Environment.GetFolderPath(
Environment.SpecialFolder.ProgramFiles);
// create our startup process and argument
var psi = new ProcessStartInfo(
"rundll32.exe",
String.Format(
"\"{0}{1}\", ImageView_Fullscreen {2}",
Environment.Is64BitOperatingSystem?
path.Replace(" (x86)",""):
path
,
@"\Windows Photo Viewer\PhotoViewer.dll",
tempFileName)
);
psi.UseShellExecute = false;
var viewer = Process.Start(psi);
// cleanup when done...
viewer.EnableRaisingEvents = true;
viewer.Exited += (o, args) =>
{
File.Delete(tempFileName);
};
查看如何从命令行启动Photoviewer。我想您可以在这里找到答案:很好,但我没有图像的路径。图像来自数据库。但我没有图像的路径。图像来自数据库..检查此链接它来自数据库选择*来自客户端;字节[]缓冲区=字节[]dr[24];如果缓冲区!=null{groupBox1.Visible=true;MemoryStream ms=new MemoryStream Buffer;pictureBox1.Image=Image.FromStreamms;}