This project has moved and is read-only. For the latest updates, please go here.

Updated from 4 to 7, have some issues

Feb 23, 2016 at 8:38 PM
I updated from 4 to 7, because my old library was throwing an SEHException that I couldn't navigate around. I was hoping the update had fixed the issue. With the update, I ran into changes in the library code. Below I've outlined the problem areas. Any help would be appreciated.

Font, FillColor, StrokeColor and TextGravity no longer exist in the following. I'm having trouble finding where it was changed in the change logs.
using (MagickImage image = new MagickImage("xc:black", settings))
{
    image.Format = MagickFormat.Png;
    image.Font = "Arial";
    image.FillColor = new MagickColor("gray");
    image.StrokeColor = new MagickColor("red");
    image.BackgroundColor = new MagickColor("black");
    // Center text vertically
    image.TextGravity = Gravity.Center;

    // Build label
    StringBuilder sb = new StringBuilder("label:");
    // If directory name <= 20
    if (dirInfo.Name.Length <= 20)
    {
        sb.Append(dirInfo.Name);
        sb.Append("\n");
    }
    sb.Append("No Images");
    image.Read(sb.ToString());

    image.Write(dirThumbLocation);
}
How do I set the image's Gamma? In the following I used to use image.Gamma()
public static void AdjustColor(MagickImage image, ImageDTO dto)
{
    image.BrightnessContrast(new Percentage(dto.Brightness), new Percentage(dto.Contrast));
    image.Gamma(dto.Gamma);
    image.Evaluate(Channels.Red, EvaluateOperator.Add, dto.Red);
    image.Evaluate(Channels.Green, EvaluateOperator.Add, dto.Green);
    image.Evaluate(Channels.Blue, EvaluateOperator.Add, dto.Blue);
}
I had
PixelCollection pixels = image.GetReadOnlyPixels();
and changed it to
PixelCollection pixels = image.GetPixels();
I hope this works.

Also the name of MagickResourceLimiteErrorException has changed in the following. Is there a new name, or does the library no longer throw it?
try
{
    using (MagickImage image = new MagickImage(file.FullName))
        colors = GetColorsOfImage(image);
}
catch (MagickResourceLimitErrorException)
{
    FileInfo thumbLocation = ImageThumb.ThumbLocation(file, true);
    using (MagickImage image = new MagickImage(thumbLocation.FullName))
        colors = GetColorsOfImage(image);
}
Feb 23, 2016 at 11:31 PM
Edited Feb 23, 2016 at 11:31 PM
I don't undestand what you mean by version 4 and 7 but it looks like you are using the latest version of Magick.NET. I made a lot of changes in version 7.0.0.0101. Below is an answer to all your questions:
  • The Font, FillColor settings are now set with the Settings property of MagickImage.
  • The Gamma method has been renamed to GammaCorrect.
  • GetPixels is indeed the new method that you should use.
  • MagickResourceLimitErrorException was removed by accident and will be included in the next version of Magick.NET.
Feb 24, 2016 at 5:02 AM
Thanks for the updates.

I'd had the following.
<Reference Include="Magick.NET-AnyCPU, Version=6.0.0.0, Culture=neutral, PublicKeyToken=2004825badfa91ec, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>..\..\packages\Magick.NET-Q16-AnyCPU.7.0.0.0004\lib\net40-client\Magick.NET-AnyCPU.dll</HintPath>
    </Reference>
I thought NuGet was saying I had version 4. I must have misread it.
Feb 24, 2016 at 11:57 AM
Edited Feb 24, 2016 at 9:50 PM
For future reference, you can find the log of breaking changes here: https://magick.codeplex.com/SourceControl/latest#Changes.md
Feb 26, 2016 at 6:16 PM
So I changed "The Font, FillColor settings are now set with the Settings property of MagickImage." But the image doesn't look the same anymore. Here's the code as it stands now:
MagickReadSettings settings = new MagickReadSettings();
settings.Width = ThumbSizeDTO.Size.Width;
settings.Height = ThumbSizeDTO.Size.Height;

using (MagickImage image = new MagickImage("xc:black", settings))
{
    image.Format = MagickFormat.Png;
    // If no PointSize set, image will be as wide as can be
    image.Settings.Font = "Arial";
    image.Settings.FillColor = new MagickColor("gray");
    image.Settings.StrokeColor = new MagickColor("red");
    image.BackgroundColor = new MagickColor("black");
    // Center text vertically
    image.Settings.TextGravity = Gravity.Center;

    // Build label
    StringBuilder sb = new StringBuilder("label:");
    // If directory name <= 20
    if (dirInfo.Name.Length <= 20)
    {
        sb.Append(dirInfo.Name);
        sb.Append("\n");
    }
    sb.Append("No Images");
    image.Read(sb.ToString());

    image.Write(dirThumbLocation);
}
It used to display an image like this:
Image
Now they look like this:
Image

Ignore the size difference, I probably changed the thumb size between when the two images were made. Notice, the text used to be on a black background and centered.

By changing BackColor to be
image.Settings.BackgroundColor = new MagickColor("black");
Image
I did get the background to be black, but the Gravity setting is still being ignored. Of note, you can still set the BackgroundColor to black without the Settings property of the image, it has no effect anymore at least for text.
Feb 27, 2016 at 5:58 PM
Edited Feb 27, 2016 at 5:58 PM
The TextGravity is not set correct because I missed a call when you set that setting. This will be fixed in the next release of Magick.NET and I also added a unit test to make sure it stays fixed.