private static ISupportedImageFormat GetFormatFromSelectedOutput(ImageFormat convertTo) { ISupportedImageFormat format = null; switch (convertTo.ToString()) { case "Jpeg": format = new JpegFormat { }; break; case "Png": format = new PngFormat { }; break; case "Tiff": format = new TiffFormat { }; break; default: break; } return(format); }
public void FormatProperties_AreAsExpected() { TiffFormat tiffFormat = TiffFormat.Instance; Assert.Equal("TIFF", tiffFormat.Name); Assert.Equal("image/tiff", tiffFormat.DefaultMimeType); Assert.Contains("image/tiff", tiffFormat.MimeTypes); Assert.Contains("tif", tiffFormat.FileExtensions); Assert.Contains("tiff", tiffFormat.FileExtensions); }
public void GetTiff() { var expected = new TiffFormat(); var i = new Imaging(); foreach (var extension in expected.FileExtensions) { var format = i.Get(extension); Assert.AreEqual(expected.GetType(), format.GetType()); } }
public void ChangeFormat(MimeType type) { ISupportedImageFormat format; switch (type.Title) { case "image/bmp": format = new BitmapFormat(); break; case "image/jpeg": format = new JpegFormat(); break; case "image/png": format = new PngFormat(); break; case "image/tiff": format = new TiffFormat(); break; case "image/gif": format = new GifFormat(); break; default: throw new ArgumentException("Image format is not supported."); } this.FileName = Path.ChangeExtension(this.FileName, type.Extension); ChangeFormat(format); }
public ImagePreviewResponse Preview(string imageId, string containerName, string imageFormat, int brightness, int contrast, int saturation, int sharpness, bool sepia, bool polaroid, bool greyscale) { var response = new ImagePreviewResponse(); //Create the id for the enhanced "preview" version of the source image string enhancedImageId = Guid.NewGuid().ToString(); var outputFormatString = string.Empty; ISupportedImageFormat outputFormatProcessorProperty = null; System.Drawing.Imaging.ImageFormat outputFormatSystemrawingFormat = null; #region Select image format, or send error switch (imageFormat) { case "jpg": outputFormatString = ".jpg"; outputFormatProcessorProperty = new JpegFormat { Quality = 90 }; outputFormatSystemrawingFormat = System.Drawing.Imaging.ImageFormat.Jpeg; break; case "gif": outputFormatString = ".gif"; outputFormatProcessorProperty = new GifFormat { }; outputFormatSystemrawingFormat = System.Drawing.Imaging.ImageFormat.Gif; break; case "png": outputFormatString = ".png"; outputFormatProcessorProperty = new PngFormat { }; outputFormatSystemrawingFormat = System.Drawing.Imaging.ImageFormat.Png; break; case "bmp": outputFormatString = ".bmp"; outputFormatProcessorProperty = new BitmapFormat { }; outputFormatSystemrawingFormat = System.Drawing.Imaging.ImageFormat.Bmp; break; case "tiff": outputFormatString = ".tiff"; outputFormatProcessorProperty = new TiffFormat { }; outputFormatSystemrawingFormat = System.Drawing.Imaging.ImageFormat.Tiff; break; default: return(new ImagePreviewResponse { isSuccess = false, ErrorMessage = "Please please use a supported file format: jpg, png, gif, bmp or tiff." }); } #endregion #region verify all input parameters, or send error if ( brightness < -100 || brightness > 100 || sharpness < -100 || sharpness > 100 || contrast < -100 || contrast > 100 || saturation < -100 || saturation > 100 ) { return(new ImagePreviewResponse { isSuccess = false, ErrorMessage = "Please pass in a value between -100 and 100 for all enhancement parameters" }); } #endregion //Build out response object response.ImageID = enhancedImageId; response.FileName = enhancedImageId + outputFormatString; response.SourceFile = imageId + outputFormatString; #region Connect to Intermediary Storage // Credentials are from centralized CoreServiceSettings StorageCredentials storageCredentials = new StorageCredentials(CoreServices.PlatformSettings.Storage.IntermediaryName, CoreServices.PlatformSettings.Storage.IntermediaryKey); var storageAccount = new CloudStorageAccount(storageCredentials, false); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); #endregion try { //Pull down the source image as MemoryStream from Blob storage and apply image enhancement properties using (MemoryStream sourceStream = Common.GetAssetFromIntermediaryStorage(response.SourceFile, containerName, blobClient)) { #region Image Processor & Storage using (MemoryStream outStream = new MemoryStream()) { using (ImageFactory imageFactory = new ImageFactory()) { // Load, resize, set the format and quality and save an image. // Applies all in order... sourceStream.Position = 0; imageFactory.Load(sourceStream); if (brightness != 0) { imageFactory.Brightness(brightness); } if (contrast != 0) { imageFactory.Contrast(contrast); } if (saturation != 0) { imageFactory.Saturation(saturation); } //Sharpness if (sharpness != 0) { imageFactory.GaussianSharpen(sharpness); } //Filters if (sepia == true) { imageFactory.Filter(MatrixFilters.Sepia); } if (polaroid == true) { imageFactory.Filter(MatrixFilters.Polaroid); } if (greyscale == true) { imageFactory.Filter(MatrixFilters.GreyScale); } imageFactory.Save(outStream); } //Store each image size to BLOB STORAGE --------------------------------- #region BLOB STORAGE //Creat/Connect to the Blob Container //blobClient.GetContainerReference(containerName).CreateIfNotExists(BlobContainerPublicAccessType.Blob); //<-- Create and make public CloudBlobContainer blobContainer = blobClient.GetContainerReference(containerName); //Get reference to the picture blob or create if not exists. CloudBlockBlob blockBlob = blobContainer.GetBlockBlobReference(response.FileName); //Save to storage //Convert final BMP to byteArray Byte[] finalByteArray; finalByteArray = outStream.ToArray(); //Store the enhanced "preview" into the same container as the soure blockBlob.UploadFromByteArray(finalByteArray, 0, finalByteArray.Length); #endregion } #endregion } } catch (Exception e) { return(new ImagePreviewResponse { isSuccess = false, ErrorMessage = e.Message }); } //Marke as successful and return the new ImageID and FileName back to the client for previewing: response.isSuccess = true; return(response); }
/// <summary> /// Gets IPTC metadata from Tiff file /// </summary> public static void ReadIPTCMetadata() { try { //ExStart:GetIPTCMetadataInTiff // initialize TiffFormat TiffFormat tiffFormat = new TiffFormat(Common.MapSourceFilePath(filePath)); // check if TIFF contains IPTC metadata if (tiffFormat.HasIptc) { // get iptc collection IptcCollection iptc = tiffFormat.GetIptc(); // and display it foreach (IptcProperty iptcProperty in iptc) { Console.Write("Tag id: {0}, name: {1}", iptcProperty.TagId, iptcProperty.Name); } } //ExEnd:GetIPTCMetadataInTiff } catch (Exception exp) { Console.WriteLine(exp.Message); } }
/// <summary> ///Reads File Directory Tags from Tiff file /// </summary> public static void ReadTiffFileDirectoryTags() { //ExStart:ReadTiffFileDirectoryTags // initialize TiffFormat TiffFormat tiffFormat = new TiffFormat(Common.MapSourceFilePath(filePath)); // get IFD TiffIfd[] directories = tiffFormat.ImageFileDirectories; if (directories.Length > 0) { // get tags of the first IFD TiffTag[] tags = tiffFormat.GetTags(directories[0]); // write tags to the console foreach (TiffTag tiffTag in tags) { Console.WriteLine("tag: {0}", tiffTag.DefinedTag); switch (tiffTag.TagType) { case TiffTagType.Ascii: TiffAsciiTag asciiTag = tiffTag as TiffAsciiTag; Console.WriteLine("Value: {0}", asciiTag.Value); break; case TiffTagType.Short: TiffShortTag shortTag = tiffTag as TiffShortTag; Console.WriteLine("Value: {0}", shortTag.Value); break; default: break; } } } //ExEnd:ReadTiffFileDirectoryTags }
/// <summary> ///Gets XMP properties from Tiff file /// </summary> public static void GetXMPProperties() { try { //ExStart:GetXMPPropertiesTiffImage // initialize TiffFormat TiffFormat tiff = new TiffFormat(Common.MapSourceFilePath(filePath)); // get xmp XmpPacketWrapper xmpPacket = tiff.GetXmpData(); if (xmpPacket != null) { // show XMP data XmpProperties xmpProperties = tiff.GetXmpProperties(); // show XMP data foreach (string key in xmpProperties.Keys) { try { XmpNodeView xmpNodeView = xmpProperties[key]; Console.WriteLine("[{0}] = {1}", xmpNodeView.Name, xmpNodeView.Value); } catch { } } } else { Console.WriteLine("No XMP data found."); } //ExEnd:GetXMPPropertiesTiffImage } catch (Exception exp) { Console.WriteLine(exp.Message); } }
/// <summary> /// Removes Exif info from Tiff image /// </summary> public static void RemoveExifInfo() { try { //ExStart:RemoveExifPropertiesTiffImage // initialize TiffFormat TiffFormat tiffFormat = new TiffFormat(Common.MapSourceFilePath(filePath)); // remove Exif info tiffFormat.RemoveExifInfo(); // commit changes and save output file tiffFormat.Save(Common.MapDestinationFilePath(filePath)); //ExEnd:RemoveExifPropertiesTiffImage } catch (Exception exp) { Console.WriteLine(exp.Message); } }
/// <summary> /// Updates Exif info using properties and creates output file /// </summary> public static void UpdateExifInfoUsingProperties() { try { //ExStart:UpdateExifValuesUsingPropertiesTiffImage // initialize TiffFormat TiffFormat tiffFormat = new TiffFormat(Common.MapSourceFilePath(filePath)); tiffFormat.ExifValues.CameraOwnerName = "camera owner's name"; // set user comment tiffFormat.ExifValues.UserComment = "user's comment"; // commit changes tiffFormat.Save(Common.MapDestinationFilePath(filePath)); //ExEnd:UpdateExifValuesUsingPropertiesTiffImage Console.WriteLine("File saved in destination folder."); } catch (Exception exp) { Console.WriteLine(exp.Message); } }
/// <summary> /// Updates Exif info of Tiff file and creates output file /// </summary> public static void UpdateExifInfo() { try { //ExStart:UpdateExifPropertiesTiffImage // initialize TiffFormat TiffFormat tiffFormat = new TiffFormat(Common.MapSourceFilePath(filePath)); // get EXIF data ExifInfo exif = tiffFormat.GetExifInfo(); exif.UserComment = "New User Comment"; exif.BodySerialNumber = "New Body Serial Number"; exif.CameraOwnerName = "New Camera Owner Name"; // update EXIF info tiffFormat.UpdateExifInfo(exif); // commit changes and save output file tiffFormat.Save(Common.MapDestinationFilePath(filePath)); //ExEnd:UpdateExifPropertiesTiffImage } catch (Exception exp) { Console.WriteLine(exp.Message); } }
//ExEnd:SourceTiffFilePath /// <summary> /// Gets Exif info from Tiff file /// </summary> public static void GetExifInfo() { try { //ExStart:GetExifPropertiesTiffImage // initialize TiffFormat TiffFormat tiffFormat = new TiffFormat(Common.MapSourceFilePath(filePath)); // get EXIF data ExifInfo exif = tiffFormat.GetExifInfo(); if (exif != null) { // get BodySerialNumber Console.WriteLine("Body Serial Number: {0}", exif.BodySerialNumber); // get CameraOwnerName Console.WriteLine("Camera Owner Name: {0}", exif.CameraOwnerName); // get CFAPattern Console.WriteLine("CFA Pattern: {0}", exif.CFAPattern); // get GPSData Console.WriteLine("GPS Data: {0}", exif.GPSData); // get UserComment Console.WriteLine("User Comment: {0}", exif.UserComment); } //ExEnd:GetExifPropertiesTiffImage } catch (Exception exp) { Console.WriteLine(exp.Message); } }