private void SaveImage() { HttpPostedFile f = Request.Files["Filedata"]; string filename = f.FileName; string filetype = Path.GetExtension(filename).ToLower(); ImageType obj = new ImageType(); string savePath = obj.GetSourcePath(obj.SourcePaths); savePath = Path.Combine(savePath, CurrentUser.UserLoginName); string resourceseq = Path.GetFileNameWithoutExtension(savedFileName); string fileFullPath = Path.Combine(savePath, resourceseq + filetype); bool slImage; try { if (!Directory.Exists(savePath)) { Directory.CreateDirectory(savePath); } //保存原图 f.SaveAs(fileFullPath); string SlImageRootPath; SlImageRootPath = Path.Combine(obj.PreviewPath_170, CurrentUser.UserLoginName); if (!Directory.Exists(SlImageRootPath)) { Directory.CreateDirectory(SlImageRootPath); } ArrayList sarray = new ArrayList(); sarray.Add(fileFullPath); ArrayList aarray = new ArrayList(); aarray.Add(Path.Combine(SlImageRootPath, resourceseq + filetype)); ImageController.ToZipImage(sarray, aarray, 170); SlImageRootPath = Path.Combine(obj.PreviewPath_400, CurrentUser.UserLoginName); if (!Directory.Exists(SlImageRootPath)) { Directory.CreateDirectory(SlImageRootPath); } sarray = new ArrayList(); sarray.Add(fileFullPath); aarray = new ArrayList(); aarray.Add(Path.Combine(SlImageRootPath, resourceseq + filetype)); ImageController.ToZipImage(sarray, aarray, 400); //将原图的长x宽保存起来 System.Drawing.Image m_Image = System.Drawing.Image.FromFile(fileFullPath); Int32 height = Convert.ToInt32(m_Image.Height.ToString()); Int32 width = Convert.ToInt32(m_Image.Width.ToString()); string hvsp = string.Empty; if (height > width) { hvsp = "v"; } else if (width > height) { hvsp = "h"; } else { hvsp = "s"; } Dictionary <string, string> dct = new Dictionary <string, string>(); dct.Add("Width", width.ToString()); dct.Add("Height", height.ToString()); dct.Add("Hvsp", hvsp); List <QJVRMS.Business.ResourceWS.DictionaryEntry> lst = new List <QJVRMS.Business.ResourceWS.DictionaryEntry>(); foreach (string key in dct.Keys) { QJVRMS.Business.ResourceWS.DictionaryEntry de = new QJVRMS.Business.ResourceWS.DictionaryEntry(); de.Key = key; de.Value = dct[key]; lst.Add(de); } QJVRMS.Business.ResourceWS.DictionaryEntry[] result = lst.ToArray(); Resource r = new Resource(); r.insertResourceAttributes(resourceseq, result); Response.Write(resourceseq + filetype + ":" + f.FileName); } catch (Exception e1) { Response.Write("保存图片出现错误" + e1.Message); LogWriter.WriteExceptionLog(e1, true); } finally { } }
private void SaveImage() { HttpPostedFile f = Request.Files["Filedata"]; string filename = f.FileName; string filetype = Path.GetExtension(filename).ToLower(); ImageType obj = new ImageType(); string savePath = obj.GetSourcePath(obj.SourcePaths); savePath = Path.Combine(savePath, CurrentUser.UserLoginName); string resourceseq = Path.GetFileNameWithoutExtension(savedFileName); string fileFullPath = Path.Combine(savePath, resourceseq + filetype); bool slImage; try { if (!Directory.Exists(savePath)) { Directory.CreateDirectory(savePath); } //保存原图 f.SaveAs(fileFullPath); string SlImageRootPath; SlImageRootPath = Path.Combine(obj.PreviewPath_170, CurrentUser.UserLoginName); if (!Directory.Exists(SlImageRootPath)) { Directory.CreateDirectory(SlImageRootPath); } ArrayList sarray = new ArrayList(); sarray.Add(fileFullPath); ArrayList aarray = new ArrayList(); aarray.Add(Path.Combine(SlImageRootPath, resourceseq + filetype)); ImageController.ToZipImage(sarray, aarray, 170); SlImageRootPath = Path.Combine(obj.PreviewPath_400, CurrentUser.UserLoginName); if (!Directory.Exists(SlImageRootPath)) { Directory.CreateDirectory(SlImageRootPath); } sarray = new ArrayList(); sarray.Add(fileFullPath); aarray = new ArrayList(); aarray.Add(Path.Combine(SlImageRootPath, resourceseq + filetype)); ImageController.ToZipImage(sarray, aarray, 400); //将原图的长x宽保存起来 System.Drawing.Image m_Image = System.Drawing.Image.FromFile(fileFullPath); Int32 height = Convert.ToInt32(m_Image.Height.ToString()); Int32 width = Convert.ToInt32(m_Image.Width.ToString()); string hvsp = string.Empty; if (height > width) { hvsp = "v"; } else if (width > height) { hvsp = "h"; } else { hvsp = "s"; } Dictionary<string, string> dct = new Dictionary<string, string>(); dct.Add("Width", width.ToString()); dct.Add("Height", height.ToString()); dct.Add("Hvsp", hvsp); List<QJVRMS.Business.ResourceWS.DictionaryEntry> lst = new List<QJVRMS.Business.ResourceWS.DictionaryEntry>(); foreach (string key in dct.Keys) { QJVRMS.Business.ResourceWS.DictionaryEntry de = new QJVRMS.Business.ResourceWS.DictionaryEntry(); de.Key = key; de.Value = dct[key]; lst.Add(de); } QJVRMS.Business.ResourceWS.DictionaryEntry[] result = lst.ToArray(); Resource r = new Resource(); r.insertResourceAttributes(resourceseq, result); Response.Write(resourceseq + filetype + ":" + f.FileName); } catch (Exception e1) { Response.Write("保存图片出现错误" + e1.Message); LogWriter.WriteExceptionLog(e1, true); } finally { } }
private void SaveImage(string fileName, string fileType) { string path = Server.MapPath(@"\temp\" + fileName + ".thumb.jpg"); string sPath = Server.MapPath(@"\temp\" + fileName + fileType); FileStream fs = new FileStream(sPath, FileMode.Open, FileAccess.Read); int l = int.Parse(fs.Length.ToString()); byte[] b = new byte[l]; fs.Read(b, 0, l); fs.Flush(); fs.Close(); fs = new FileStream(path, FileMode.Open, FileAccess.Read); int ll = int.Parse(fs.Length.ToString()); byte[] bb = new byte[ll]; fs.Read(bb, 0, ll); fs.Flush(); fs.Close(); ImageType obj = new ImageType(); //yangguang //string savePath = obj.SourcePath; string savePath = obj.GetSourcePath(obj.SourcePaths); savePath = Path.Combine(savePath, CurrentUser.UserLoginName); string resourceseq = Path.GetFileNameWithoutExtension(savedFileName); string fileFullPath = Path.Combine(savePath, resourceseq + fileType); string fileFullPath1 = Path.Combine(savePath, resourceseq + ".jpg"); try { if (!Directory.Exists(savePath)) { Directory.CreateDirectory(savePath); } FileStream stream = new FileStream(fileFullPath, FileMode.Create, FileAccess.Write); stream.Write(b, 0, l); stream.Flush(); stream.Close(); stream = new FileStream(fileFullPath1, FileMode.Create, FileAccess.Write); stream.Write(bb, 0, ll); stream.Flush(); stream.Close(); string SlImageRootPath; SlImageRootPath = Path.Combine(obj.PreviewPath_170, CurrentUser.UserLoginName); if (!Directory.Exists(SlImageRootPath)) { Directory.CreateDirectory(SlImageRootPath); } ArrayList sarray = new ArrayList(); sarray.Add(path); ArrayList aarray = new ArrayList(); aarray.Add(Path.Combine(SlImageRootPath, resourceseq + ".jpg")); ImageController.ToZipImage(sarray, aarray, 170); SlImageRootPath = Path.Combine(obj.PreviewPath_400, CurrentUser.UserLoginName); if (!Directory.Exists(SlImageRootPath)) { Directory.CreateDirectory(SlImageRootPath); } sarray = new ArrayList(); sarray.Add(path); aarray = new ArrayList(); aarray.Add(Path.Combine(SlImageRootPath, resourceseq + ".jpg")); ImageController.ToZipImage(sarray, aarray, 400); System.Drawing.Image m_Image = System.Drawing.Image.FromFile(path); Int32 height = Convert.ToInt32(m_Image.Height.ToString()); Int32 width = Convert.ToInt32(m_Image.Width.ToString()); string hvsp = string.Empty; if (height > width) { hvsp = "v"; } else if (width > height) { hvsp = "h"; } else { hvsp = "s"; } Dictionary <string, string> dct = new Dictionary <string, string>(); dct.Add("Width", width.ToString()); dct.Add("Height", height.ToString()); dct.Add("Hvsp", hvsp); List <QJVRMS.Business.ResourceWS.DictionaryEntry> lst = new List <QJVRMS.Business.ResourceWS.DictionaryEntry>(); foreach (string key in dct.Keys) { QJVRMS.Business.ResourceWS.DictionaryEntry de = new QJVRMS.Business.ResourceWS.DictionaryEntry(); de.Key = key; de.Value = dct[key]; lst.Add(de); } QJVRMS.Business.ResourceWS.DictionaryEntry[] result = lst.ToArray(); Resource r = new Resource(); r.insertResourceAttributes(resourceseq, result); string directoryPath = Server.MapPath(@"\temp\"); DirectoryInfo dir = new DirectoryInfo(directoryPath); foreach (FileInfo info in dir.GetFiles()) { DeleteTempFile(info.FullName); } Response.Write(resourceseq + ".jpg" + ":" + savedFileName); } catch (Exception e1) { Response.Write("保存图片出现错误" + e1.Message); LogWriter.WriteExceptionLog(e1, true); } finally { } }
private void SaveImage(string fileName, string fileType) { string path = Server.MapPath(@"\temp\" + fileName + ".thumb.jpg"); string sPath = Server.MapPath(@"\temp\" + fileName + fileType); FileStream fs = new FileStream(sPath, FileMode.Open, FileAccess.Read); int l = int.Parse(fs.Length.ToString()); byte[] b = new byte[l]; fs.Read(b, 0, l); fs.Flush(); fs.Close(); fs = new FileStream(path, FileMode.Open, FileAccess.Read); int ll = int.Parse(fs.Length.ToString()); byte[] bb = new byte[ll]; fs.Read(bb, 0, ll); fs.Flush(); fs.Close(); ImageType obj = new ImageType(); //yangguang //string savePath = obj.SourcePath; string savePath = obj.GetSourcePath(obj.SourcePaths); savePath = Path.Combine(savePath, CurrentUser.UserLoginName); string resourceseq = Path.GetFileNameWithoutExtension(savedFileName); string fileFullPath = Path.Combine(savePath, resourceseq + fileType); string fileFullPath1 = Path.Combine(savePath, resourceseq + ".jpg"); try { if (!Directory.Exists(savePath)) { Directory.CreateDirectory(savePath); } FileStream stream = new FileStream(fileFullPath, FileMode.Create, FileAccess.Write); stream.Write(b, 0, l); stream.Flush(); stream.Close(); stream = new FileStream(fileFullPath1, FileMode.Create, FileAccess.Write); stream.Write(bb, 0, ll); stream.Flush(); stream.Close(); string SlImageRootPath; SlImageRootPath = Path.Combine(obj.PreviewPath_170, CurrentUser.UserLoginName); if (!Directory.Exists(SlImageRootPath)) { Directory.CreateDirectory(SlImageRootPath); } ArrayList sarray = new ArrayList(); sarray.Add(path); ArrayList aarray = new ArrayList(); aarray.Add(Path.Combine(SlImageRootPath, resourceseq + ".jpg")); ImageController.ToZipImage(sarray, aarray, 170); SlImageRootPath = Path.Combine(obj.PreviewPath_400, CurrentUser.UserLoginName); if (!Directory.Exists(SlImageRootPath)) { Directory.CreateDirectory(SlImageRootPath); } sarray = new ArrayList(); sarray.Add(path); aarray = new ArrayList(); aarray.Add(Path.Combine(SlImageRootPath, resourceseq + ".jpg")); ImageController.ToZipImage(sarray, aarray, 400); System.Drawing.Image m_Image = System.Drawing.Image.FromFile(path); Int32 height = Convert.ToInt32(m_Image.Height.ToString()); Int32 width = Convert.ToInt32(m_Image.Width.ToString()); string hvsp = string.Empty; if (height > width) hvsp = "v"; else if (width > height) hvsp = "h"; else hvsp = "s"; Dictionary<string, string> dct = new Dictionary<string, string>(); dct.Add("Width", width.ToString()); dct.Add("Height", height.ToString()); dct.Add("Hvsp", hvsp); List<QJVRMS.Business.ResourceWS.DictionaryEntry> lst = new List<QJVRMS.Business.ResourceWS.DictionaryEntry>(); foreach (string key in dct.Keys) { QJVRMS.Business.ResourceWS.DictionaryEntry de = new QJVRMS.Business.ResourceWS.DictionaryEntry(); de.Key = key; de.Value = dct[key]; lst.Add(de); } QJVRMS.Business.ResourceWS.DictionaryEntry[] result = lst.ToArray(); Resource r = new Resource(); r.insertResourceAttributes(resourceseq, result); string directoryPath = Server.MapPath(@"\temp\"); DirectoryInfo dir = new DirectoryInfo(directoryPath); foreach (FileInfo info in dir.GetFiles()) { DeleteTempFile(info.FullName); } Response.Write(resourceseq + ".jpg" + ":" + savedFileName); } catch (Exception e1) { Response.Write("保存图片出现错误" + e1.Message); LogWriter.WriteExceptionLog(e1, true); } finally { } }