public async Task <IActionResult> GetFile([FromBody] UploadedImg img, int id) { // Create unique file name string photoId = Guid.NewGuid().ToString(); //string filePath = @"ClientApp\src\assets\Post\" + photoId + ".jpg"; string filePathDetail = "Photo/" + photoId + ".jpg"; string filePath = @"wwwroot\Photo\" + photoId + ".jpg"; // Remove file type from base64 encoding, if any if (img.FileAsBase64.Contains(",")) { img.FileAsBase64 = img.FileAsBase64 .Substring(img.FileAsBase64.IndexOf(",") + 1); } // Convert base64 encoded string to binary img.FileAsByteArray = Convert.FromBase64String(img.FileAsBase64); // Write binary file to server path using (var fs = new FileStream(filePath, FileMode.CreateNew)) { fs.Write(img.FileAsByteArray, 0, img.FileAsByteArray.Length); } ImgPath imgPath = new ImgPath(); imgPath.Path = filePathDetail; imgPath.AlbumID = id; _context.ImgPaths.Add(imgPath); _context.SaveChanges(); await Task.CompletedTask; return(new OkObjectResult(filePathDetail)); }
public async Task <IActionResult> AddAlbumImg(ImgPath img) { _context.ImgPaths.Add(img); _context.SaveChanges(); await Task.CompletedTask; return(Ok()); }
public async Task <IActionResult> RemoveImgFromAlbum(int id) { ImgPath imgPath = _context.ImgPaths.FirstOrDefault(s => s.ID == id); Album album = _context.Album.FirstOrDefault(s => s.ID == imgPath.AlbumID); await Task.CompletedTask; ApiTools.RemoveImg(imgPath.Path); _context.ImgPaths.Remove(imgPath); _context.SaveChanges(); await Task.CompletedTask; return(Ok()); }
private void upload_Click(object sender, RoutedEventArgs e) { string title = caption.Text; string cs = content.Text; string position = order.Text; string storyId = styList.SelectedItem.ToString().Split('_').Last(); string img = ImgPath.Text; string blk = storyId + "?" + title + "?" + cs + "?" + position + "?" + img; cl.upLoadFile(blk); caption.Clear(); content.Clear(); order.Clear(); styList.Items.Clear(); ImgPath.Clear(); }
public IActionResult GetFile([FromBody] UploadedImg img, int id) { // Create unique file name string photoId = Guid.NewGuid().ToString(); //string filePath = @"ClientApp\src\assets\Post\" + photoId + ".jpg"; string filePath = @"wwwroot\Photo\" + photoId + ".jpg"; // Remove file type from base64 encoding, if any if (img.FileAsBase64.Contains(",")) { img.FileAsBase64 = img.FileAsBase64 .Substring(img.FileAsBase64.IndexOf(",") + 1); } // Convert base64 encoded string to binary img.FileAsByteArray = Convert.FromBase64String(img.FileAsBase64); // Write binary file to server path using (var fs = new FileStream(filePath, FileMode.CreateNew)) { fs.Write(img.FileAsByteArray, 0, img.FileAsByteArray.Length); } var entity = _context.Album.FirstOrDefault(s => s.ID == id); if (entity == null) { return(new BadRequestResult()); } ImgPath path = new ImgPath(); path.Path = filePath; entity.ImgPaths.Add(path); _context.Entry(entity).CurrentValues.SetValues(entity); _context.SaveChanges(); return(new OkObjectResult("Photo/" + photoId + ".jpg")); }
private void Recurse(int FolderId, string CurrentDirectory) { // Create Child Docs List<int> ChildDocs = dir.ChildDocumentIds(FolderId); foreach (int docId in ChildDocs) { // Create a Folder if (!Directory.Exists(CurrentDirectory + doc.DocumentName(docId)) {Directory.CreateDirectory(CurrentDirectory + doc.DocumentName(docId));} // Get Image Paths List<string> ImgPaths = doc.ImagePaths(docId); // Move Images foreach (string ImgPath in ImgPaths) { File.Copy(ImgPath, CurrentDirectory + doc.DocumentName(docId) + "\\" + ImgPath.Substring(ImgPath.LastIndexOf("\\") + 1)); } } // Create Child Folders List<int> ChildFolders = dir.ChildFolderIds(FolderId); foreach (int fid in ChildFolders) { if (!Directory.Exists(CurrentDirectory + dir.FolderName(fid))) { Directory.CreateDirectory(CurrentDirectory + dir.FolderName(fid)); } Recurse(fid, CurrentDirectory + dir.FolderName(fid) + "\\"); } }
private void Export() { string DestinationRootDir = tbxDestinationRoot.Text; // Make sure last char is a backslash if (DestinationRootDir.Substring(DestinationRootDir.Length - 1) != "\\") { DestinationRootDir = DestinationRootDir + '\\'; } // Get name of root folder string RootFolderName = dir.FolderName(1); // Create root folder inside location provided by user if (!Directory.Exists(DestinationRootDir + RootFolderName)) { Directory.CreateDirectory(DestinationRootDir + RootFolderName); } // Create Child Docs List<int> ChildDocs = dir.ChildDocumentIds(1); foreach (int docId in ChildDocs) { // Create a Folder if (!Directory.Exists(DestinationRootDir + RootFolderName + "\\" + doc.DocumentName(docId)) {Directory.CreateDirectory(DestinationRootDir + RootFolderName + "\\" + doc.DocumentName(docId));} // Get Image Paths List<string> ImgPaths = doc.ImagePaths(docId); // Move Images foreach (string ImgPath in ImgPaths) { File.Copy(ImgPath, DestinationRootDir + RootFolderName + "\\" + doc.DocumentName(docId) + "\\" + ImgPath.Substring(ImgPath.LastIndexOf("\\") + 1)); } } // Create Child Folders List<int> ChildFolders = dir.ChildFolderIds(1); foreach (int fid in ChildFolders) { if (!Directory.Exists(DestinationRootDir + RootFolderName + "\\" + dir.FolderName(fid))) { Directory.CreateDirectory(DestinationRootDir + RootFolderName + "\\" + dir.FolderName(fid)); } Recurse(0, DestinationRootDir + RootFolderName + "\\" + dir.FolderName(fid) + "\\"); } }
public void Save() { Image image = Image.FromFile(@ImgPath); Bitmap bitmap = new Bitmap(image.Width, image.Height); Graphics graphics = Graphics.FromImage(bitmap); graphics.DrawImage(image, 0, 0, image.Width, image.Height); //文字区域宽高 float stringHeight = image.Height - float.Parse(Top) - float.Parse(Bottom); float stringWidth = image.Width - 2 * float.Parse(BothSides); //↖️↘️ float x1 = float.Parse(BothSides); float y1 = float.Parse(Top); //间隔 float xSpace = stringWidth / float.Parse(Column); float ySpace = stringHeight / float.Parse(Row); ListName = Names.Split(new string[] { "\r\n" }, StringSplitOptions.None); for (int i = 0; i < int.Parse(Row); i++) //按行打印 { float y = i * ySpace + y1; //计算当前行的纵坐标 for (int j = 0; j < int.Parse(Column); j++) { int num = i * int.Parse(Column) + j + 1;//第n个元素 //计算坐标 float x = j * xSpace + x1; Point p = new Point((int)x, (int)y);//坐标 if (num > ListName.Length) { break; } else { graphics.DrawString(ListName[num - 1], new Font(FontName, float.Parse(Scale) * 0.2f * stringHeight / int.Parse(Row), FontStyle.Bold), new SolidBrush(Color.Black), p); } } } string output = ImgPath.Replace(@".png", @"副本.png"); bitmap.Save(output); //Random random = new Random(); //string str = ""; //for (int i = 0; i < 5; i++) //{ // int x = random.Next(0, 10); // str += x; //} //string[] myfont = { "宋体", "仿宋", "微软雅黑", "楷书", "黑体" }; //Color[] colors = { Color.Red, Color.Green, Color.Black, Color.Blue, Color.Yellow }; //for (int i = 0; i < 5; i++) //{ // Point p = new Point(i * 20, 0); // graphics.DrawString(str[i].ToString(), new Font(myfont[i], 16, FontStyle.Bold), new SolidBrush(colors[i]), p); //} //bitmap.Save(@"/Users/tylor/Desktop/1.png"); }