Rank: Newbie
Groups: Guest
Joined: 5/6/2012(UTC) Posts: 5
Thanks: 1 times
|
Is it possible to have a greyscaling-function that greyscales all types of images regardless of format ( I guess pdf won't work ). And in addition preserve any transparancy for images that contain this information. It is also important to preserve metainfo/keywords in the image (if present). I tried your sample-code: Code: using (var reader = ImageReader.Create("../../../../_Input/Copenhagen_RGB.jpg"))
using (var converter = new ColorConverter(PixelFormat.Format1bppIndexed))
using (var writer = ImageWriter.Create("../../../../_Output/PF_ConvertToBlackAndWhiteMemoryFriendly.png"))
{
Pipeline.Run(reader + converter + writer);
}
and changed the pixelformat to grayscale, but all i get is "UnsupportedPixelFormatException", and I get that also when using 1bppIndexed as in your sample... Edited by moderator Thursday, March 5, 2015 3:08:08 AM(UTC)
| Reason: Not specified
|
|
|
|
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)
|
Do you need to convert image to grayscale or black and white pixel format? Please note only the grayscale pixel formats support transparency (we don't support alpha channel with B&W images). To preserve metadata you need to copy EXIF, IPTC, XMP, and Adobe Resources. Code:using Aurigma.GraphicsMill;
using Aurigma.GraphicsMill.Codecs;
using Aurigma.GraphicsMill.Transforms;
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
using (var reader = ImageReader.Create(@"C:\temp\dscf9639.jpg"))
using (var converter = new ColorConverter(
reader.PixelFormat.HasAlpha ? PixelFormat.Format16bppAgrayscale : PixelFormat.Format8bppGrayscale))
using (var writer = new TiffWriter(@"C:\temp\out.tiff"))
{
writer.Exif = reader.Exif;
writer.Iptc = reader.Iptc;
writer.AdobeResources = reader.AdobeResources;
writer.Xmp = reader.Xmp;
Pipeline.Run(reader + converter + writer);
}
}
}
}
Unfortunately I couldn't reproduce the "UnsupportedPixelFormatException" problem. Could you post an entire code sample? |
Best regards, Fedor Skvortsov
|
1 user thanked Fedor for this useful post.
|
|
|
Rank: Newbie
Groups: Guest
Joined: 5/6/2012(UTC) Posts: 5
Thanks: 1 times
|
Works perfectly. Don't know what I did wrong other than having an ImageWriter instead of TIFFWriter (I'm now using JpegWriter without errors).
|
|
|
|
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)
|
BTW, I had to use use the TiffWriter class because only the TIFF format supports both grayscale with alpha channel (Format16bppAgrayscale) and all type of metadata (EXIF, IPTC and so on). For example JPEG doesn't support alpha channel and PNG doesn't support metadata. |
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.