GDI+ output directly to CMYK JPG?

Posted on 2012-08-30
Last Modified: 2012-09-11
I have an ASP.NET application using GDI+ to create a Bitmap to be displayed on the client's browser (as a JPG in an Image), and can also be downloaded as a JPG.

My problem is that the image will need to be printed, and a lot of commercial printers will only accept JPGs with colors specified in CMYK, not RGB.

I have looked at using a tool like ImageMagick to convert the RGB JPG to CMYK JPG after the former has been created... but this takes more time than the creation of the image to begin with (performance is an issue).

Is there anyway to output a CMYK JPG file directly from GDI+ ? I've been looking around the web, but have failed to find an answer.

Question by:futuremoose
    LVL 83

    Accepted Solution


    Author Comment

    Ok... sorry to take so long getting back to this thread, but I only now finally got a chance to try out the suggestions above. The first link led to some code that claimed to work, but I could not get it to work... however, it led me eventually to another example posted here

    which I did get to work (code is just below). The output file's metadata confirms that the PhotometricInterpretation is "CMYK". Colors may be kind of messed up, but now I'll look for a way to apply a Color Profile (ICM or ICC) file. If I have trouble, I'll open another thread.

    Anyhow, thanks CodeCruiser... I'll mark your comment as solution.

    Imports System.Windows.Freezable
    Imports System.Windows.Media
    Imports System.Windows.Media.Imaging
    Imports System.IO
    Public Class Form1
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            ' this example from:
            ' this one does work... kind of. Colors seem messed up, and file size also much larger (as expected).
            Dim imageStream As Stream = New FileStream("c:\temp\a.jpg", FileMode.Open, FileAccess.Read, FileShare.Read)
            Dim myBitmapSource As BitmapSource = BitmapFrame.Create(imageStream)
            Dim newFormatedBitmapSource As FormatConvertedBitmap = New FormatConvertedBitmap()
            newFormatedBitmapSource.Source = myBitmapSource
            newFormatedBitmapSource.DestinationFormat = PixelFormats.Cmyk32
            Dim encoder As BitmapEncoder = New TiffBitmapEncoder()
            Dim cmykStream As Stream = New FileStream("C:\temp\a_CMYK.tif", FileMode.Create, FileAccess.Write, FileShare.Write)
        End Sub
    End Class

    Open in new window


    Author Closing Comment

    Example pointed to did not actually work, but it led to one that did, which is good enough for me.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now