Welcome Guest! You need to login or register to make posts.

Notification

Icon
Error

Options
Go to last post Go to first unread
bma  
#1 Posted : Thursday, January 14, 2016 10:39:36 AM(UTC)
bma

Rank: Member

Groups: Member
Joined: 1/12/2016(UTC)
Posts: 23

Thanks: 8 times
Hello,

Is it possible to adapth the clipping path when rotating or cropping an image with bitmap? I've tried with the pipeline and it worked, however when I try with bitmap, the clipping path doesn't adapt.


Code snippet working (pipeline):
Code:
public byte[] Test(byte[] media)
{
	using (var imageStream = new MemoryStream(media))
	using (var exportedImageStream = new MemoryStream())
	using (var reader = new JpegReader(imageStream))
	using (var writer = new JpegWriter(exportedImageStream))
	using (var rotate = new Rotate(60f))
	using (var crop = new Crop(reader.Width / 2, 0, reader.Width / 2, reader.Height / 2))
	{
		writer.AdobeResources = reader.AdobeResources;

		Pipeline.Run(reader + rotate + crop + writer);

		return exportedImageStream.GetBuffer();
	}
}



Code snippet not working (bitmap):
Code:
public byte[] Test(byte[] media, int width, int height)
{
	using (var imageStream = new MemoryStream(media))
	using (var exportedImageStream = new MemoryStream())
	using (var imageReader = ImageReader.Create(imageStream))
	using (var bitmap = imageReader.Frames[0].GetBitmap())
	{
		var jpegSettings = new JpegSettings { Quality = 100 };

		#region metadata

		if (imageReader.AdobeResources != null)
		{
			jpegSettings.AdobeResources = imageReader.AdobeResources;
		}

		if (imageReader.Exif != null)
		{
			jpegSettings.Exif = imageReader.Exif;
		}

		if (imageReader.Iptc != null)
		{
			jpegSettings.Iptc = imageReader.Iptc;
		}

		if (imageReader.Xmp != null)
		{
			jpegSettings.Xmp = imageReader.Xmp;
		}

		#endregion

		bitmap.Transforms.Resize(width, height);
		bitmap.Transforms.Crop(imageReader.Width / 2, 0, imageReader.Width / 2, imageReader.Height / 2);

		bitmap.Transforms.Rotate(30f);

		bitmap.Save(exportedImageStream, jpegSettings);

		return exportedImageStream.GetBuffer();
	}
}


Thank you in advance,
Kind regards
bma attached the following image(s):
clippingpath.jpg
Fedor  
#2 Posted : Thursday, January 14, 2016 11:33:20 AM(UTC)
Fedor

Rank: Advanced Member

Groups: Member, Administration, Moderator
Joined: 7/28/2003(UTC)
Posts: 1,660

Thanks: 5 times
Was thanked: 76 time(s) in 74 post(s)
The clipping path is processed correctly using the Pipeline API only.

Is this limitation critical for you?
Best regards,
Fedor Skvortsov
bma  
#3 Posted : Friday, January 15, 2016 7:32:54 AM(UTC)
bma

Rank: Member

Groups: Member
Joined: 1/12/2016(UTC)
Posts: 23

Thanks: 8 times
This limitation it's not critical, but I would like to have this feature in the future, if it's possible...

Best regards
Fedor  
#4 Posted : Friday, January 15, 2016 11:28:14 PM(UTC)
Fedor

Rank: Advanced Member

Groups: Member, Administration, Moderator
Joined: 7/28/2003(UTC)
Posts: 1,660

Thanks: 5 times
Was thanked: 76 time(s) in 74 post(s)
I have added the feature to the backlog of Graphics Mill (Aurigma Bug #0021662).
Best regards,
Fedor Skvortsov
thanks 1 user thanked Fedor for this useful post.
bma on 1/18/2016(UTC)
Fedor  
#5 Posted : Tuesday, February 16, 2016 2:21:12 AM(UTC)
Fedor

Rank: Advanced Member

Groups: Member, Administration, Moderator
Joined: 7/28/2003(UTC)
Posts: 1,660

Thanks: 5 times
Was thanked: 76 time(s) in 74 post(s)
We have just released the new version 8.1.12 of the Graphics Mill SDK where we have implemented manipulation of clipping path.

F.Metadata\F.05.ClippingPath\ClippingPathExample.cs

Code:
/// <summary>
/// Modifies clipping path explicitly using memory-friendly Pipeline API
/// </summary>
private static void ModifyClippingPathExplicitlyMemoryFriendly()
{
	int width = 1000;
	int height = 1000;

	using (var reader = new JpegReader(@"../../../../_Input/Apple.jpg"))
	using (var generator = new ImageGenerator(width, height, reader.PixelFormat, RgbColor.White))
	using (var combiner = new Combiner(CombineMode.Copy))
	using (var writer = new JpegWriter(@"../../../../_Output/ModifyClippingPathExplicitlyMemoryFriendly.jpg"))
	{
		combiner.TopImage = reader;
		combiner.X = (width - reader.Width) / 2;
		combiner.Y = (height - reader.Height) / 2;

		//The clipping path has relatives coordinates (0.0f ... 1.f0). So we need to transform it.
		var transform = new System.Drawing.Drawing2D.Matrix();
		transform.Scale((float)reader.Width / (float)width, (float)reader.Height / (float)height);
		transform.Translate((float)combiner.X / (float)reader.Width, (float)combiner.Y / (float)reader.Height);

		var adobeResources = reader.AdobeResources;

		//2000-2997 Clipping path information 
		//http://www.adobe.com/devnet-apps/photoshop/fileformatashtml/ 
		const int firstPathId = 2000;
		const int lastPathId = 2997;

		//Remove clipping paths
		foreach (long key in adobeResources.Keys)
		{
			if (key >= firstPathId && key <= lastPathId)
			{
				adobeResources.Remove(key);
			}
		}

		//Transform and save clipping paths
		for (var i = 0; i < reader.ClippingPaths.Count; i++)
		{
			var clippingPath = reader.ClippingPaths[0];
			clippingPath.ApplyTransform(transform);

			adobeResources.Add(2000 + i, new AdobeResourceBlock(clippingPath.Name, clippingPath.Data));
		}

		writer.AdobeResources = adobeResources;

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


/// <summary>
/// Modifies clipping path explicitly
/// </summary>
private static void ModifyClippingPathExplicitly()
{
	using (var reader = new JpegReader(@"../../../../_Input/Apple.jpg"))
	using (var bitmap = reader.Frames[0].GetBitmap())
	{
		var crop = new Crop(20, 20, bitmap.Width - 40, bitmap.Height - 40);

		var cropped = crop.Apply(bitmap);

		var clippingPath = reader.ClippingPaths[0];
		
		clippingPath.ApplyTransform(crop.GetPathTransformMatrix(bitmap.Width, bitmap.Height).ToGdiPlusMatrix());

		var adobeResources = new AdobeResourceDictionary();
		adobeResources.Add(2000, new AdobeResourceBlock("Apple", clippingPath.Data));

		var jpegSettings = new JpegSettings();
		jpegSettings.AdobeResources = adobeResources;

		cropped.Save(@"../../../../_Output/ModifyClippingPathExplicitly.jpg", jpegSettings);
	}
}
Best regards,
Fedor Skvortsov
Users browsing this topic
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.