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

Notification

Icon
Error

Options
Go to last post Go to first unread
Tanya  
#1 Posted : Sunday, April 27, 2008 6:08:25 PM(UTC)
Tanya

Rank: Advanced Member

Groups: Member
Joined: 5/14/2007(UTC)
Posts: 24

Was thanked: 1 time(s) in 1 post(s)
Description:

This application demonstrates how to use Advanced PSD Add-on to create real estate advertising booklets. It stores realty details in the internal database and uses this data to create booklets. The user can preview a booklet using the BitmapViewer or save it with the specified dpi as well as change some text or image information and choose a template. Note that the application provides a read-only access to real estate data and all your modifications will not affect sample database.

The main functionality of this application is implemented with the PsdRenderer class. Let’s consider it more detailed.

PsdRenderer Class Overview

The PsdRenderer class is based on Graphics Mill for .NET Advanced PSD Add-on. It is intended to render PSD files and customize raster and text layers. Such functionality may be useful if you need to create several images based on the same template with different content, e.g. business cards, advertising booklets, postcards, etc.

This class provides only one public method: Render(string, Dictionary<string, IReplacerInfo>, int) which returns the Bitmap class instance and accepts the following arguments:
  • The filename of the PSD template;
  • The dictionary which contains names of the layers we need to customize and new content for these layers;
  • The DPI of the result image.
New content for raster and text layers is specified with BitmapReplacerInfo and TextReplacerInfo classes respectively.

The TextReplacerInfo class specifies new text value. The BitmapReplacerInfo class specifies new bitmap to render and two additional placement parameters - ImageFitMode and ImageAlignment.

The ImageFitMode enumeration contains values specifying how to handle situations when the replacer's image is not fit at its placeholder at the result image. The following values are supported:
  • CropToFit - Crops the image. The crop area is centered.
  • ResizeToFill - Resizes the image so that it fills the whole placeholder, even if the resulting image is larger than the placeholder. The aspect ratio is preserved.
  • ResizeToFit - Resizes the image to have the same size as a placeholder for this image at the page (preserving the aspect ratio though). The image is resized even if it is smaller than the placeholder.
  • ShrinkToFit - Resizes the image to have the same size as a placeholder for this image at the page (preserving the aspect ratio though) only if the image is larger than the placeholder. If the image is smaller, it is not changed.
The ImageAlignment enumeration contains possible values for the replacer's image alignment inside the placeholder (CenterTop, CenterBottom, etc).

To gain a better understanding of the Render method let us consider a simple example. Assume that we have the PSD template which contains three layers: background raster layer which will not be replaced, image and text placeholders. Suppose, the layer contained an image placeholder has the “Image” name and the layer with a text placeholder has the “Text” name. To create both preview and printable versions of the personalized graphics using this template and the custom image and text we need to perform the following steps:

1.Create a dictionary.

Code:

Dictionary<string, IReplacerInfo> replacers = new Dictionary<string, 
IReplacerInfo>();


2.Fill this dictionary with two replacers: one for the image layer and another for the text.

Code:

Aurigma.GraphicsMill.Bitmap image = new 
Aurigma.GraphicsMill.Bitmap(@"C:\image.jpg");
replacers.Add("Image", new BitmapReplacerInfo(image, 
ImageFitMode.ResizeToFit, ImageAlignment.LeftCenter));
replacers.Add("Text", new TextReplacerInfo("New text"));


3.Create new instance on the PsdRenderer class and use its method Render to create a preview version with 72 dpi and printable one with 300 dpi.

Code:

string template = @"C:\Template.psd";

PsdRenderer rend = new PsdRenderer();
Aurigma.GraphicsMill.Bitmap print = rend.Render(template, replacers, 300);
print.Save(@"C:\print.jpg");
Aurigma.GraphicsMill.Bitmap preview = rend.Render(template, replacers, 72);
preview.Save(@"C:\preview.jpg"); 


Required Graphics Mill for .NET assemblies:

Aurigma.GraphicsMill.dll
Aurigma.GraphicsMill.WinControls.dll
Aurigma.GraphicsMill.Codecs.AdvancedPsd.dll

Edited by moderator Monday, May 28, 2012 8:40:51 PM(UTC)  | Reason: Not specified

File Attachment(s):
RealEstateDigestCS.zip (1,036kb) downloaded 113 time(s).
Tanya attached the following image(s):
preview.png
Best regards,
Tatyana Bertyakova

UserPostedImage Follow Aurigma on Twitter!
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.