dlemstra / Magick.NET

The .NET library for ImageMagick
Apache License 2.0
3.47k stars 416 forks source link

MagickFactory.Image.Create() no longer accepts bitmap #1491

Open DSPaul opened 10 months ago

DSPaul commented 10 months ago

Magick.NET version

Magick.NET.SystemDrawing 7.2.1

Environment (Operating system, version and so on)

Windows WPF .NET 7

Description

After updating Magick.NET.SystemDrawing from 7.2.0 to 7.2.1, the Create() method of the MagicFactory() no longer works with a bitmap.

When called with a single argument, it used to invoke this overload but after the update, it gives an error that it expects a byte[] as argument, referring to this overload instead.

Steps to Reproduce

This the minimal code snippet of my situation that results in the problem. It simply converts a bitmap to a MagickImage.

Bitmap bitmap = ...
var mf = new MagickFactory();
MagickImage img = (MagickImage)mf.Image.Create(bitmap);

If you need more context or want to look at the real code, you can find that here.

dlemstra commented 10 months ago

I suspect something else is happening. That method is still available and there is also a unit test for that method here: https://github.com/dlemstra/Magick.NET/blob/999f4779c1bd632923d3d100e7737353d0818bfa/tests/Magick.NET.SystemDrawing.Tests/IMagickImageFactoryExtensionsTests/TheCreateMethod.cs.

p.s. Why are you typecasting the interface to MagickImage?

DSPaul commented 8 months ago

Small update on the issue, sorry for the long wait.

I was having a look at upgrading my codebase from .NET 7 to .NET 8 and in .NET 8, it does compile just fine with the newest version of Magick.NET.SystemDrawing. Which explains why your unit test for that function that you mentioned still works as that test project was also upgraded to .NET 8 in the update. But it does not compile in .NET 7 so it seems to be a backwards compatibility issue with .NET 8 rather than a bug in Magick.NET.

I honestly don't know if there is anything you can do to solve this but I wanted to keep you updated just in case.

ps. the typecasting is indeed redundant, I wasn't really used to working with interfaces yet when I wrote that code, I have changed it since. But its not all that relevant for this issue.

dlemstra commented 7 months ago

That is not related to this issue and please don't open an issue but create a discussion because this is a problem in your project.