2017-11-30 5 views
-4
string fname = ""; 
    string filename = ""; 
    if (context.Request.Files.Count > 0) 
    {   
     HttpFileCollection files = context.Request.Files; 
     for (int i = 0; i < files.Count; i++) 
     { 
      HttpPostedFile file = files[i]; 
      string filess = files[i].FileName; 


      if (HttpContext.Current.Request.Browser.Browser.ToUpper() == "IE" || HttpContext.Current.Request.Browser.Browser.ToUpper() == "INTERNETEXPLORER") 
      { 
       string[] testfiles = file.FileName.Split(new char[] { '\\' }); 
       fname = DateTime.Now.ToString("ddMMMyyyyhhmissmmm") + testfiles[testfiles.Length - 1]; 
       filename = filename + Path.GetFileName(fname); 
      } 
      else 
      {//some code here 
       fname = DateTime.Now.ToString("ddMMMyyyyhhmissmmm") + file.FileName; 
       filename = filename + Path.GetFileName(fname); 
      } 
      string replacestr = System.Text.RegularExpressions.Regex.Replace(filename, "[^a-zA-Z0-9_]+", " "); 
      fname = replacestr; 
      fname = replacestr; 
      fname = fname.Replace(" ", "").Replace(",", "").Trim(); 
      fname = fname + ""; 
      fname = fname + ".png"; 
      filename = fname; 

fname = Path.Combine(context.Server.MapPath( "../ admin/img/product_images /")、fname);
file.SaveAs(fname);c#を使用して画像にウォーターマークを追加する方法

//ここにいくつかのコード

}}

+5

あなたの実際の問題は何ですか? –

+1

あなたのコードは今何をしていますか?あなたは何をしたいのですか? – mjwills

+0

私は特定のフォルダに保存した後に画像にウォーターマークを追加したいと思います。上記のコードはウォーターマークのない状態では正しく保存されません。 –

答えて

0

//この作品の透かしを行いenter image description here

  Bitmap bmp = new Bitmap(file.InputStream); 
      Graphics graphicsobj = Graphics.FromImage(bmp); 
      Brush brush = new SolidBrush(Color.FromArgb(80, 255, 255, 255)); 
      Point postionWaterMark = new Point((enter image description herebmp.Width/6), (bmp.Height/2)); 
      graphicsobj.DrawString("Daphnisys Technology", new System.Drawing.Font("Arial", 30, FontStyle.Bold, GraphicsUnit.Pixel), brush, postionWaterMark); 
      Image img = (Image)bmp; 
      string filepath = HttpContext.Current.Server.MapPath("../admin/img/product_images/") + filename; 
      //image.Save(filepath); 
      img.Save(filepath, System.Drawing.Imaging.ImageFormat.Png); 
      graphicsobj.Dispose(); 
関連する問題