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

Notification

Icon
Error

Options
Go to last post Go to first unread
ot2  
#1 Posted : Thursday, March 5, 2015 2:57:27 AM(UTC)
ot2

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

Fedor  
#2 Posted : Thursday, March 5, 2015 3:43:13 AM(UTC)
Fedor

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
thanks 1 user thanked Fedor for this useful post.
ot2 on 3/5/2015(UTC)
ot2  
#3 Posted : Thursday, March 5, 2015 6:22:57 AM(UTC)
ot2

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).
Fedor  
#4 Posted : Thursday, March 5, 2015 6:42:08 AM(UTC)
Fedor

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
Users browsing this topic
Guest
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.