中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

圖片加水印和生成縮略圖C#代碼

2018-07-20    來源:open-open

容器云強(qiáng)勢(shì)上線!快速搭建集群,上萬Linux鏡像隨意使用
一: 圖片加水印處理

         //獲得圖片的名稱
        string name = context.Request["name"];
        string filePath = context.Server.MapPath("Upload/" + name);
        //首先獲得要進(jìn)行水印處理的圖片
        if (!string.IsNullOrEmpty(name))
        {
            using (Image image = Bitmap.FromFile(filePath))
            {
                //準(zhǔn)備一個(gè)畫筆來在圖片上作畫
                using (Graphics g = Graphics.FromImage(image))
                {
                    //作畫
                    g.DrawString("str", new Font("微軟雅黑", 20), Brushes.Red, new PointF(1, 1));
                    image.Save(context.Response.OutputStream, ImageFormat.Jpeg);
                }
            }
        }

二:生成縮略圖

        

 HttpPostedFile hpFile= context.Request.Files[0];
        if (hpFile.ContentLength > 0)
        {
            string filePath = context.Server.MapPath("Upload/" + hpFile.FileName);
            //判斷文件是否為圖片文件
            if (hpFile.ContentType.IndexOf("image") > -1)
            {
                //從輸入流中獲得圖片數(shù)據(jù)
                using (Image img = Image.FromStream(hpFile.InputStream))
                {
                    //準(zhǔn)備一張畫板來存儲(chǔ)小圖
                    using (Bitmap thumbImg = new Bitmap(120, 80))
                    {
                        //利用畫筆將大圖繪制在小圖中
                        using (Graphics g = Graphics.FromImage(thumbImg))
                        {                     //用于指定最終畫的圖的大小
                            g.DrawImage(img, new Rectangle(0, 0, thumbImg.Width, thumbImg.Height),
                                new Rectangle(0, 0, img.Width, img.Height), GraphicsUnit.Pixel);
                            //用于指定畫大圖中的那一部分

                            //將小圖也保存在相應(yīng)的路徑中
                            thumbImg.Save(context.Server.MapPath("Upload/thumb_" + hpFile.FileName));
                            context.Response.Write("保存成功!");
                        }
                    }
                }
            }
           
           
            //保存大圖
            hpFile.SaveAs(filePath);
        }

標(biāo)簽:

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請(qǐng)聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請(qǐng)與原作者聯(lián)系。

上一篇:java gzip壓縮解壓縮代碼

下一篇:利用JS實(shí)現(xiàn)時(shí)間格式轉(zhuǎn)化