I am currently testing the "Graphicmill" FrameWork. I try to create a large picture from 2 pictures. The two pictures are placed side by side on the big picture. The 2 pictures have both a clipping path with same names. My problem is that I can not combine the both clipping path into 1 clipping path.
Is that possible? Can anyone give tips or code example?
You can copy 2 clipping paths to the result image using the following code:
using System;
using Aurigma.GraphicsMill;
using Aurigma.GraphicsMill.Codecs;
using Aurigma.GraphicsMill.Transforms;
class Program
{
private const int FirstPathId = 2000;
private const int LastPathId = 2997;
static void Main(string[] args)
{
using (var reader1 = new JpegReader("../../../source-image-1.jpg"))
using (var reader2 = new JpegReader("../../../source-image-2.jpg"))
using (var writer = new JpegWriter("../../../result.jpg"))
using (var sourceBitmap1 = reader1.Frames[0].GetBitmap())
using (var sourceBitmap2 = reader2.Frames[0].GetBitmap())
using (var resultBitmap = new Bitmap(sourceBitmap1.Width + sourceBitmap2.Width,
Math.Max(sourceBitmap1.Height, sourceBitmap1.Height)
, sourceBitmap1.PixelFormat))
{
resultBitmap.Draw(sourceBitmap1, 0, 0, CombineMode.Copy);
resultBitmap.Draw(sourceBitmap2, sourceBitmap1.Width, 0, CombineMode.Copy);
var adobeResources = new Aurigma.GraphicsMill.Codecs.AdobeResourceDictionary();
// The clipping path has relatives coordinates (0.0f ... 1.f0). So we need to transform it.
var clippingPath1 = reader1.ClippingPaths[0];
var transform1 = new System.Drawing.Drawing2D.Matrix();
transform1.Scale((float)sourceBitmap1.Width / (float)resultBitmap.Width, 1f);
clippingPath1.ApplyTransform(transform1);
adobeResources.Add(FirstPathId, new AdobeResourceBlock(clippingPath1.Name + "_1", clippingPath1.Data));
var clippingPath2 = reader2.ClippingPaths[0];
var transform2 = new System.Drawing.Drawing2D.Matrix();
transform2.Translate((float)sourceBitmap1.Width / (float)resultBitmap.Width, 0);
transform2.Scale((float)sourceBitmap2.Width / (float)resultBitmap.Width, 1f);
clippingPath2.ApplyTransform(transform2);
adobeResources.Add(FirstPathId + 1, new AdobeResourceBlock(clippingPath2.Name + "_2", clippingPath2.Data));
writer.AdobeResources = adobeResources;
Pipeline.Run(resultBitmap + writer);
}
}
}
Please let me know if you need to combine 2 paths.
My Problem: As a result I need a path "Path 1", which is from the path "Path 1" from Source Image1 and from the path "Path 1" from Source Image 2. I need to merge 2 Clipping Path in 1 Clipping Path "Path 1".
Currently, it is not possible. If you just concatenate two raw Adobe clipping path data blocks, it won't join these paths properly. You need to parse it (convert to a regular Path object) and do some math to make a union of these paths.
In theory, you can take Aurigma.GraphicsMill.Codecs.ClippingPath.Path.Data (raw Adobe data, clippingPath1.Data and clippingPath2.Data) and parse it yourself in accordance to Adobe Photoshop file specification. It may be a bit challenging (some Adobe structures are unusual, apparently due to the legacy reasons), but it is possible.
We don't have any plans to implement this feature in the product in the near future. However, if it is really important for you and you don't want to write the Adobe data parser yourself, we could consider implementing it as a custom work. Please let me know if you are interested.