public JsonResult GetImageSheet( int imageWidth, int imageHeight, int sheetWidth, int sheetHeight, float xStartPercent, float yStartPercent, float cropWidthPercent, float cropHeightPercent, [FromBody] string image) { string[] splitImage = image.Split(","); Image <Rgba32> inputImage = StringToImage(splitImage[1]); //Convert from percentage values to image-relative values. int xStart = (int)(inputImage.Width * (xStartPercent / 100)); int yStart = (int)(inputImage.Height * (yStartPercent / 100)); int cropHeight = (int)(inputImage.Height * (cropHeightPercent / 100)); int cropWidth = (int)(inputImage.Width * (cropWidthPercent / 100)); ImageSheet sheet = ImageSheet.FromImage(inputImage); sheet.SetSheetFormat(new CustomSheet(sheetWidth, sheetHeight)); sheet.SetImageFormat(new CustomImageFormat(imageWidth, imageHeight)); sheet.SetCropArea(xStart, yStart, xStart + cropWidth, yStart + cropHeight); //Disabled until ImagePermutator library calculates cols and rows correctly on rotation. //if(sheetHeight > sheetWidth) //{ // sheet.SetCroppedImageRotation(270); // sheet.SetOutputImageRotation(90); //} sheet.Create(); string outputImageString = sheet.OutputImage.ToBase64String(ImageFormats.Png); inputImage.Dispose(); sheet.CroppedImage.Dispose(); sheet.OutputImage.Dispose(); sheet.SourceImage.Dispose(); return(new JsonResult(outputImageString)); }
private void WriteImageSheetJson(JsonWriter output, string key, ImageSheet sheet) { using (output.BeginObject(key)) { using (output.BeginArray("entries")) { foreach (ImageSheetEntry entry in sheet) { entry.WriteJson(output); } } } }
private void PrepareFontImageSheets() { ImageSheet outlineMonoCharSheet = new ImageSheet(settings.MaxImageSheetWidth, settings.MaxImageSheetHeight, 2, 1); ImageSheet normalMonoCharSheet = new ImageSheet(settings.MaxImageSheetWidth, settings.MaxImageSheetHeight, 0, 0); outlineMonoCharSheet.ClearColor = Color.Black; outlineMonoCharSheet.MakeTransparent = true; normalMonoCharSheet.ClearColor = Color.Black; normalMonoCharSheet.MakeTransparent = true; fonts = GetFonts(); foreach (AgsFont font in fonts) { foreach (AgsFontChar c in font.Chars) { if (c == null || c.Width == 0 || c.Height == 0) { continue; } if (font.font.OutlineStyle == AGS.Types.FontOutlineStyle.Automatic) { outlineMonoCharSheet.AddEntry(c); } else { normalMonoCharSheet.AddEntry(c); } } } if (!normalMonoCharSheet.IsEmpty) { if (!normalMonoCharSheet.Pack()) { throw new Exception("Cannot pack normal fonts!"); } GameImageSheets.Add(normalMonoCharSheet); } if (!outlineMonoCharSheet.IsEmpty) { if (!outlineMonoCharSheet.Pack()) { throw new Exception("Cannot pack outline fonts!"); } GameImageSheets.Add(outlineMonoCharSheet); } }
private void ExportSpriteFolder( AGS.Types.ISpriteFolder folder, ImageSheet toMaskSheet, List<ImageSheet> completeImageSheets, bool alpha, bool topLevel) { if (toMaskSheet == null) { toMaskSheet = new ImageSheet(settings.MaxImageSheetWidth, settings.MaxImageSheetHeight, 0, 0); if (!alpha) { toMaskSheet.ClearColor = HacksAndKludges.GetTransparencyColor(); toMaskSheet.MakeTransparent = true; } foreach (AGS.Types.Sprite sprite in folder.Sprites) { if ((alpha && !sprite.AlphaChannel) || (!alpha && sprite.AlphaChannel)) { continue; } if (sprite.Width > settings.MaxImageSheetWidth || sprite.Height > settings.MaxImageSheetHeight) { throw new Exception("Sprite #" + sprite.Number + " is bigger than the maximum image sheet size"); } SpriteImageSheetEntry entry; if (alpha) { entry = new SpriteImageSheetEntry(editor, sprite, Color.Transparent); } else { entry = new SpriteImageSheetEntry(editor, sprite, HacksAndKludges.GetTransparencyColor()); } if (!toMaskSheet.AddEntry(entry)) { if (!toMaskSheet.IsEmpty) { completeImageSheets.Add(toMaskSheet); } toMaskSheet = new ImageSheet(settings.MaxImageSheetWidth, settings.MaxImageSheetHeight, 0, 0); } } } else { object maskSnapshot = toMaskSheet.Snapshot(); foreach (AGS.Types.Sprite sprite in folder.Sprites) { if ((alpha && !sprite.AlphaChannel) || (!alpha && sprite.AlphaChannel)) { continue; } if (sprite.Width > settings.MaxImageSheetWidth || sprite.Height > settings.MaxImageSheetHeight) { throw new Exception("Sprite #" + sprite.Number + " is bigger than the maximum image sheet size"); } SpriteImageSheetEntry entry; if (alpha) { entry = new SpriteImageSheetEntry(editor, sprite, Color.Transparent); } else { entry = new SpriteImageSheetEntry(editor, sprite, HacksAndKludges.GetTransparencyColor()); } if (!toMaskSheet.AddEntry(entry)) { toMaskSheet.RestoreSnapshot(maskSnapshot); ExportSpriteFolder(folder, null, completeImageSheets, alpha, true); return; } } } int insert = completeImageSheets.Count; foreach (AGS.Types.SpriteFolder subfolder in folder.SubFolders) { ExportSpriteFolder(subfolder, toMaskSheet, completeImageSheets, alpha, false); } if (topLevel && !toMaskSheet.IsEmpty) { completeImageSheets.Insert(insert, toMaskSheet); } }
private void WriteImageSheetJson(JsonWriter output, ImageSheet sheet) { WriteImageSheetJson(output, null, sheet); }