照片地址存储在数据库中。 [英] Photo addresses are stored in a database.

查看:65
本文介绍了照片地址存储在数据库中。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi



我用这种方法从IP Camera拍照:



hi

I take a picture from IP Camera with this method :

public byte[] snapshot( string ip, string user, string pass)
        {
            byte[] imageByte;
             
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://" + ip + "/ipcam/jpeg.cgi");
                req.Credentials = new NetworkCredential(user, pass);
                HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
                Stream stm = resp.GetResponseStream();
                img = new Bitmap(stm);
                stm.Close();
                System.IO.MemoryStream MemoryStream = new System.IO.MemoryStream();
                img.Save(MemoryStream, System.Drawing.Imaging.ImageFormat.Jpeg);
 
                imageByte = MemoryStream.ToArray();
                return imageByte;
            
        }





现在,我希望将此图片保存在服务器的文件夹中并保存图片中的图片地址数据库。



我该怎么做???



now , i want save this picture in a folder in server And save picture's address in my database .

How do I do it ???

推荐答案

这个主题 [ ^ ]回答你的确切问题。



本文 [ ^ ]也可以帮到你。
This thread[^] answers the exact question you have.

This article[^] should help you as well.


Hello Meisam,



BitMap类有一个Save(String)方法。您可以使用此方法将文件保存在指定的文件夹中。以下代码段显示了如何修改您的函数。

Hello Meisam,

The BitMap class has a Save(String) method. You can use this method to save the file in a designated folder. Following code snippet shows how your function can be modified to to this.
public byte[] snapshot( string ip, string user, string pass, string saveToFile) {
    byte[] imageByte;

    HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://" + ip + "/ipcam/jpeg.cgi");
    req.Credentials = new NetworkCredential(user, pass);
    HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
    Stream stm = resp.GetResponseStream();
    img = new Bitmap(stm);
    stm.Close();
    img.Save(saveToFile);    // Save file on disk
    System.IO.MemoryStream MemoryStream = new System.IO.MemoryStream();
    img.Save(MemoryStream, System.Drawing.Imaging.ImageFormat.Jpeg);

    imageByte = MemoryStream.ToArray();
    return imageByte;
}



您可以生成如下所示的唯一文件名。


You can generate unique file names as shown below.

long ticks = DateTime.UtcNow.Ticks;
DateTime today = DateTime.Today;
string sFile = string.Format("{0:yyyyMMdd}-{1:00000}.png", today, ticks);



问候,


Regards,


这篇关于照片地址存储在数据库中。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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