用C#打开照片帮助我 [英] Open photos in C # help me
本文介绍了用C#打开照片帮助我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
在程序中,DataGridView内部是从数据库加载的照片字段之一
现在我想要在照片上显示照片应用程序(如veiwer)的照片
有没有人有解决方案?
我尝试了什么:
[删除重复文本]
推荐答案
Photo应用程序(如Viewer)需要一张照片的路径阅读文件并进行预览。由于您的照片来自数据库,因此Viewer应用程序(或任何其他照片应用程序)不太可能访问它。
一个解决方案是使用基于Guid
的名称创建一个临时文件。这将允许您存储文件一段时间,然后将该临时文件传递给照片查看器。这是解决问题的唯一方法 - 因为我认为照片查看器不会访问数据库流。 :笑:
您需要将数据库中的所有内容(二进制内容)写入具有适当mime类型的文件,然后将其存储为临时文件在本地目录中为查看者提供对此文件的访问权限。 在c#中从流对象创建临时文件 - DeveloperQ - 开发者问题网 - 海量问题解决方案 [ ^ ],您可以稍后在不再需要时将其删除。 :-)
打开照片查看器只是一个简单的任务,你可以使用进程
从System.Diagnostics
并启动一个新进程来显示该文件。
The Photo app (like Viewer) requires a path to the photo to read the file and preview it. Since your photo comes from a database, Viewer app (or any other photo app) is unlikely to get access to it.
One solution to this will be to create a temporary file with aGuid
based name. This will allow you to store the file for a while and then pass that temporary file to the Photo viewer. This is the only way you can solve it — as I believe photo viewers won't access database streams. :laugh:
You would need to write all the content from the database (binary content) to a file with the proper mime types and then store that as a temporary file in your local directories to provided the viewer with the access to this file. Create a temporary file from stream object in c# - Stack Overflow[^], you can later on delete it when no longer needed. :-)
Opening the photo viewer will be just simple task, you can use theProcess
type fromSystem.Diagnostics
and start a new process to show the file.
Process.Start("viewer.exe", "parameter-temp-file-path");
对于不再需要时部分,您可以检查进程何时终止,然后删除该文件。
有关Process类的更多信息,请阅读:进程类(System.Diagnostics) [ ^ ]
如何查找
parameter-temp-file-path
这篇关于用C#打开照片帮助我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文