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

Notification

Icon
Error

Options
Go to last post Go to first unread
nikmauro  
#1 Posted : Thursday, September 12, 2019 10:08:39 AM(UTC)
nikmauro

Rank: Newbie

Groups: Member
Joined: 12/24/2018(UTC)
Posts: 7

Hello i have a PSD with 2 smart objects with names Design & Design2, i create the following code to change the content of smart object layers.

The code replace only the smartframe with name Design2.

If comment the part2 code the smartframe with name Design working.

Plase any help how to resolve this problem.

Code:

public static String PsdChangeSO(String filename,String Template, String filename2)
        {
            var customResolver = new FontResolver(@"C:\inetpub\wwwroot\Images\FontCache");
            var psdProcessor = new PsdProcessor(Path.GetTempPath());

//part1
            psdProcessor.FrameCallback = (processor, frame) =>
            {
                if (frame.Type == FrameType.SmartObject && frame.Name == "Design")
                {
                    var smartFrame = (PsdSmartFrame)frame;
                    var webclient = new System.Net.WebClient();
                    var uriimage = webclient.OpenRead(new Uri(filename));
                    return smartFrame.ToGraphicsContainer(new Aurigma.GraphicsMill.Bitmap(uriimage), ResizeMode.Fit);
                }
                else {
                    return processor.ProcessFrame(frame);
                }
            };

//part2
            psdProcessor.FrameCallback = (processor, frame) =>
            {
                if (frame.Type == FrameType.SmartObject && frame.Name == "Design2")
                {
                    var smartFrame2 = (PsdSmartFrame)frame;
                    var webclient = new System.Net.WebClient();
                    var uriimage = webclient.OpenRead(new Uri(filename2));
                    return smartFrame2.ToGraphicsContainer(new Aurigma.GraphicsMill.Bitmap(uriimage), ResizeMode.Fit);
                }
                else {
                    return processor.ProcessFrame(frame);
                }
                };

            var outputFilename = GetTimestamp(DateTime.Now);
            psdProcessor.Render(@"C:\inetpub\wwwroot\Images\"+Template, @"C:\inetpub\wwwroot\Images\Output\" + outputFilename + ".png");
            return outputFilename+".png";
        }
nikmauro  
#2 Posted : Thursday, September 12, 2019 10:16:51 AM(UTC)
nikmauro

Rank: Newbie

Groups: Member
Joined: 12/24/2018(UTC)
Posts: 7

Here another not working code

Code:
public static String PsdChangeSO(String filename,String Template, String filename2)
        {
            var customResolver = new FontResolver(@"C:\inetpub\wwwroot\Images\FontCache");
            var psdProcessor = new PsdProcessor(Path.GetTempPath());

            psdProcessor.FrameCallback = (processor, frame) =>
            {
                if (frame.Type != FrameType.SmartObject || frame.Name != "Design")
                    return processor.ProcessFrame(frame);

                var smartFrame = (PsdSmartFrame)frame;
                var webclient = new System.Net.WebClient();
                var uriimage = webclient.OpenRead(new Uri(filename));
                return smartFrame.ToGraphicsContainer(new Aurigma.GraphicsMill.Bitmap(uriimage), ResizeMode.Fit);
            };
            
            psdProcessor.FrameCallback = (processor, frame) =>
            {
                if (frame.Type != FrameType.SmartObject || frame.Name != "Design2")
                    return processor.ProcessFrame(frame);

                var smartFrame = (PsdSmartFrame)frame;
                var webclient = new System.Net.WebClient();
                var uriimage = webclient.OpenRead(new Uri(filename));
                return smartFrame.ToGraphicsContainer(new Aurigma.GraphicsMill.Bitmap(uriimage), ResizeMode.Fit);
            };

            var outputFilename = GetTimestamp(DateTime.Now);
            psdProcessor.Render(@"C:\inetpub\wwwroot\Images\"+Template, @"C:\inetpub\wwwroot\Images\Output\" + outputFilename + ".png");
            return outputFilename+".png";
        }
Fedor  
#3 Posted : Thursday, September 12, 2019 11:36:59 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)
You should use a single delegate for the FrameCallback callback, as it is not an event and doesn't broadcast to multiple delegates. Please note, the code is untested.

Code:
            psdProcessor.FrameCallback = (processor, frame) =>
            {
                if (frame.Type != FrameType.SmartObject || (frame.Name != "Design" && frame.Name != "Design2"))
                    return processor.ProcessFrame(frame);

				if (frame.Name == "Design")
				{
					var smartFrame = (PsdSmartFrame)frame;
					var webclient = new System.Net.WebClient();
					var uriimage = webclient.OpenRead(new Uri(filename));
					return smartFrame.ToGraphicsContainer(new Aurigma.GraphicsMill.Bitmap(uriimage), ResizeMode.Fit);
				}
				else //Design2
				{
					var smartFrame = (PsdSmartFrame)frame;
					var webclient = new System.Net.WebClient();
					var uriimage = webclient.OpenRead(new Uri(filename));
					return smartFrame.ToGraphicsContainer(new Aurigma.GraphicsMill.Bitmap(uriimage), ResizeMode.Fit);
				}
            };
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.