.NET TIFF file: RGB to CMYK conversion possible without a third party library?

前端 未结 2 1874
小蘑菇
小蘑菇 2021-01-07 03:22

Following up my previous question: if and how would it be possible to take RGB based TIFF files and convert them over to CMYK with standard .NET (3.5) functionality?

2条回答
  •  余生分开走
    2021-01-07 04:21

    Actually there is a way using the System.Windows.Media.Imaging namespace which only seems to work properly with TIFFs at the moment (which is fine for me):

        Stream imageStream = new
            FileStream(@"C:\temp\mike4.jpg", FileMode.Open, FileAccess.Read, FileShare.Read);
        BitmapSource myBitmapSource = BitmapFrame.Create(imageStream);
        FormatConvertedBitmap newFormatedBitmapSource = new FormatConvertedBitmap();
        newFormatedBitmapSource.BeginInit();
        newFormatedBitmapSource.Source = myBitmapSource;
        newFormatedBitmapSource.DestinationFormat = PixelFormats.Cmyk32;
        newFormatedBitmapSource.EndInit();
    
        BitmapEncoder encoder = new TiffBitmapEncoder();
        encoder.Frames.Add(BitmapFrame.Create(newFormatedBitmapSource));
    
        Stream cmykStream = new FileStream(@"C:\temp\mike4_CMYK.tif",
    
        FileMode.Create, FileAccess.Write, FileShare.Write);
        encoder.Save(cmykStream);
        cmykStream.Close();
    

    See "Converting images from RGB to CMYK", the answer by Calle Mellergardh.

提交回复
热议问题