public static Stream GetVector(ApiPattern pattern, string filter) { var bitmap = GetMergedBitmap(pattern); var stream = FiltersHandler.ApplySvgFilter(bitmap, filter); return(stream); }
public PatternImage CanvasesToPatternImage(ApiPattern pattern, int scale, String filterName) { if (scale < 1 || scale > 4) { throw new ArgumentException("Scale can't be less than 1 and more than 4"); } var mergedBitmap = GetMergedBitmap(pattern); mergedBitmap = FiltersHandler.ApplyFilter(mergedBitmap, scale, filterName); byte[] bytes; String contentType; using (var stream = new MemoryStream()) { var pixelsCount = mergedBitmap.Width * mergedBitmap.Height; if (pixelsCount < 500 * 500) { mergedBitmap.Save(stream, ImageFormat.Png); contentType = "image/png"; } else { var quality = pixelsCount < 700 * 700 ? 100L : pixelsCount < 1000 * 1000 ? 80L : 60L; ImageCodecInfo jgpEncoder = GetEncoder(ImageFormat.Jpeg); Encoder myEncoder = Encoder.Quality; var myEncoderParameters = new EncoderParameters(1); var myEncoderParameter = new EncoderParameter(myEncoder, quality); myEncoderParameters.Param[0] = myEncoderParameter; mergedBitmap.Save(stream, jgpEncoder, myEncoderParameters); contentType = "image/jpeg"; } stream.Close(); bytes = stream.ToArray(); } var result = new PatternImage() { RawData = bytes, ContentType = contentType }; return(result); }