显示图片框中的图像
本文关键字:图像 显示图 | 更新日期: 2023-09-27 17:58:48
我有一个C#项目。我添加图片框控件来显示来自数据库的图像。
我有一个DbComand,它执行"select * from Client ";
和DataReader
来读取结果:
byte[] buffer = (byte[])dr[24];
if (buffer != null)
{
groupBox1.Visible = true;
MemoryStream ms = new MemoryStream(buffer);
pictureBox1.Image = Image.FromStream(ms);
}
如何使用图片框中显示的图像打开Windows照片查看器。。。
您可以用以下代码打开它:
Process.Start(@"C:'Picture.jpg");
您可以将图片框中的图像保存到一个临时文件中,并通过运行PhotoViewer dll来显示。这可以通过使用Process类使用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,请参阅此答案。
如果你在论坛应用程序中工作,你可以用工具箱添加一个picturebox,如果你这样做了,请转到picturebox的属性,然后按属性中名称图像旁边的三个点。按本地资源,您就在自己的文档中。希望这能帮助你