Rank: Member
Groups: Guest
Joined: 7/30/2017(UTC) Posts: 18
Thanks: 7 times
|
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.
|
|
|
|
Rank: Advanced Member
Groups: Guest
Joined: 7/28/2003(UTC) Posts: 1,660
Thanks: 5 times Was thanked: 76 time(s) in 74 post(s)
|
You can use an instance of Bitmap (sourceBitmap) instead of ImageReader as a source: Code: 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);
}
}
}
|
Best regards, Fedor Skvortsov
|
1 user thanked Fedor for this useful post.
|
|
|
Rank: Member
Groups: Guest
Joined: 7/30/2017(UTC) Posts: 18
Thanks: 7 times
|
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?
|
|
|
|
Rank: Advanced Member
Groups: Guest
Joined: 7/28/2003(UTC) Posts: 1,660
Thanks: 5 times Was thanked: 76 time(s) in 74 post(s)
|
Yes, exactly. Alternatively you can create a new bitmap: Code: 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);
}
}
}
|
Best regards, Fedor Skvortsov
|
|
|
|
Rank: Member
Groups: Guest
Joined: 7/30/2017(UTC) Posts: 18
Thanks: 7 times
|
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 Edited by user Monday, October 23, 2017 1:01:59 PM(UTC)
| Reason: Not specified
|
|
|
|
Rank: Member
Groups: Guest
Joined: 7/30/2017(UTC) Posts: 18
Thanks: 7 times
|
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.
|
|
|
|
Rank: Advanced Member
Groups: Guest
Joined: 7/28/2003(UTC) Posts: 1,660
Thanks: 5 times Was thanked: 76 time(s) in 74 post(s)
|
Originally Posted by: lauren@photoboothsupplyco.com 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): Code:if (bitmap.ColorProfile == null)
bitmap.ColorProfile = ColorProfile.FromSrgb();
You can specify the default color profile for ColorConverter as well: Code:using (var labConverter = new ColorConverter(PixelFormat.Format24bppLab)
{ DefaultSourceProfile = ColorProfile.FromSrgb() })
|
Best regards, Fedor Skvortsov
|
|
|
|
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.