public ActionResult CreateGif(long[] PlayerImageIDs) { string Msg = ""; bool status = true; long ParamPlayerID = 0; PlayerImagesRepository modelRepo = new PlayerImagesRepository(); // var Selected_PlayerImgs = modelRepo.ReadAll(false).Where(m => PlayerImageIDs.Contains(m.PlayerImageID)).ToList(); List <string> ListOfImagePaths = new List <string>(); foreach (var item in PlayerImageIDs) { var Selected_PlayerImgs = modelRepo.ReadOne(item); string FullPath = Server.MapPath(Selected_PlayerImgs.ImageLink); ListOfImagePaths.Add(FullPath); ParamPlayerID = Selected_PlayerImgs.PlayerID; } string PlayerImagesFolder = Path.Combine(Server.MapPath("~" + SecurityUtils.Players_ImagePath + ""), ParamPlayerID.ToString()); modelRepo.CreateGif(ListOfImagePaths, PlayerImagesFolder, ParamPlayerID, ref Msg, ref status, this); //String[] imageFilePaths = new String[] { "D:\\temp\\01.png", "D:\\temp\\02.png", "D:\\temp\\03.png" }; //String outputFilePath = "D:\\temp\\test.gif"; //AnimatedGifEncoder e = new AnimatedGifEncoder(); //e.Start(outputFilePath); //e.SetDelay(1000); ////-1:no repeat,0:always repeat //e.SetRepeat(0); //for (int i = 0, count = imageFilePaths.Length; i < count; i++) //{ // e.AddFrame(Image.FromFile(imageFilePaths[i])); //} //e.Finish(); ///* extract Gif */ //string outputPath = "D:\\temp"; //GifDecoder gifDecoder = new GifDecoder(); //gifDecoder.Read("D:\\temp\\Finalsss.gif"); //for (int i = 0, count = gifDecoder.GetFrameCount(); i < count; i++) //{ // Image frame = gifDecoder.GetFrame(i); // frame i // frame.Save(outputPath + Guid.NewGuid().ToString() + ".png", ImageFormat.Png); //} if (status && SecurityUtils.Enable_PremiumDashboard) { AchievementsRepository achRepo = new AchievementsRepository(); Guid guid = Guid.NewGuid(); AchievementThread = new Thread(() => achRepo.ImageGallery_AchievementPoints(ParamPlayerID, AchievementThread)); AchievementThread.Name = "ImageGallery_BeforeAfterImageCreated_AchievementPoints_" + guid.ToString(); AchievementThread.Start(); } return(new JsonResult { Data = new { status = status, Msg = Msg } }); }
public ActionResult Async_Save(IEnumerable <HttpPostedFileBase> files) { long ParamPlayerID = 4; string FinalFileName = ""; // The Name of the Upload component is "files" if (files != null) { PlayerImagesRepository modelRepo = new PlayerImagesRepository(); string PlayerImagesFolder = Path.Combine(Server.MapPath("~" + SecurityUtils.Players_ImagePath + ""), ParamPlayerID.ToString()); foreach (var file in files) { if (!(System.IO.Directory.Exists(PlayerImagesFolder))) { System.IO.Directory.CreateDirectory(PlayerImagesFolder); } // Some browsers send file names with full path. This needs to be stripped. string IEFileName = "", FileNameWithExtension = ""; if (Request.Browser.Browser.ToLower().Equals("ie") || Request.Browser.Browser.ToLower().Equals("internetexplorer")) { IEFileName = Path.GetFileName(file.FileName); } if (IEFileName != "") { FileNameWithExtension = IEFileName; SecurityUtils.CheckforInvalidFileNameChar(ref FileNameWithExtension); } else { FileNameWithExtension = file.FileName; SecurityUtils.CheckforInvalidFileNameChar(ref FileNameWithExtension); } var fileExtension = Path.GetExtension(FileNameWithExtension); //Following Code will rename the file if it is already Exists int count = 1; string fileNameOnly = Guid.NewGuid().ToString(); //Path.GetFileNameWithoutExtension(FileNameWithExtension); string extension = Path.GetExtension(FileNameWithExtension); string newFullPath = FileNameWithExtension; newFullPath = Path.Combine(PlayerImagesFolder, fileNameOnly + extension); while (System.IO.File.Exists(newFullPath)) { string tempFileName = string.Format("{0}({1})", fileNameOnly, count++); newFullPath = Path.Combine(PlayerImagesFolder, tempFileName + extension); } fileNameOnly = Path.GetFileNameWithoutExtension(newFullPath); //Update Filename from Repository string Msg = ""; bool status = true; FinalFileName = fileNameOnly + extension; //Save the file to the Disk file.SaveAs(newFullPath); string PlayerImagePath = Path.Combine(PlayerImagesFolder, FinalFileName); string WaterMarkImagePath = Server.MapPath("~/Images/verticle_mvff.png"); Image_Combine imgCombine = new Image_Combine(); string FinalFileName_WaterMarked = imgCombine.CombineBitmap_WatermarkImage(PlayerImagesFolder, FinalFileName, WaterMarkImagePath); //Clear the Object imgCombine = null; PlayerImagesExt PlayerImg = new PlayerImagesExt() { PlayerID = ParamPlayerID, FileName = FinalFileName_WaterMarked, IsAnimated = false, Display = true, DefaultImage = false, UploadDateTime = DateTime.Now }; modelRepo.CreateOrUpdate(ref PlayerImg, ref Msg, ref status, this); string NonWaterMarkImagePath = Path.Combine(PlayerImagesFolder, FinalFileName); if (System.IO.File.Exists(NonWaterMarkImagePath)) { System.IO.File.Delete(NonWaterMarkImagePath); } if (status && SecurityUtils.Enable_PremiumDashboard) { AchievementsRepository achRepo = new AchievementsRepository(); Guid guid = Guid.NewGuid(); AchievementThread = new Thread(() => achRepo.ImageGallery_AchievementPoints(ParamPlayerID, AchievementThread)); AchievementThread.Name = "ImageGallery_BeforeAfterImageCreated_AchievementPoints_" + guid.ToString(); AchievementThread.Start(); } } } // Return an empty string to signify success return(Content("")); }