Code Monkey home page Code Monkey logo

Comments (3)

koszeggy avatar koszeggy commented on June 17, 2024

Thank you for the report. I'm aware about the issue and I plan to extend the new KnownPixelFormat enum (so far available as a preview in KGySoft.Drawing.Core, which is the new package of the platform and technology-independent APIs) with a new Format32bppCmyk field so CMYK format will be natively supported.

As I already implemented CMYK format for WPF (also in preview so far) it will not be a big deal even for the Core package.

However, GDI+ Bitmap is a bit different. Its CMYK support is actually quite a hack: it uses an unnamed System.Drawing.Imaging.PixelFormat value (8207) and is not supported on all platforms. Actually you can open the posted image even in my ImagingTools: in Windows Vista or above you will see 8207 as the displayed pixel format. Windows XP behaves differently though: CMYK JPEG images are loaded with Format24bppRgb pixel format, and CMYK TIFF images with Format32bppArgb format (if the source image uses 8 bits for each channel).

What you can expect from me:
I was already planning to add CMYK support also to KGySoft.Drawing (starting with 7.0.0 this contains only the GDI+ specific APIs) but maybe only as source format. Meaning, ImageExtensions.ConvertPixelFormat will support it as source format but (probably) not as a target format.

What you can do today:
If you need to use CMYK source images you can try the following workarounds today:

  • Use WPF's WriteableBitmap to load the source image, and then access it by WriteableBitmapExtensions.GetReadWriteBitmapData, where I already implemented CMYK support (requires the KGySoft.Drawing.Wpf package). Then you can use the Clone extension methods that have a pixelFormat parameter, which are essentially the same as the ConvertPixelFormat methods for GDI+ images. The converted IReadWriteBitmapData can be converted to a GDI+ Bitmap by the ToBitmap extension method.
  • Even the last stable release allows you to use custom pixel formats. For a native GDI+ Bitmap you can use the LockBits method, and then the buffer is exposed by the BitmapData.Scan0 property as you can see here (the solution should be something similar to the WPF version linked above). This way you will have an IReadWriteBitmapData so the rest is the same as in the previous point with cloning, etc.
  • Save your CMYK images in TIFF format using 16 bits-per-channel. Such a Bitmap is loaded with Format48bppRgb pixel format by the TIFF decoder (at least in Windows Vista and above) so you can use ConvertPixelFormat as expected.

from kgysoft.drawing.

davidei1955 avatar davidei1955 commented on June 17, 2024

Thanks for the quick response! My current usage requirement is only as a source input to ConvertPixelFormat(), so 'source only' is fine.
My workaround is to convert the cmyk image to rgb thusly:
public static Bitmap AsRgb(this Bitmap img) { if (((int) img.PixelFormat) != 8207) { //8207 == PixelFormat.Cmyk32 return img; } try { return img.To24bppRgb(); } finally { img.Dispose(); } }

from kgysoft.drawing.

koszeggy avatar koszeggy commented on June 17, 2024

The CMYK support of Bitmap (only as input format) has been released in 7.0.0-preview.2 (see the change log)

from kgysoft.drawing.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.