亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

asp.net圖片上傳的方法教程

發布時間:2021-10-08 14:59:23 來源:億速云 閱讀:266 作者:iii 欄目:開發技術

本篇內容主要講解“asp.net圖片上傳的方法教程”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“asp.net圖片上傳的方法教程”吧!

第一、圖片上傳,代碼如下:
xxx.aspx

復制代碼 代碼如下:

 <td class="style1">
                <asp:FileUpload ID="FileUpload1" runat="server"  />
                <asp:Button ID="Button1" runat="server" Text="上傳一般圖片" onclick="Button1_Click" />
            </td>
            <td class="style3">
                <asp:Image ID="Image1" runat="server" Height="200px" Width="200px" />
            </td>

xxx.aspx.cs

復制代碼 代碼如下:

 protected void Button1_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < Request.Files.Count; i++)
            {
                HttpPostedFile file = Request.Files[i];
                if (file.ContentLength > 0)
                {
                    if (file.ContentType.Contains("image/"))
                    {
                        using (System.Drawing.Image img = System.Drawing.Image.FromStream(file.InputStream))
                        {
                            string FileName = System.IO.Path.GetFileName(file.FileName);
                            string[] SplitFileName = FileName.Split('.');
                            string AtterFileName = DateTime.Now.ToString("yyyMMddHHmmss")+"." + SplitFileName[1];
                            img.Save(Server.MapPath("/upload/" + AtterFileName));

                            this.Image1.ImageUrl = "upload/" + AtterFileName;
                        }
                    }
                    else
                    {
                        Response.Write("<script>alert('該文件不是圖片格式!');</script>");
                    }
                }
                else
                {
                    Response.Write("<script>alert('請選擇要上傳的圖片');</script>");
                }

            }
        }

第二、添加文字水印的圖片上傳,代碼如下:
xxx.aspx

復制代碼 代碼如下:

 <td class="style1">
                <asp:FileUpload ID="FileUpload2" runat="server" />
                <asp:Button ID="Button2" runat="server" Text="上傳文字圖片" onclick="Button2_Click" />
            </td>
            <td>
                <asp:Image ID="Image2" runat="server" Height="200px" Width="200px" />
            </td>

xxx.aspx.cs

復制代碼 代碼如下:

 protected void Button2_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < Request.Files.Count; i++)
            {
                HttpPostedFile file = Request.Files[i];
                if (file.ContentLength > 0)
                {
                    if (file.ContentType.Contains("image/"))
                    {
                        using (System.Drawing.Image img = System.Drawing.Image.FromStream(file.InputStream))
                        {
                            using (Graphics g = Graphics.FromImage(img))
                            {
                                g.DrawString("我的圖片", new Font("宋體", 14), Brushes.Red, 0, 0);
                            }
                            string FileName = System.IO.Path.GetFileName(file.FileName);
                            string[] SplitFileName = FileName.Split('.');
                            string AtterFileName = DateTime.Now.ToString("yyyMMddHHmmss") + "." + SplitFileName[1];
                            img.Save(Server.MapPath("/upload/" + AtterFileName));
                            this.Image2.ImageUrl = "upload/" + AtterFileName;
                        }
                    }
                    else
                    {
                        Response.Write("<script>alert('該文件不是圖片格式!');</script>");
                    }
                }
                else
                {
                    Response.Write("<script>alert('請選擇要上傳的圖片');</script>");
                }

            }
        }

第三、添加圖片水印的圖片上傳,代碼如下:
xxx.aspx

復制代碼 代碼如下:

 <td class="style1">
                <asp:FileUpload ID="FileUpload3" runat="server" />
                <asp:Button ID="Button3" runat="server" Text="上傳水印圖片" onclick="Button3_Click" />
            </td>
            <td>
                <asp:Image ID="Image3" runat="server" Height="200px" Width="200px" />
            </td>

xxx.aspx.cs

復制代碼 代碼如下:

protected void Button3_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < Request.Files.Count; i++)
            {
                HttpPostedFile file = Request.Files[i];
                if (file.ContentLength > 0)
                {
                    if (file.ContentType.Contains("image/"))
                    {
                        string fileName = file.FileName;
                        using (System.Drawing.Image img = System.Drawing.Image.FromStream(file.InputStream))
                        {
                            using (System.Drawing.Image imgWater = System.Drawing.Image.FromFile(Server.MapPath("/img/czlogo.jpg")))
                            {
                                using (Graphics g = Graphics.FromImage(img))
                                {
                                    g.DrawImage(imgWater, 0, 0);
                                }
                                string[] SplitFileName = fileName.Split('.');
                                string AtterFileName = DateTime.Now.ToString("yyyMMddHHmmss") + "." + SplitFileName[1];
                                img.Save(Server.MapPath("/upload/" + AtterFileName));
                                this.Image3.ImageUrl = "upload/" + AtterFileName;
                            }
                        }
                    }
                    else
                    {
                        Response.Write("<script>alert('該文件不是圖片格式!');</script>");
                    }
                }
                else
                {
                    Response.Write("<script>alert('請選擇要上傳的圖片');</script>");
                }
            }
        }


第四、上傳圖片濃縮圖,代碼如下:
xxx.aspx

復制代碼 代碼如下:

 <td class="style1">
                <asp:FileUpload ID="FileUpload4" runat="server" />
                <asp:Button ID="Button4" runat="server" Text="上傳濃縮圖片" onclick="Button4_Click" />
            </td>
            <td>
                <asp:Image ID="Image4" runat="server" Height="200px" Width="200px" />
            </td>

xxx.aspx.cs

復制代碼 代碼如下:


 protected void Button4_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < Request.Files.Count; i++)
            {
                HttpPostedFile file = Request.Files[i];
                if (file.ContentLength > 0)
                {
                    if (file.ContentType.Contains("image/"))
                    {
                        using (System.Drawing.Image img = System.Drawing.Image.FromStream(file.InputStream))
                        {
                            using (System.Drawing.Image imgThumb = new Bitmap(200, 100))
                            {
                                using (Graphics g = Graphics.FromImage(imgThumb))
                                {
                                    g.DrawImage(img, new Rectangle(0, 0, imgThumb.Width, imgThumb.Height), new Rectangle(0, 0, img.Width, img.Height), GraphicsUnit.Pixel);
                                }
                                string fileName = file.FileName;
                                string[] SplitFileName = fileName.Split('.');
                                string AtterFileName = DateTime.Now.ToString("yyyMMddHHmmss") + "." + SplitFileName[1];
                                img.Save(Server.MapPath("/upload/" + AtterFileName));
                                this.Image4.ImageUrl = "upload/" + AtterFileName;
                            }
                        }
                    }
                    else
                    {
                        Response.Write("<script>alert('該文件不是圖片格式!');</script>");
                    }
                }
                else
                {
                    Response.Write("<script>alert('請選擇要上傳的圖片');</script>");
                }
            }

        }

到此,相信大家對“asp.net圖片上傳的方法教程”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

嘉荫县| 镇赉县| 玛纳斯县| 淳化县| 临安市| 琼结县| 扶风县| 成安县| 化州市| 北宁市| 苍山县| 彰化市| 建德市| 洪湖市| 贞丰县| 正定县| 万安县| 淅川县| 洞口县| 平乐县| 老河口市| 拉孜县| 安康市| 聂荣县| 华池县| 绥德县| 凤山县| 洛宁县| 苏尼特左旗| 上饶市| 乌拉特后旗| 忻城县| 澎湖县| 文登市| 富宁县| 宁津县| 东乌珠穆沁旗| 保德县| 泾阳县| 普洱| 普宁市|