public override void SaveImage(MemBitmap bitmap, string filename, OutputImageFormat outputFormat, object saveParameters) { //using (FileStream fs = new FileStream(filename, FileMode.Create)) //{ // SaveImage(bitmap, fs, outputFormat, saveParameters); //} }
/// <summary> /// <inheritdoc /> /// </summary> public StoragePathModel PrepareStoragePath(OutputImageFormat format) { var uploadKeyGuid = Guid.NewGuid(); var uploadKey = uploadKeyGuid.ToString("N"); var basePath = this.appSettings.Value.Directory.WorkingDirectory; var segmentsPath = Path.Combine( uploadKey[0].ToString(), uploadKey[1].ToString(), uploadKey[2].ToString()); var baseDirectoryPath = Path.Combine(basePath, segmentsPath); var finalPath = $"{Path.Combine(baseDirectoryPath, uploadKey)}.{format.GetImageFormat()}"; var urlPath = $"/{segmentsPath}/{uploadKey}.{format.GetImageFormat()}"; // If storage directory doesn't exists, create it if (!Directory.Exists(baseDirectoryPath)) { Directory.CreateDirectory(baseDirectoryPath); } return(new StoragePathModel { Key = uploadKeyGuid, FilePath = finalPath, UrlPath = urlPath }); }
public MemBitmap LoadImage(Stream input, OutputImageFormat format) { ImageTools.ExtendedImage extendedImg = new ImageTools.ExtendedImage(); //TODO: review img loading, we should not use only its extension switch (format) { case OutputImageFormat.Jpeg: { var decoder = new ImageTools.IO.Jpeg.JpegDecoder(); var dst = new JpegDecoderDst(); extendedImg.JpegDecompressDest = dst; extendedImg.Load(input, decoder); //copy from return(dst.MemBitmapOutput); } break; case OutputImageFormat.Png: { var decoder = new ImageTools.IO.Png.PngDecoder(); extendedImg.Load(input, decoder); } break; default: throw new System.NotSupportedException(); } //assume 32 bit ?? byte[] pixels = extendedImg.Pixels; unsafe { fixed(byte *p_src = &pixels[0]) { PixelFarm.CpuBlit.MemBitmap memBmp = PixelFarm.CpuBlit.MemBitmap.CreateFromCopy( extendedImg.PixelWidth, extendedImg.PixelHeight, (IntPtr)p_src, pixels.Length, false ); memBmp.IsBigEndian = true; return(memBmp); } } ////PixelFarm.CpuBlit.MemBitmap memBmp = PixelFarm.CpuBlit.MemBitmap.CreateFromCopy( //// extendedImg.PixelWidth, //// extendedImg.PixelHeight, //// extendedImg.PixelWidth * 4, //assume //// 32, //assume? //// extendedImg.Pixels, //// false //// ); ////the imgtools load data as BigEndian //memBmp.IsBigEndian = true; //return memBmp; }
public override void SaveImage(MemBitmap bitmap, string filename, OutputImageFormat outputFormat, object saveParameters) { //using (FileStream fs = new FileStream(LocalFileStorageProvider.s_globalBaseDir + "/" + filename, FileMode.Create)) //{ // SaveImage(bitmap, fs, outputFormat, saveParameters); //} }
public override void SaveImage(MemBitmap bitmap, Stream output, OutputImageFormat outputFormat, object saveParameters) { //save img to using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(bitmap.Width, bitmap.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)) { var bmpdata = bmp.LockBits(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); unsafe { byte *ptr = (byte *)MemBitmap.GetBufferPtr(bitmap).Ptr; MemMx.memcpy((byte *)bmpdata.Scan0, ptr, bmpdata.Stride * bmp.Height); } bmp.UnlockBits(bmpdata); //save to stream System.Drawing.Imaging.ImageFormat format = null; switch (outputFormat) { case OutputImageFormat.Default: throw new NotSupportedException(); case OutputImageFormat.Jpeg: format = System.Drawing.Imaging.ImageFormat.Jpeg; break; case OutputImageFormat.Png: format = System.Drawing.Imaging.ImageFormat.Png; break; } bmp.Save(output, format); } }
public static string GetMimeType(this OutputImageFormat val) { return(val.GetType() .GetMember(val.ToString()) .FirstOrDefault() ?.GetCustomAttribute <MimeTypeAttribute>(false) ?.Description ?? val.ToString()); }
public async Task <IActionResult> ToJpeg(OutputImageFormat type) { var file = this.GetDefaultFile(); if (file == null) { return(BadRequest()); } return(await File(file, type)); }
public override void SaveImage(MemBitmap bitmap, Stream output, OutputImageFormat outputFormat, object saveParameters) { switch (outputFormat) { case OutputImageFormat.Png: PngIOStorage.Save(bitmap, output); break; default: throw new NotSupportedException(); } //throw new NotImplementedException(); }
private static MagickFormat ToMagickFormat(OutputImageFormat outputFormat) { var magickFormat = outputFormat switch { OutputImageFormat.Gif => MagickFormat.Gif, OutputImageFormat.Png => MagickFormat.Png, _ => MagickFormat.Jpeg }; return(magickFormat); } #endregion }
private async Task <IActionResult> File(IFormFile file, OutputImageFormat format) { var outputStream = new MemoryStream(); await using var imageStream = file.OpenReadStream(); await this.imageConvertingService.ImageToFormat(imageStream, new StreamImageSavingParamsModel { Format = OutputImageFormat.Jpeg, Quality = Constants.DefaultJpegQuality, OutputStream = outputStream }); return(File(outputStream, format.GetMimeType())); }
public MemBitmap LoadImage(Stream input, OutputImageFormat format) { ImageTools.ExtendedImage extendedImg = new ImageTools.ExtendedImage(); //TODO: review img loading, we should not use only its extension switch (format) { case OutputImageFormat.Png: { var decoder = new ImageTools.IO.Png.PngDecoder(); extendedImg.Load(input, decoder); } break; case OutputImageFormat.Jpeg: { var decoder = new ImageTools.IO.Jpeg.JpegDecoder(); extendedImg.Load(input, decoder); } break; default: throw new System.NotSupportedException(); } //var decoder = new ImageTools.IO.Png.PngDecoder(); //assume 32 bit PixelFarm.CpuBlit.MemBitmap memBmp = PixelFarm.CpuBlit.MemBitmap.CreateFromCopy( extendedImg.PixelWidth, extendedImg.PixelHeight, extendedImg.Pixels32 ); //the imgtools load data as BigEndian memBmp.IsBigEndian = true; return(memBmp); }
/// <summary> /// Converts to file with given name and format /// </summary> /// <param name="filename">The output file name to save the image to</param> /// <param name="imageFormat">The output image file format. Example: JPEG, GIF, PNG</param> /// <returns>True on success, false on error</returns> public bool toFile(string filename, OutputImageFormat imageFormat) { this.output = new Output(OutputType.File, imageFormat, filename); return(this.convertToFile()); }
public Output(OutputType type, OutputImageFormat imageFormat) : this(type, imageFormat, null) { }
public Output(OutputType type, OutputImageFormat imageFormat, string value) { this.type = type; this.imageFormat = imageFormat; this.value = value; }
/// <summary> /// Converts to file with given name and format /// </summary> /// <param name="filename">The output file name to save the image to</param> /// <param name="imageFormat">The output image file format. Example: JPEG, GIF, PNG</param> /// <returns>True on success, false on error</returns> public bool toFile(string filename, OutputImageFormat imageFormat) { this.output = new Output(OutputType.File, imageFormat, filename); return this.convertToFile(); }
/// <summary> /// Converts to base64 encoded string with given output image format /// </summary> /// <param name="imageFormat">The desired output image format. Example: JPEG, GIF, PNG</param> /// <returns>The base64 encoded string that represents the image</returns> public string toBase46EncodedString(OutputImageFormat imageFormat) { this.output = new Output(OutputType.Base64EncodedString, imageFormat); return this.convertToBase46EncodedString(); }
public abstract void SaveImage(MemBitmap bitmap, string filename, OutputImageFormat outputFormat, object saveParameters);
public abstract void SaveImage(MemBitmap bitmap, System.IO.Stream output, OutputImageFormat outputFormat, object saveParameters);
/// <summary> /// <inheritdoc /> /// </summary> public ImageThumbPathsModel PrepareThumbFilePath(StoragePathModel originalPath, OutputImageFormat format, int width, int height) { // Prepare a disk path var diskPath = $"{Path.ChangeExtension(originalPath.FilePath, null)}_thumb_{width}x{height}.{format.GetImageFormat()}"; // Prepare an URL path var url = this.NormalizeWebPath(Path.ChangeExtension(originalPath.UrlPath, null)) + $"_thumb_{width}x{height}.{format.GetImageFormat()}"; return(new ImageThumbPathsModel { DiskPath = diskPath, Url = url }); }
/// <summary> /// Converts to base64 encoded string with given output image format /// </summary> /// <param name="imageFormat">The desired output image format. Example: JPEG, GIF, PNG</param> /// <returns>The base64 encoded string that represents the image</returns> public string toBase46EncodedString(OutputImageFormat imageFormat) { this.output = new Output(OutputType.Base64EncodedString, imageFormat); return(this.convertToBase46EncodedString()); }
public override void SaveImage(MemBitmap bitmap, string filename, OutputImageFormat outputFormat, object saveParameters) { throw new NotImplementedException(); }
public async Task StartFrameReaderAsync(InputSource inputSource, OutputImageFormat outputImageFormat, CancellationToken cancellationToken) { var inputArgs = $"-y {inputSource.InputCommand}"; var outputArgs = $"-c:v {outputImageFormat.ToString().ToLower()} -f image2pipe -"; var startInfo = new ProcessStartInfo { FileName = this._ffmpegPath, Arguments = $"{inputArgs} {outputArgs}", UseShellExecute = false, CreateNoWindow = true, RedirectStandardInput = true, RedirectStandardError = true, RedirectStandardOutput = true, }; using (var ffmpegProcess = new Process { StartInfo = startInfo }) { ffmpegProcess.ErrorDataReceived += this.ProcessDataReceived; ffmpegProcess.Start(); ffmpegProcess.BeginErrorReadLine(); using (var frameOutputStream = ffmpegProcess.StandardOutput.BaseStream) { var index = 0; var buffer = new byte[32768]; var imageData = new List <byte>(); byte[] imageHeader = null; while (!cancellationToken.IsCancellationRequested) { var length = await frameOutputStream.ReadAsync(buffer, 0, buffer.Length); if (length == 0) { break; } if (imageHeader == null) { imageHeader = buffer.Take(5).ToArray(); } if (buffer.Take(5).SequenceEqual(imageHeader)) { if (imageData.Count > 0) { this.NewImageReceived?.Invoke(imageData.ToArray()); imageData.Clear(); index++; } } imageData.AddRange(buffer.Take(length)); } frameOutputStream.Close(); } ffmpegProcess.ErrorDataReceived -= this.ProcessDataReceived; ffmpegProcess.WaitForExit(1000); if (!ffmpegProcess.HasExited) { ffmpegProcess.Kill(); } } }