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

Notification

Icon
Error

Options
Go to last post Go to first unread
saravanakumar38  
#1 Posted : Wednesday, May 10, 2017 6:47:02 AM(UTC)
saravanakumar38

Rank: Newbie

Groups: Member
Joined: 5/10/2017(UTC)
Posts: 4

Hi,

I need to read frames in PSD file and update the color in one of the frame, But it is not allowing me to change color.
I tried below code, but it not working. Please advice

Code:
using (var psdReader = new PsdReader(@"C:\temp\photooverlay_5.psd"))
            {
                using (var bitmap = new Bitmap(psdReader.Width, psdReader.Height, psdReader.PixelFormat)
                {
                    DpiX = psdReader.DpiX,
                    DpiY = psdReader.DpiY
                })
                {

                    //read layers and save raster layers in PNG files
                    for (int i = 0; i < psdReader.Frames.Count; i++)
                    {
                        using (var frame = psdReader.Frames[i])
                        {

                            Console.WriteLine("Frame " + frame.Index + " is processing. Frame type is " + frame.Type + ".");

                            if (string.Equals(frame.Name, "maincolor1", StringComparison.InvariantCultureIgnoreCase))
                            {
                                //Need to update color
                                //((Aurigma.GraphicsMill.Codecs.Psd.PsdShapeFrame)frame).Brush =                                  
                            }
                            
                                using (var bitmap1 = frame.GetBitmap())
                                {
                                    bitmap1.Save(@"C:\temp\frame_" + frame.Name + ".png");
                                    var rect = new System.Drawing.Rectangle()
                                    {
                                        X = frame.X,
                                        Y = frame.Y,
                                        Width = frame.Width,
                                        Height = frame.Height
                                    };

                                    bitmap.Draw(bitmap1, rect, Aurigma.GraphicsMill.Transforms.CombineMode.Alpha, 1.0f,
                                        Aurigma.GraphicsMill.Transforms.ResizeInterpolationMode.High);
                                }
                           
                        }
                    }
                    bitmap.Save(@"C:\temp\photooverlay_03.png");
                }

            }

Edited by moderator Wednesday, May 10, 2017 7:31:23 AM(UTC)  | Reason: code formatting

Fedor  
#2 Posted : Wednesday, May 10, 2017 9:32:17 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 rendering of PSD files is a pretty complex task. That's why we introduced PsdProcessor to simplify it. First of all please read the Personalizing PSD Templates article.

There are several helper properties and methods to update text, raster and shape layers. For example, you can update a color of shape frame using the ShapeCallback delegate:

Code:
var psdProcessor = new PsdProcessor();

psdProcessor.ShapeCallback = (processor, frame) =>
{
	if (frame.Name == "Polygon 1")
	{
		var shapeData = new ShapeData(frame);

		shapeData.Brush = new SolidBrush(RgbColor.Yellow);
		shapeData.Pen = new Pen(RgbColor.Blue, 4.0f);
				
		return shapeData;
	}

	return new ShapeData(frame);
};

psdProcessor.Render("../../../in.psd", "../../../out.png");


in.zip (36kb) downloaded 3 time(s).

Edited by user Wednesday, May 10, 2017 9:34:43 AM(UTC)  | Reason: Not specified

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.