color space?
- Hi all,
does anyone have any experience with WPF and color spaces? (i.e. Adobe 1998)
I'm finding that images loaded into my app keep their color space fine (in this case, adobe 1998), but i'm rendering a bitmap from on the fly compositions (some layered canvases) using RenderTargetBitmap. I encode to Tiff and save to harddrive and find the colors have changed dramatically.
Not sure how to keep the adobe 1998 colorspace/ assign a colorspace /or even possibly assign and difference colorspace than the original.
can't seem to find anything in the sdk docs or the forums...
thoughts?
thanks,
steve
Answers
- ahemm... oops... typo
encoder.Frames.Add(BitmapFrame.Create(ccb));
actually, this seems to work... no embedded profile (when opening in photoshop), but the colors ARE correct to Adobe1998 color profile. So, no assigning of profile but actual color conversion.
might be interesting to be able to assign a color profile, instead of just converting colors.
All Replies
- When you save the RenderTargetBitmap, do you add a color space to the encoder? Can you share the code that you're using here?
- sadly, i don't know how one goes about adding a colorspace to the encoder. Of course, i'm choosing a PixelFormat when instantiating the the RenderTargetBitmap, this isn't the same thing as far as i know.
The code used is almost verbatum from the RenderTargetBitmap sdk docs so i won't repeat here.
I suppose the issue is how to 'use' a colorspace altogether? Would one use a ColorConvertedBitmap class somehow? etc.. etc...
i originally thought one could use ColorContext in some way to 'set' a color space. but i haven't been able to do anything useful so far.
-steve - okay, i thought i'd show a bit of code ( i realize the sdk docs don't have a detailed rendertargetbitmap version)...
this code was an example of trying to find something that works!static class Utility
{
public static void SaveImage(Window1 owner)
{
FileStream stream = new FileStream(@"c:\TEMP\new.tif", FileMode.Create);
TiffBitmapEncoder encoder = new TiffBitmapEncoder();
encoder.Compression = TiffCompressOption.Lzw;
ColorContext cc = new ColorContext(new Uri(@"c:\TEMP\AdobeRGB1998.icc"));
/////// can't seem to use anything but Pbgra32 with Rendertargetbitmap
RenderTargetBitmap rtb = new RenderTargetBitmap((int)owner.maincanvas.ActualWidth, (int)owner.maincanvas.ActualHeight, 96, 96, PixelFormats.Pbgra32);
foreach (Layer L in owner.layers) // observable collection of Layer structs
{
rtb.Render(L.fe); // layer struct with fe as FrameworkElement
ColorConvertedBitmap ccb = new ColorConvertedBitmap(rtb, new ColorContext(PixelFormats.Pbgra32), cc, PixelFormats.Bgr32);
encoder.Frames.Add(BitmapFrame.Create(rtb));
}
encoder.Save(stream);
stream.Close();
}
} - ahemm... oops... typo
encoder.Frames.Add(BitmapFrame.Create(ccb));
actually, this seems to work... no embedded profile (when opening in photoshop), but the colors ARE correct to Adobe1998 color profile. So, no assigning of profile but actual color conversion.
might be interesting to be able to assign a color profile, instead of just converting colors. FYI, in order to reference a ColorContext when saving a file, try this:
static class Utility
{
public static void SaveImage(Window1 owner)
{
FileStream stream = new FileStream(@"c:\TEMP\new.tif", FileMode.Create);
TiffBitmapEncoder encoder = new TiffBitmapEncoder();
encoder.Compression = TiffCompressOption.Lzw;
ColorContext cc = new ColorContext(new Uri(@"c:\TEMP\AdobeRGB1998.icc"));List<ColorContext> colorContexts = new List<ColorContext>();
colorContexts.Add(cc);
RenderTargetBitmap rtb = new RenderTargetBitmap((int)owner.maincanvas.ActualWidth, (int)owner.maincanvas.ActualHeight, 96, 96, PixelFormats.Pbgra32);
foreach (Layer L in owner.layers) // observable collection of Layer structs
{
rtb.Render(L.fe); // layer struct with fe as FrameworkElement
encoder.Frames.Add(BitmapFrame.Create(rtb));encoder.ColorContexts = new ReadOnlyCollection(colorContexts);
}
encoder.Save(stream);
stream.Close();
}
}

