This forum contains outdated content and is available for reading only. Please contact technical support if you have any questions.

ImageReader

I'm looking at the Tint example (specifically the TintUsingLab() method) from the sample code and had a question regarding how the ImageReader works. I'm in a situation where I already have a Bitmap object so I'm wondering if I need to create an ImageReader before I can apply the tint effect or if I can do so directly to the Bitmap object? Any help is greatly appreciated.
You can use an instance of Bitmap (sourceBitmap) instead of ImageReader as a source:

    private static void TintUsingLab(RgbColor color)
    {
        // You can hardcode a = 20, b = 60 for sepia effect
        var labColor = RgbToLabColor(color);
        var a = labColor.A;
        var b = labColor.B;

        using (var lChannel = new Bitmap())
        {
            // Convert to Lab color space and get lightness channel
            //using (var reader = ImageReader.Create("../../../../_Input/Chicago.jpg"))
            using (var labConverter = new ColorConverter(PixelFormat.Format24bppLab))
            using (var splitter = new LabChannelSplitter())
            {
                splitter.L = lChannel;

                //Pipeline.Run(reader + labConverter + splitter);
                Pipeline.Run(sourceBitmap + labConverter + splitter);				
            }

            // Create a and b channels, combine with lightness channel and convert to RGB color space
            using (var combiner = new LabChannelCombiner())
            using (var aChannel = new Bitmap(lChannel.Width, lChannel.Height, PixelFormat.Format8bppGrayscale,
                new GrayscaleColor((byte)(a + 127))))
            using (var bChannel = new Bitmap(lChannel.Width, lChannel.Height, PixelFormat.Format8bppGrayscale,
                new GrayscaleColor((byte)(b + 127))))
            using (var rgbConverter = new ColorConverter(PixelFormat.Format24bppRgb))
            using (var writer = ImageWriter.Create("../../../../_Output/TintUsingLab_" + color.ToString() + ".jpg"))
            {
                combiner.L = lChannel;
                combiner.A = aChannel;
                combiner.B = bChannel;

                rgbConverter.DestinationProfile = ColorProfile.FromSrgb();

                Pipeline.Run(combiner + rgbConverter + writer);
            }
        }
    }

And if I wanted to save the "tinted" image back to the same (sourceBitmap), would I just use the sourceBitmap in place of the ImageWriter? Or is the ImageWriter just used to save the image out to an image file?
Yes, exactly. Alternatively you can create a new bitmap:

 private static void TintUsingLab(RgbColor color)
    {
        // You can hardcode a = 20, b = 60 for sepia effect
        var labColor = RgbToLabColor(color);
        var a = labColor.A;
        var b = labColor.B;

        using (var lChannel = new Bitmap())
        {
            // Convert to Lab color space and get lightness channel
            //using (var reader = ImageReader.Create("../../../../_Input/Chicago.jpg"))
            using (var labConverter = new ColorConverter(PixelFormat.Format24bppLab))
            using (var splitter = new LabChannelSplitter())
            {
                splitter.L = lChannel;

                //Pipeline.Run(reader + labConverter + splitter);
                Pipeline.Run(sourceBitmap + labConverter + splitter);				
            }

            // Create a and b channels, combine with lightness channel and convert to RGB color space
            using (var combiner = new LabChannelCombiner())
            using (var aChannel = new Bitmap(lChannel.Width, lChannel.Height, PixelFormat.Format8bppGrayscale,
                new GrayscaleColor((byte)(a + 127))))
            using (var bChannel = new Bitmap(lChannel.Width, lChannel.Height, PixelFormat.Format8bppGrayscale,
                new GrayscaleColor((byte)(b + 127))))
            using (var rgbConverter = new ColorConverter(PixelFormat.Format24bppRgb))
            //using (var writer = ImageWriter.Create("../../../../_Output/TintUsingLab_" + color.ToString() + ".jpg"))
           using (var resultBitmap = new Bitmap())
            {
                combiner.L = lChannel;
                combiner.A = aChannel;
                combiner.B = bChannel;

                rgbConverter.DestinationProfile = ColorProfile.FromSrgb();

                //Pipeline.Run(combiner + rgbConverter + writer);
                Pipeline.Run(combiner + rgbConverter + resultBitmap);				
            }
        }
    }
Wasn't sure if I should start a new thread but since this has to do with the ImageReader I figured I would continue this one.

If I use the image in the samples folder (Chicago.jpg) this code works perfectly but if I use a picture that I have (just a picture taken from a camera) I am getting an exception whenever I run the Pipeline.Run command with the reader. The exception I'm getting is:

Unhandled Exception: System.ArgumentNullException: Argument is null pointer (LittleCms engine requires source color profile for Lab conversion.).
at Aurigma.GraphicsMill.PipelineElement.RunPipeline()
at Aurigma.GraphicsMill.Pipeline.Run()
at Aurigma.GraphicsMill.Pipeline.Run(Pipeline pipeline)
at TintExample.TintUsingLab(RgbColor color, Bitmap& bmp)
at TintExample.Main(String[] args)

The reason you see the reference to a Bitmap as the parameter for the TintUsingLab method is because I was trying different things to get it to work, such as reading in the image to a Bitmap object and then passing it into the method. But it seems it has something to do with the image that I'm using. Again, if I use the chicago.jpg image it works great but not with one of my own. Any ideas as to why this might be happening?

Thanks
Okay I think I figured this one out. After looking at more documentation, I found that the ColorProfile was not defined on the Bitmap so I just had to define that and everything started working as designed. Just replied here in case anyone else runs into this.
lauren@photoboothsupplyco.com;32466
Okay I think I figured this one out. After looking at more documentation, I found that the ColorProfile was not defined on the Bitmap so I just had to define that and everything started working as designed. Just replied here in case anyone else runs into this.


Yes, you can either assign a color profile to a bitmap (for example the sRGB color profile):

if (bitmap.ColorProfile == null)
	bitmap.ColorProfile = ColorProfile.FromSrgb();


You can specify the default color profile for ColorConverter as well:

using (var labConverter = new ColorConverter(PixelFormat.Format24bppLab) 
	{ DefaultSourceProfile = ColorProfile.FromSrgb() })