//上传控件 包括图片和文件 public string UploadFileAndImage(string fileStorageName, string uploadName, string width = "100", string height = "100", bool isCut = false) { //保存临时文件 HttpPostedFileBase file = Request.Files[0]; ResourceInfo info = SaveFileByStorageName(file, fileStorageName); if (file.ContentType == "image/jpeg") { //上传图片 info.IsImage = true; if (!isCut) { string oldPath = info.PhysicalPath; string fileName = Path.GetFileName(oldPath); string oldTitle = Path.GetFileNameWithoutExtension(oldPath); if (uploadName.IsEmpty()) { if (!height.IsEmpty() && !width.IsEmpty()) { string newFile = FileUtil.ChangeFileName(oldPath, ImageCut.GetNewFileTitle(oldTitle, width.Value <int>(), height.Value <int>())); ImageUtil.SavePictureInFile(oldPath, fileName, width.Value <int>(), height.Value <int>(), newFile); string _ff = "{0}-{1}".AkFormat(width, height); info.ExtendList.Add(_ff, _ff); } } else { var _cuts = FileManagementUtil.GetImageCutsByUploadName(uploadName); foreach (ImageCut cut in _cuts) { string newFile = FileUtil.ChangeFileName(oldPath, cut.GetNewFileTitle(oldTitle)); ImageUtil.SavePictureInFile(oldPath, fileName, cut.ImageSizeWidth, cut.ImageSizeHeight, newFile, cut.Quality); string _ff = "{0}-{1}".AkFormat(cut.ImageSizeWidth, cut.ImageSizeHeight); info.ExtendList.Add(_ff, _ff); } } } } else { //上传文件 info.IsImage = false; } return(ReturnJson(info)); }
public static ImageCut FromBaseObject(BaseObject baseObj) { if (baseObj == null || baseObj.NativeObject == IntPtr.Zero) { return(null); } ImageCut obj = baseObj as ImageCut; if (object.Equals(obj, null)) { obj = new ImageCut(CreatedWhenConstruct.CWC_NotToCreate); obj.BindNativeObject(baseObj.NativeObject, "CImageCut"); obj.IncreaseCast(); } return(obj); }
public void Init(string txt) { Regex re = new Regex(RegexHead); MatchCollection gc = re.Matches(txt); int indexText = 0; foreach (Match match in gc) { NormalCut ntbd = new NormalCut(); ntbd.SetInfo(txt.Substring(indexText, match.Index - indexText)); indexText = match.Index + match.Length; mCutDatas.Add(ntbd); ntbd.Create(); string allName = match.Groups[0].ToString(); if (allName.Length > 8) { if (allName.IndexOf("<link=", 0, 6) != -1) { LinkCut ltd = new LinkCut(); ltd.SetInfo(allName, match.Groups[1].ToString(), match.Groups[2].ToString()); mCutDatas.Add(ltd); ltd.Create(); } else if (allName.IndexOf("<color=", 0, 7) != -1) { ColorCut ltd = new ColorCut(); ltd.SetInfo(allName, match.Groups[3].ToString(), match.Groups[4].ToString()); mCutDatas.Add(ltd); ltd.Create(); } else if (allName.IndexOf("<image=", 0, 7) != -1) { ImageCut ltd = new ImageCut(); ltd.SetInfo(allName, "", ""); mCutDatas.Add(ltd); ltd.Create(); } } } NormalCut temp = new NormalCut(); temp.SetInfo(txt.Substring(indexText, txt.Length - indexText)); mCutDatas.Add(temp); temp.Create(); }
Bitmap Bi; //定义位图对像 private void button11_Click(object sender, EventArgs e) { openFileDialog1.Filter = "*.gif|*.jpg|*.JPEG|*.JPEG|*.bmp|*.bmp"; //设置读取图片类型 if (openFileDialog1.ShowDialog() == DialogResult.OK) { try { strHeadImagePath = openFileDialog1.FileName; //this.Show(strHeadImagePath); Bi = new Bitmap(strHeadImagePath); //使用打开的图片路径创建位图对像 ImageCut IC = new ImageCut(40, 112, this.pictureBox1.Width, this.pictureBox1.Height); //实例化ImageCut类,四个参数据分别表示为:x、y、width、heigth,(40、112)表示pictureBox1的Lcation的坐标,(120、144)表示pictureBox1控件的宽度和高度 this.pictureBox1.Image = IC.KiCut((Bitmap)(this.GetSelectImage(this.pictureBox1.Width, this.pictureBox1.Height))); //(120、144)表示pictureBox1控件的宽度和高度 //this.pictureBox1.Image = (this.GetSelectImage(120, 144)); } catch (Exception ex) { MessageBox.Show("格式不对"); ex.ToString(); } } else { } }
public string UploadImage(string fileStorageName, string width, string height, bool isCut, string uploadName) { //保存临时文件 HttpPostedFileBase file = Request.Files[0]; ResourceInfo info = SaveFileByStorageName(file, fileStorageName); if (!isCut) { string oldPath = info.PhysicalPath; string fileName = Path.GetFileName(oldPath); string oldTitle = Path.GetFileNameWithoutExtension(oldPath); if (uploadName.IsEmpty()) { if (!height.IsEmpty() && !width.IsEmpty()) { string newFile = FileUtil.ChangeFileName(oldPath, ImageCut.GetNewFileTitle(oldTitle, width.Value <int>(), height.Value <int>())); ImageUtil.SavePictureInFile(oldPath, fileName, width.Value <int>(), height.Value <int>(), newFile); string _ff = "{0}-{1}".AkFormat(width, height); info.ExtendList.Add(_ff, _ff); } } else { var _cuts = FileManagementUtil.GetImageCutsByUploadName(uploadName); foreach (ImageCut cut in _cuts) { string newFile = FileUtil.ChangeFileName(oldPath, cut.GetNewFileTitle(oldTitle)); ImageUtil.SavePictureInFile(oldPath, fileName, cut.ImageSizeWidth, cut.ImageSizeHeight, newFile, cut.Quality); string _ff = "{0}-{1}".AkFormat(cut.ImageSizeWidth, cut.ImageSizeHeight); info.ExtendList.Add(_ff, _ff); } } //ImageUtil.SavePictureInFile(oldPath, fileName, width.Value<int>(), height.Value<int>(), fullPath); //System.IO.File.Delete(tempPath); } else { } return(ReturnJson(info)); //获取文件夹物理路径 //string path = ThumbsPath; //if (!Directory.Exists(path)) //{ // Directory.CreateDirectory(path); //} ////获取文件后缀 //string fileExtension = Path.GetExtension(file.FileName); //string fileExtensionButDot = Path.GetExtension(file.FileName).Substring(1); //string fileID = AtawAppContext.Current.UnitOfData.GetUniId(); //int pathID = fileID.Substring(0, 8).Value<int>(); //AtawDebug.Assert(pathID > 0, "文件夹字符串不能为空", this); //string relativePath = Path.Combine(FileManagementUtil.GetRelativePath(fileStorageName, pathID.Value<int>()), // FileManagementUtil.GetFileName(fileStorageName, fileID, fileExtension)); //string fullPath = new Uri(Path.Combine(FileManagementUtil.GetRootPath(fileStorageName, FilePathScheme.Physical), relativePath)).LocalPath; //FileManagementUtil.ForeDirectories(FileManagementUtil.GetParentDirectory(fullPath)); //string newFileName = fileID + fileExtension; //string tempPath = path + newFileName; //file.SaveAs(tempPath); //string httpPath = ""; //if (!isCut) //{ // httpPath = FileManagementUtil.GetFullPath(fileStorageName, FilePathScheme.Http, pathID, fileID, fileExtensionButDot); // ImageUtil.SavePictureInFile(tempPath, newFileName, width.Value<int>(), height.Value<int>(), fullPath); // System.IO.File.Delete(tempPath); //} //else //{ // httpPath = TH_PATH + newFileName; //} //string res = FastJson( // new // { // FileName = Path.GetFileNameWithoutExtension(file.FileName), // FileExtension = fileExtension, // HttpPath = httpPath, //当图片需要裁减时,该值是临时路径,不需要裁减则值为当前图片保存在服务器上的路径 // FileSize = file.ContentLength / 1024, // } // ); //return res; }
public BaseObject Create() { ImageCut emptyInstance = new ImageCut(CreatedWhenConstruct.CWC_NotToCreate); return(emptyInstance); }