public static void DefinesThatNeedToBeSetBeforeReadingAnImage()
    {
      MagickReadSettings settings = new MagickReadSettings();
      // Set define that tells the jpeg coder that the output image will be 32x32
      settings.SetDefine(MagickFormat.Jpeg, "size", "32x32");

      // Read image from file
      using (MagickImage image = new MagickImage(SampleFiles.SnakewareJpg))
      {
        // Create thumnail that is 32 pixels wide and 32 pixels high
        image.Thumbnail(32, 32);
        // Save image as tiff
        image.Write(SampleFiles.OutputDirectory + "Snakeware.tiff");
      }
    }
Example #2
0
        private MagickReadSettings CreateMagickReadSettings(XmlElement element)
        {
            if (element == null)
            {
                return(null);
            }
            MagickReadSettings result = new MagickReadSettings();

            result.ColorSpace    = Variables.GetValue <Nullable <ColorSpace> >(element, "colorSpace");
            result.Defines       = CreateIReadDefines(element["defines"]);
            result.Density       = Variables.GetValue <Nullable <PointD> >(element, "density");
            result.Format        = Variables.GetValue <Nullable <MagickFormat> >(element, "format");
            result.FrameCount    = Variables.GetValue <Nullable <Int32> >(element, "frameCount");
            result.FrameIndex    = Variables.GetValue <Nullable <Int32> >(element, "frameIndex");
            result.Height        = Variables.GetValue <Nullable <Int32> >(element, "height");
            result.PixelStorage  = CreatePixelStorageSettings(element["pixelStorage"]);
            result.UseMonochrome = Variables.GetValue <Nullable <Boolean> >(element, "useMonochrome");
            result.Width         = Variables.GetValue <Nullable <Int32> >(element, "width");
            XmlElement setDefine = (XmlElement)element.SelectSingleNode("setDefine");

            if (setDefine != null)
            {
                MagickFormat format_ = XmlHelper.GetAttribute <MagickFormat>(setDefine, "format");
                String       name_   = XmlHelper.GetAttribute <String>(setDefine, "name");
                String       value_  = XmlHelper.GetAttribute <String>(setDefine, "value");
                result.SetDefine(format_, name_, value_);
            }
            return(result);
        }
 private MagickReadSettings CreateMagickReadSettings(XmlElement element)
 {
   if (element == null)
     return null;
   MagickReadSettings result = new MagickReadSettings();
   result.ColorSpace = Variables.GetValue<Nullable<ColorSpace>>(element, "colorSpace");
   result.Defines = CreateIReadDefines(element["defines"]);
   result.Density = Variables.GetValue<Nullable<PointD>>(element, "density");
   result.Format = Variables.GetValue<Nullable<MagickFormat>>(element, "format");
   result.FrameCount = Variables.GetValue<Nullable<Int32>>(element, "frameCount");
   result.FrameIndex = Variables.GetValue<Nullable<Int32>>(element, "frameIndex");
   result.Height = Variables.GetValue<Nullable<Int32>>(element, "height");
   result.PixelStorage = CreatePixelStorageSettings(element["pixelStorage"]);
   result.UseMonochrome = Variables.GetValue<Nullable<Boolean>>(element, "useMonochrome");
   result.Width = Variables.GetValue<Nullable<Int32>>(element, "width");
   XmlElement setDefine = (XmlElement)element.SelectSingleNode("setDefine");
   if (setDefine != null)
   {
     MagickFormat format_ = XmlHelper.GetAttribute<MagickFormat>(setDefine, "format");
     String name_ = XmlHelper.GetAttribute<String>(setDefine, "name");
     String value_ = XmlHelper.GetAttribute<String>(setDefine, "value");
     result.SetDefine(format_,name_,value_);
   }
   return result;
 }
Example #4
0
        private void ExecuteSetDefine(XmlElement element, MagickReadSettings readSettings)
        {
            Hashtable arguments = new Hashtable();

            foreach (XmlAttribute attribute in element.Attributes)
            {
                if (attribute.Name == "flag")
                {
                    arguments["flag"] = GetValue <Boolean>(attribute);
                }
                else if (attribute.Name == "format")
                {
                    arguments["format"] = GetValue <MagickFormat>(attribute);
                }
                else if (attribute.Name == "name")
                {
                    arguments["name"] = GetValue <String>(attribute);
                }
                else if (attribute.Name == "value")
                {
                    arguments["value"] = GetValue <String>(attribute);
                }
            }
            if (OnlyContains(arguments, "format", "name", "flag"))
            {
                readSettings.SetDefine((MagickFormat)arguments["format"], (String)arguments["name"], (Boolean)arguments["flag"]);
            }
            else if (OnlyContains(arguments, "format", "name", "value"))
            {
                readSettings.SetDefine((MagickFormat)arguments["format"], (String)arguments["name"], (String)arguments["value"]);
            }
            else if (OnlyContains(arguments, "name", "value"))
            {
                readSettings.SetDefine((String)arguments["name"], (String)arguments["value"]);
            }
            else
            {
                throw new ArgumentException("Invalid argument combination for 'setDefine', allowed combinations are: [format, name, flag] [format, name, value] [name, value]");
            }
        }
 private void ExecuteSetDefine(XmlElement element, MagickReadSettings readSettings)
 {
   Hashtable arguments = new Hashtable();
   foreach (XmlAttribute attribute in element.Attributes)
   {
     if (attribute.Name == "flag")
       arguments["flag"] = Variables.GetValue<Boolean>(attribute);
     else if (attribute.Name == "format")
       arguments["format"] = Variables.GetValue<MagickFormat>(attribute);
     else if (attribute.Name == "name")
       arguments["name"] = Variables.GetValue<String>(attribute);
     else if (attribute.Name == "value")
       arguments["value"] = Variables.GetValue<String>(attribute);
   }
   if (OnlyContains(arguments, "format", "name", "flag"))
     readSettings.SetDefine((MagickFormat)arguments["format"], (String)arguments["name"], (Boolean)arguments["flag"]);
   else if (OnlyContains(arguments, "format", "name", "value"))
     readSettings.SetDefine((MagickFormat)arguments["format"], (String)arguments["name"], (String)arguments["value"]);
   else if (OnlyContains(arguments, "name", "value"))
     readSettings.SetDefine((String)arguments["name"], (String)arguments["value"]);
   else
     throw new ArgumentException("Invalid argument combination for 'setDefine', allowed combinations are: [format, name, flag] [format, name, value] [name, value]");
 }