如何将图像从数据库下载到文件夹并重命名. [英] how to download image from Database into a folder and rename it.

查看:83
本文介绍了如何将图像从数据库下载到文件夹并重命名.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;


namespace MOSS
{
    public partial class StoreImageInDB : System.Web.UI.Page
    {

        protected System.Web.UI.HtmlControls.HtmlInputFile Upload;
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void Page_Init(object sender, EventArgs e)
        {

            try
            {
                if (Request.QueryString["id"] == null)
                {
                    string id = "B0001";
                    Response.Clear();
                    Response.ContentType = "image/jpeg";
                    System.Drawing.Image image = RetrieveImage(id);
                    Bitmap bmPhoto = new Bitmap(image);
                    bmPhoto.SetResolution(72, 72);
                    bmPhoto.Save("lkfjlk.jpeg",System.Drawing.Imaging.ImageFormat.Jpeg);
                    bmPhoto.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);

                    //System.IO.File.Copy(
                    bmPhoto.Dispose();
                }
            }
            catch (Exception ee)
            {

            }

        }

        private System.Drawing.Image RetrieveImage(string id)
        {
            System.Drawing.Image image = null;
            //command.CommandText = "SELECT Photo FROM Photos  WHERE PhotoId = @PhotoId";
            //command.Parameters.AddWithValue("@PhotoId", photoId);
            byte[] imageData = DAlAutoComplete.GetImgDB(id);//(byte[])command.ExecuteScalar();
            MemoryStream memStream = new MemoryStream(imageData);
            image = System.Drawing.Image.FromStream(memStream);
            return image;
        }

    

        protected void OnUpload(object sender, EventArgs e)
        {
          
            if (FileUpload1.HasFile)
            {
                using (BinaryReader reader = new BinaryReader(FileUpload1.PostedFile.InputStream))
                {
                    byte[] image = reader.ReadBytes(FileUpload1.PostedFile.ContentLength);
                    int i = DAlAutoComplete.ImageInsetDB(image);
                }

            }





        }
    }
}



我正在将二进制数据转换为位图图像,但需要保存到文件夹中并重命名图像.



I am converting binary data into bitmap image but I need to save into a folder and rename the image.

推荐答案

请检查以下链接: ^ ]
Please check the following link:Link[^]


这篇关于如何将图像从数据库下载到文件夹并重命名.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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