/// <summary> /// Gets the image format. /// </summary> /// <param name="format">The format.</param> /// <returns>An ImageFormat instance which matches the specified OutputFormat</returns> public static ImageFormat GetImageFormat(ImageFormatType format) { switch (format) { case ImageFormatType.Bmp: return(ImageFormat.Bmp); case ImageFormatType.Jpeg: return(ImageFormat.Jpeg); case ImageFormatType.Png: return(ImageFormat.Png); case ImageFormatType.Tiff: return(ImageFormat.Tiff); case ImageFormatType.Gif: return(ImageFormat.Gif); case ImageFormatType.Default: return(ImageFormat.Jpeg); default: return(ImageFormat.Jpeg); } }
/// <summary> /// Finds the best provider. /// </summary> /// <param name="format">The format.</param> public IImageProvider FindBestProvider(ImageFormatType format) { if (ImageProviders.ContainsKey(format)) return ImageProviders[format]; else return ImageProviders[ImageFormatType.Default]; }
public static YuvImage GetYUVImage(ByteBuffer framebuff, ImageFormatType _CameraColorFormat, int _Width, int _Height) { byte[] barray = new byte[framebuff.Remaining()]; framebuff.Get(barray); return(new YuvImage(barray, _CameraColorFormat, _Width, _Height, null)); }
/// <summary> /// Retrieves the signature image from the canvas /// </summary> /// <param name="imgFormat"></param> /// <returns></returns> public Stream GetImage(ImageFormatType imgFormat) { var imageTask = Task.Run(async() => { //Create new Random Access Tream var stream = new InMemoryRandomAccessStream(); //Create bitmap encoder var encoder = await BitmapEncoder.CreateAsync( imgFormat == ImageFormatType.Png ? BitmapEncoder.PngEncoderId : BitmapEncoder.JpegEncoderId, stream); //Set the pixel data and flush it encoder.SetPixelData( BitmapPixelFormat.Bgra8, BitmapAlphaMode.Straight, (uint)bitmapInfo.PixelWidth, (uint)bitmapInfo.PixelHeight, 96d, 96d, bitmapInfo.BitmapBuffer.ToArray()); await encoder.FlushAsync(); return(stream.AsStream()); }); imageTask.Wait(); return(imageTask.Result); }
public ImageGrabbedEventArgs(Bitmap image, object data, ImageFormatType imageFormat) { Image = image; Data = data; ImageFormat = imageFormat; Error = 0; }
private Texture2D(ImageFormatType imageFormat, byte[] imageBytes, uint resourceSetNo, string textureName, string samplerName) { if (null == textureName || null == samplerName) { throw new ArgumentException("Must provide valid texture and sampler name"); } ResourceSetNo = resourceSetNo; TextureName = textureName; SamplerName = samplerName; ImageFormat = imageFormat; ImageBytes = imageBytes; if (null != ImageBytes) { var texProcessor = new ImageSharpProcessor(); using (var stream = new MemoryStream(ImageBytes)) { switch (ImageFormat) { case ImageFormatType.Jpeg: ProcessedTexture = texProcessor.ProcessT(stream, "jpg"); break; case ImageFormatType.Png: ProcessedTexture = texProcessor.ProcessT(stream, "png"); break; default: throw new InvalidEnumArgumentException("Unknown type"); } } } }
public async Task <IEnumerable <Image> > Create( IEnumerable <ImageTransitional> entities, ImageFormatType format) { Guard.WhenArgument( entities, GlobalConstants.ImageTransitionalCollectionRequiredExceptionMessage) .IsNull() .Throw(); ICollection <Image> imageList = new List <Image>(); Image entityDb; foreach (var entity in entities) { Guard.WhenArgument( entity, GlobalConstants.ImageRequiredExceptionMessage) .IsNull() .Throw(); entity.Format = format; entityDb = await this.CreateImage(entity, null, null); this.images.Create(entityDb); imageList.Add(entityDb); } await this.context.SaveAsync(); return(imageList); }
/// <summary> /// Gets the image format. /// </summary> /// <param name="format">The format.</param> /// <returns>An ImageFormat instance which matches the specified OutputFormat</returns> public static ImageFormat GetImageFormat(ImageFormatType format) { switch (format) { case ImageFormatType.Bmp: return ImageFormat.Bmp; case ImageFormatType.Jpeg: return ImageFormat.Jpeg; case ImageFormatType.Png: return ImageFormat.Png; case ImageFormatType.Tiff: return ImageFormat.Tiff; case ImageFormatType.Gif: return ImageFormat.Gif; case ImageFormatType.Default: return ImageFormat.Jpeg; default: return ImageFormat.Jpeg; } }
/// <summary> /// Actual image generator. Internally used. /// </summary> /// <param name="captchaCode">Captcha code for which the image has to be generated</param> /// <param name="imageHeight">Height of the image to be generated</param> /// <param name="imageWidth">Width of the image to be generated</param> /// <param name="fontSize">Font size to be used</param> /// <param name="distortion">Distortion required</param> /// <returns>Generated jpeg image as a MemoryStream object</returns> public static MemoryStream BuildImage(string captchaCode, int imageHeight, int imageWidth, int fontSize, int distortion = 18, ImageFormatType imgType = ImageFormatType.Png) { int newX, newY; MemoryStream memoryStream = new MemoryStream(); using (Bitmap captchaImage = new Bitmap(imageWidth, imageHeight, System.Drawing.Imaging.PixelFormat.Format64bppArgb)) using (Bitmap cache = new Bitmap(imageWidth, imageHeight, System.Drawing.Imaging.PixelFormat.Format64bppArgb)) using (Graphics graphicsTextHolder = Graphics.FromImage(captchaImage)) { graphicsTextHolder.Clear(BackgroundColor); graphicsTextHolder.DrawString(captchaCode, new Font(FONTFAMILY, fontSize, FontStyle.Italic), new SolidBrush(Color.Gray), new PointF(8.4F, 20.4F)); //Distort the image with a wave function for (int y = 0; y < imageHeight; y++) { for (int x = 0; x < imageWidth; x++) { newX = (int)(x + (distortion * Math.Sin(Math.PI * y / 64.0))); newY = (int)(y + (distortion * Math.Cos(Math.PI * x / 64.0))); if (newX < 0 || newX >= imageWidth) { newX = 0; } if (newY < 0 || newY >= imageHeight) { newY = 0; } cache.SetPixel(x, y, captchaImage.GetPixel(newX, newY)); } } System.Drawing.Imaging.ImageFormat imgFormat; switch (imgType) { case ImageFormatType.Bmp: imgFormat = System.Drawing.Imaging.ImageFormat.Bmp; break; case ImageFormatType.Gif: imgFormat = System.Drawing.Imaging.ImageFormat.Gif; break; case ImageFormatType.Jpeg: imgFormat = System.Drawing.Imaging.ImageFormat.Jpeg; break; case ImageFormatType.Png: imgFormat = System.Drawing.Imaging.ImageFormat.Png; break; default: throw new ArgumentException("unkown image type"); } cache.Save(memoryStream, imgFormat); memoryStream.Position = 0; return(memoryStream); } }
// public override void TouchesBegan(NSSet touches, UIEvent evt) { // base.TouchesBegan(touches, evt); // if (this.onResult == null) // this.DismissViewController(true, null); // } private static Stream GetImageStream(UIImage image, ImageFormatType formatType) { if (formatType == ImageFormatType.Jpg) { return(image.AsJPEG().AsStream()); } return(image.AsPNG().AsStream()); }
public static ITexture2D Create( ImageFormatType imageFormat, byte[] imageBytes, uint resourceSetNo, string textureName, string samplerName) { return(new Texture2D(imageFormat, imageBytes, resourceSetNo, textureName, samplerName)); }
/// <summary> /// Writes the specified images to the output stream /// </summary> /// <param name="images">The images.</param> /// <param name="imageStream"></param> /// <param name="outputFormat">The output format.</param> /// <param name="quality">The quality.</param> public void Write(IEnumerable<System.Drawing.Image> images, System.IO.Stream imageStream, ImageFormatType outputFormat, long quality) { if (images.Count() > 0) { OctreeQuantizer quantizer = new OctreeQuantizer(this.ColourDepth - 1, 8); Bitmap quantized = quantizer.Quantize(images.First()); quantized.Save(imageStream, ImageFormat.Gif); } }
/// <summary> /// Finds the best provider. /// </summary> /// <param name="format">The format.</param> public IImageProvider FindBestProvider(ImageFormatType format) { if (ImageProviders.ContainsKey(format)) { return(ImageProviders[format]); } else { return(ImageProviders[ImageFormatType.Default]); } }
public Bitmap GetCharacterImage(string characterName, string expression, ImageFormatType imageFormatType) { string ext = imageFormatType.ToString(); var characterPath = $"{Directory.GetCurrentDirectory()}\\Characters\\{characterName}\\{expression}.{ext}"; if (!File.Exists(characterPath)) { throw new ArgumentException($"{expression} missing for character {characterName}"); } return(new Bitmap($"{characterPath}")); }
private Stream GetImageStream(ImageFormatType imgFormat) { using (var image = this.Control.GetImage()) { var stream = new MemoryStream(); var format = imgFormat == ImageFormatType.Png ? Android.Graphics.Bitmap.CompressFormat.Png : Android.Graphics.Bitmap.CompressFormat.Jpeg; image.Compress(format, 100, stream); // TODO: quality control return(stream); // TODO: careful } }
public Bitmap GetSceneImage(string sceneName, ImageFormatType imageFormatType) { string ext = imageFormatType.ToString(); var sceneFilePath = $"{Directory.GetCurrentDirectory()}\\Scenes\\{sceneName}.{ext}"; if (!File.Exists(sceneFilePath)) { throw new ArgumentException($"{sceneName} is missing"); } return(new Bitmap(sceneFilePath)); }
public Bitmap GetImageAsset(string fileName, ImageFormatType imageFormatType) { string ext = imageFormatType.ToString(); var assetFilePath = $"{Directory.GetCurrentDirectory()}\\Assets\\{fileName}.{ext}"; if (!File.Exists(assetFilePath)) { throw new ArgumentException($"{fileName}.{ext} is not present in the assets folder"); } return(new Bitmap(assetFilePath)); }
/// <summary> /// Writes the specified images to the output stream /// </summary> /// <param name="images">The images.</param> /// <param name="outputStream">The image stream.</param> /// <param name="outputFormat">The output format.</param> /// <param name="quality">The quality.</param> public void Write(IEnumerable<Image> images, Stream outputStream, ImageFormatType outputFormat, long quality) { if (images.Count() > 0) { EncoderParameters codecParams = new EncoderParameters(1); codecParams.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality); ImageCodecInfo codecInfo = Util.FindCodecInfo(Util.GetImageFormat(outputFormat)); images.First().Save(outputStream, codecInfo, codecParams); } }
/// <summary> /// Writes the specified images to the output stream /// </summary> /// <param name="images">The images.</param> /// <param name="outputStream">The image stream.</param> /// <param name="outputFormat">The output format.</param> /// <param name="quality">The quality.</param> public void Write(IEnumerable <Image> images, Stream outputStream, ImageFormatType outputFormat, long quality) { if (images.Count() > 0) { EncoderParameters codecParams = new EncoderParameters(1); codecParams.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality); ImageCodecInfo codecInfo = Util.FindCodecInfo(Util.GetImageFormat(outputFormat)); images.First().Save(outputStream, codecInfo, codecParams); } }
} //SaveImage(string, ImageFormatTypes) /// <summary> /// Saves an encoded image to a specified stream. /// </summary> /// <param name="stream">Stream to write image to.</param> /// <param name="FileType">Format to use.</param> public void SaveImage(Stream stream, ImageFormatType FileType) { try { if (_Encoded_Image != null) { ((Bitmap)_Encoded_Image).Save(stream, getImageFormat(FileType)); } //if } //try catch (System.Exception ex) { throw new System.Exception("ESAVEIMAGE-2: Could not save image.\n\n=======================\n\n" + ex.Message); } //catch } //SaveImage(Stream, ImageFormatTypes)
/// <summary> /// Processes an image using the filters in the filter collection, setting the image /// in an input stream. /// </summary> /// <param name="inputStream">The input stream containing image data.</param> /// <param name="outputStream">The stream to write the resulting image to</param> public void ProcessImage(Stream inputStream, Stream outputStream, ImageFormatType inputImageFormat = ImageFormatType.Default, ImageFormatType outputImageFormat = ImageFormatType.Default) { IImageProvider inputProvider = this.ProviderFactory.FindBestProvider(inputImageFormat); IImageProvider outputProvider = this.ProviderFactory.FindBestProvider(outputImageFormat); IEnumerable <Image> inputImages = inputProvider.Read(inputStream); List <Image> outputImages = new List <Image>(); foreach (var image in inputImages) { outputImages.Add(ProcessImage(image)); } outputProvider.Write(outputImages, outputStream, outputImageFormat, this.JpegCompression); }
public ImageFormat(ImageFormatType imageFormat) { Format = imageFormat; if (Format == ImageFormatType.gif) { Extension = ".gif"; } else if (Format == ImageFormatType.jpg) { Extension = ".jpg"; } else if (Format == ImageFormatType.png) { Extension = ".png"; } }
private ImageFormat getImageFormat(ImageFormatType FileType) { System.Drawing.Imaging.ImageFormat imageformat; switch (FileType) { case ImageFormatType.BMP: imageformat = System.Drawing.Imaging.ImageFormat.Bmp; break; case ImageFormatType.EMF: imageformat = System.Drawing.Imaging.ImageFormat.Emf; break; case ImageFormatType.EXIF: imageformat = System.Drawing.Imaging.ImageFormat.Exif; break; case ImageFormatType.GIF: imageformat = System.Drawing.Imaging.ImageFormat.Gif; break; case ImageFormatType.ICON: imageformat = System.Drawing.Imaging.ImageFormat.Icon; break; case ImageFormatType.JPG: imageformat = System.Drawing.Imaging.ImageFormat.Jpeg; break; case ImageFormatType.PNG: imageformat = System.Drawing.Imaging.ImageFormat.Png; break; case ImageFormatType.TIFF: imageformat = System.Drawing.Imaging.ImageFormat.Tiff; break; case ImageFormatType.WMF: imageformat = System.Drawing.Imaging.ImageFormat.Wmf; break; default: imageformat = System.Drawing.Imaging.ImageFormat.Jpeg; break; } // return(imageformat); }
/// <summary> /// Resizes the image. /// </summary> /// <param name="inputFilename">The input filename.</param> /// <param name="outputFilename">The output filename.</param> /// <param name="width">The desired width of the output image.</param> /// <param name="height">The desired height of the output image.</param> /// <param name="method">The resize calculation method</param> /// <param name="anchorLocation">The anchor location.</param> /// <param name="jpegQuality">The JPEG quality.</param> /// <param name="outputFormat">The output format.</param> public static void ResizeImage(string inputFilename, string outputFilename, int width, int height, ResizeMethod method = ResizeMethod.KeepAspectRatio, AnchorLocation anchorLocation = AnchorLocation.Middle, long jpegQuality = 80L, ImageFormatType outputFormat = ImageFormatType.Default) { ImageProcessor processor = new ImageProcessor(new ResizeFilter(width, height, method, anchorLocation)); ResizeFilter filter = new ResizeFilter(width, height, method, anchorLocation); processor.JpegCompression = jpegQuality; processor.OutputFormat = outputFormat; processor.ProcessImage(inputFilename, outputFilename); }
public async Task <Image> Create(ImageTransitional entity, ImageFormatType format) { Guard.WhenArgument( entity, GlobalConstants.ImageTransitionalRequiredExceptionMessage) .IsNull() .Throw(); entity.Format = format; var entityDb = await this.CreateImage(entity, null, null); this.images.Create(entityDb); await this.context.SaveAsync(); return(entityDb); }
private void PixelBuffertoYUV2(byte[] rgba, int width, int height, ImageFormatType imageFormatType, ref byte[] y, ref byte[] uv) { //in grayscale, it's a byte per pixel, which we can just assign to Y, and leave uv null //Probably not the most accurate conversion, would save some performance if (imageFormatType == ImageFormatType.ImageFormatGrayscale) { y = rgba; uv = null; return; } int pixelCount = width * height; if (y == null || y.Length != pixelCount) { y = new byte[pixelCount]; } if (uv == null || uv.Length != pixelCount / 2) { uv = new byte[pixelCount / 2]; } int iY = 0; int iUV = 0; int iRGBA = 0; for (int row = 0; row < height; row++) { for (int column = 0; column < width; column++) { //Random magic starts here! //Convert every pixel to 1 byte Y y[iY++] = (byte)(((66 * rgba[iRGBA] + 129 * rgba[iRGBA + 1] + 25 * rgba[iRGBA + 2] + 128) >> 8) + 16); //Convert every pixel to 2 bytes UV at quarter resolution if (row % 2 == 0 && column % 2 == 0) { uv[iUV++] = (byte)(((-38 * rgba[iRGBA] - 74 * rgba[iRGBA + 1] + 112 * rgba[iRGBA + 2] + 128) >> 8) + 128); uv[iUV++] = (byte)(((112 * rgba[iRGBA] - 94 * rgba[iRGBA + 1] - 18 * rgba[iRGBA + 2] + 128) >> 8) + 128); } //To next pixel iRGBA += 4; } } }
/// <summary> /// Processes an image using the filters which have been added to the filter collection. /// </summary> /// <param name="inputImage">The real path to the input image.</param> /// <param name="outputImage">The real path to the resulting image after processing.</param> public void ProcessImage(string inputImage, string outputImage) { using (Stream inputStream = new FileStream(inputImage, FileMode.Open)) { using (Stream outputFileStream = new FileStream(outputImage, FileMode.Create)) { ImageFormatType inputFormat = Util.DiscoverOutputFormatFromFile(inputImage); // Try and discover the output format from the extension, if one hasn't already been set. if (OutputFormat == ImageFormatType.Default) { OutputFormat = Util.DiscoverOutputFormatFromFile(outputImage); } ProcessImage(inputStream, outputFileStream, inputFormat, OutputFormat); } } }
public Image CreateImage( string fileName, string fileExtension, string urlPath, ImageFormatType format, Guid?photocourseId, Photocourse photocourse) { return(new Image { FileName = fileName, FileExtension = fileExtension, UrlPath = urlPath, Format = format, PhotocourseId = photocourseId, Photocourse = photocourse }); }
public static void ImageCompress(ImageFormatType format = ImageFormatType.Jpeg, int quality = 50) { var formatTable = new Dictionary <ImageFormatType, ImageFormat>() { { ImageFormatType.Bmp, ImageFormat.Bmp }, { ImageFormatType.Gif, ImageFormat.Gif }, { ImageFormatType.Jpeg, ImageFormat.Jpeg }, { ImageFormatType.Png, ImageFormat.Png }, { ImageFormatType.Tiff, ImageFormat.Tiff }, }; Glb.DrawMatAndHist0(Glb.matSrc); var bmpBufferSize = Glb.matSrc.Step() * Glb.matSrc.Height; var bmp = Glb.matSrc.ToBitmap(); // 인코더 준비 var imageFormat = formatTable[format]; var enc = ImageCodecInfo.GetImageEncoders().FirstOrDefault(codecInfo => codecInfo.FormatID == imageFormat.Guid); var encPrms = new EncoderParameters(1); encPrms.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality); // 메모리 스트림으로 저장 var ms = new MemoryStream(); bmp.Save(ms, enc, encPrms); var compressedBufferSize = ms.Length; // 메모리 스트림에서 로드 var compressedImage = System.Drawing.Image.FromStream(ms); var bmpNew = new System.Drawing.Bitmap(compressedImage); var matDsp = bmpNew.ToMat(); Console.WriteLine("bmp : {0}KB => {1}({2}%) : {3}KB", bmpBufferSize / 1000, imageFormat, quality, compressedBufferSize / 1000); Glb.DrawMatAndHist1(matDsp); Glb.DrawMatAndHist2(null); matDsp.Dispose(); }
}//Generate_Image /// <summary> /// Gets the bytes that represent the image. /// </summary> /// <param name="savetype">File type to put the data in before returning the bytes.</param> /// <returns>Bytes representing the encoded image.</returns> public byte[] GetImageData(ImageFormatType savetype) { byte[] imageData = null; try { if (_Encoded_Image != null) { //Save the image to a memory stream so that we can get a byte array! using (MemoryStream ms = new MemoryStream()) { SaveImage(ms, savetype); imageData = ms.ToArray(); ms.Flush(); ms.Close(); } //using } //if } //try catch (System.Exception ex) { throw new System.Exception("EGETIMAGEDATA-1: Could not retrieve image data. " + ex.Message); }//catch return(imageData); }
public Stream GetImage(ImageFormatType imageFormat) { return this.getImageFunc(imageFormat); }
/// <summary> /// Creates the texture reader instance. /// </summary> /// <param name="format">Format of the output image pixel. Can be either eImageFormat_RGBA /// or eImageFormat_I8.</param> /// <param name="width">Width of the output image, in pixels.</param> /// <param name="height">Height of the output image, in pixels.</param> /// <param name="keepAspectRatio">Indicate whether or not to keep aspect ratio. If true, the /// output image may be cropped if the image aspect ratio is different from the texture /// aspect ratio. If false, the output image covers the entire texture scope and no cropping /// is applied.</param> public void Create(ImageFormatType format, int width, int height, bool keepAspectRatio) { ExternApi.TextureReader_create((int)format, width, height, keepAspectRatio); }
private static Stream GetImageStream(UIImage image, ImageFormatType formatType) { if (formatType == ImageFormatType.Jpg) return image.AsJPEG().AsStream(); return image.AsPNG().AsStream(); }
/// <summary> /// Initializes a new instance of the <see cref="ImageProviderAttribute"/> class. /// </summary> /// <param name="targetFormat">The target format.</param> public ImageProviderAttribute(ImageFormatType targetFormat) { this.TargetFormat = targetFormat; }
/// <summary> /// Writes the specified images to the output stream /// </summary> /// <param name="images">The images.</param> /// <param name="imageStream"></param> /// <param name="outputFormat">The output format.</param> /// <param name="quality">The quality.</param> public void Write(IEnumerable <System.Drawing.Image> images, System.IO.Stream imageStream, ImageFormatType outputFormat, long quality) { if (images.Count() > 0) { OctreeQuantizer quantizer = new OctreeQuantizer(this.ColourDepth - 1, 8); Bitmap quantized = quantizer.Quantize(images.First()); quantized.Save(imageStream, ImageFormat.Gif); } }
/// <summary> /// Retrieves the signature image from the canvas /// </summary> /// <param name="imgFormat"></param> /// <returns></returns> public Stream GetImage(ImageFormatType imgFormat) { var imageTask = Task.Run(async () => { //Create new Random Access Tream var stream = new InMemoryRandomAccessStream(); //Create bitmap encoder var encoder = await BitmapEncoder.CreateAsync( imgFormat == ImageFormatType.Png ? BitmapEncoder.PngEncoderId : BitmapEncoder.JpegEncoderId, stream); //Set the pixel data and flush it encoder.SetPixelData( BitmapPixelFormat.Bgra8, BitmapAlphaMode.Straight, (uint)bitmapInfo.PixelWidth, (uint)bitmapInfo.PixelHeight, 96d, 96d, bitmapInfo.BitmapBuffer.ToArray()); await encoder.FlushAsync(); return stream.AsStream(); }); imageTask.Wait(); return imageTask.Result; }
public Stream GetImage(ImageFormatType imageFormat) { return(this.getImageFunc(imageFormat)); }
/// <summary> /// Processes an image using the filters in the filter collection, setting the image /// in an input stream. /// </summary> /// <param name="inputStream">The input stream containing image data.</param> /// <param name="outputStream">The stream to write the resulting image to</param> public void ProcessImage(Stream inputStream, Stream outputStream, ImageFormatType inputImageFormat = ImageFormatType.Default, ImageFormatType outputImageFormat = ImageFormatType.Default) { IImageProvider inputProvider = this.ProviderFactory.FindBestProvider(inputImageFormat); IImageProvider outputProvider = this.ProviderFactory.FindBestProvider(outputImageFormat); IEnumerable<Image> inputImages = inputProvider.Read(inputStream); List<Image> outputImages = new List<Image>(); foreach (var image in inputImages) { outputImages.Add(ProcessImage(image)); } outputProvider.Write(outputImages, outputStream, outputImageFormat, this.JpegCompression); }