This forum contains outdated content and is available for reading only. Please contact technical support if you have any questions.

Notification

Icon
Error

Options
Go to last post Go to first unread
MattW  
#1 Posted : Wednesday, May 26, 2010 6:56:53 AM(UTC)
MattW

Rank: Newbie

Groups: Guest
Joined: 6/24/2009(UTC)
Posts: 3

Using the latest version of GraphicsMill and .NET 4.0, I am getting the following error. I get the same error on the business card sample as well out of the box.

Code:
Aurigma.GraphicsMill.BitmapEmptyException was unhandled by user code
  Message=Bitmap object has not been filled up with data.
  Source=Aurigma.GraphicsMill
  StackTrace:
       at Aurigma.GraphicsMill.Bitmap.ThrowIfEmpty()
       at Aurigma.GraphicsMill.Bitmap.Draw(Bitmap destinationBitmap, Int32 destinationX, Int32 destinationY, Int32 destinationWidth, Int32 destinationHeight, CombineMode combine, Single opacity, InterpolationMode interpolationMode)
       at AurigmaImageTest.imagegen.RasterizePsd(String inputFilename, Hashtable updatedLayers) in C:\Matthew Williams\Sandbox\AurigmaImageTest\imagegen.aspx.cs:line 122
       at AurigmaImageTest.imagegen.Page_Load(Object sender, EventArgs e) in C:\Matthew Williams\Sandbox\AurigmaImageTest\imagegen.aspx.cs:line 24
       at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
       at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
       at System.Web.UI.Control.OnLoad(EventArgs e)
       at System.Web.UI.Control.LoadRecursive()
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException: 


Here is the code I am using which is just a shameless copy from the business card sample project.

Code:
using System;
using Aurigma.GraphicsMill;

namespace AurigmaImageTest
{
    public partial class imagegen : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            System.Collections.Hashtable updatedLayers = new System.Collections.Hashtable();

			updatedLayers.Add("FullName", "John Doe");

            // don't do anything yet
            Bitmap Bmp = RasterizePsd(@"c:\ImageTemplates\BusinessCard.psd", updatedLayers);
        }

        public static Aurigma.GraphicsMill.Bitmap RasterizePsd(string inputFilename, System.Collections.Hashtable updatedLayers)
        {

            // Open the reader object on the template file.
            Aurigma.GraphicsMill.Codecs.AdvancedPsdReader reader =
                new Aurigma.GraphicsMill.Codecs.AdvancedPsdReader(inputFilename);

            // Create the bitmap which will keep the result.
            Aurigma.GraphicsMill.Bitmap resultBitmap =
                new Aurigma.GraphicsMill.Bitmap();

            // Load the background layer into the result bitmap.
            // Background layer always has index = 1.
            Aurigma.GraphicsMill.Codecs.AdvancedPsdFrame frame;
            frame = (Aurigma.GraphicsMill.Codecs.AdvancedPsdFrame)reader.LoadFrame(1);
            frame.GetBitmap(resultBitmap);
            frame.Dispose();

            resultBitmap.Channels.DiscardAlpha(Aurigma.GraphicsMill.RgbColor.White);

            // Create intermediate bitmap which will keep the current layer.
            Aurigma.GraphicsMill.Bitmap currentLayerBitmap =
                new Aurigma.GraphicsMill.Bitmap();

            // Process all frames (except of first two ones) of the template file and 
            // draw them on the result bitmap. If it is placeholder which should 
            // be replaced, draw the text instead of the bitmap.
            //
            // We skip first two frames, because the very first one stores pre-rendered 
            // PSD image (meaningless to us) and the second one stores the background
            // layer which is already loaded into the result bitmap.
            for (int i = 2; i < reader.FrameCount; i++)
            {
                frame = (Aurigma.GraphicsMill.Codecs.AdvancedPsdFrame)reader.LoadFrame(i);

                // Skip layers which we cannot process.
                if (frame.Type != Aurigma.GraphicsMill.Codecs.PsdFrameType.Unknown)
                {
                    // Determine whether the current layer is a placeholder by 
                    // searching its name in the hash table of placeholder data.
                    bool isPlaceholder = updatedLayers[frame.Name] != null;

                    // If this is a placeholder, and the layer is a text, replace the text data...
                    if (isPlaceholder && frame.Type == Aurigma.GraphicsMill.Codecs.PsdFrameType.Text)
                    {
                        Aurigma.GraphicsMill.Codecs.AdvancedPsdTextFrame textFrame;
                        Aurigma.GraphicsMill.Drawing.GdiGraphics graphics;

                        // Cast the frame to text frame type to be able to get textual settings.
                        textFrame = (Aurigma.GraphicsMill.Codecs.AdvancedPsdTextFrame)frame;

                        // When drawing the text layer as a text string, keep in mind that
                        // Left and Top properties return position of the layer bounding box
                        // rather than coordinate of text output. While the DrawString method
                        // inserts small gap above the string, the Top property of the frame,
                        // does not include this gap (it returns the box which circumscribes 
                        // the text string).
                        //
                        // There is no need to recalculate the X coordinate, because Graphics Mill 
                        // does not any horizontal gaps between the first character in the string. 						
                        //
                        // To calculate the Y coordinate properly, we can use analyze the black box of
                        // characters of the text layer. It represents the bounding rectangle of the  
                        // character relatively the text output origin. This way we can get the 
                        // necessary offset. See GetBlackBox method of the Font object for more details. 
                        float y = textFrame.Top - textFrame.Font.GetBlackBox(textFrame.Text.Trim()).Top;

                        // Draw the necessary text instead the placeholder text.
                        graphics = resultBitmap.GetGdiGraphics();
                        graphics.DrawString((string)(updatedLayers[frame.Name]), textFrame.Font, textFrame.TextBrush, textFrame.Left, y);

                        // Release resources
                        graphics.Dispose();

                    }

                        // ... otherwise just draw the bitmap.
                    else
                    {
                        // If this is a placeholder, draw passed bitmap. 
                        if (isPlaceholder)
                        {
                            // Since the width of the bitmap from updatedLayers may differ from 
                            // width of the layer, we need to resize it to avoid design corruption.
                            // If you need to resize it differently, try to play with arguments.
                            ((Aurigma.GraphicsMill.Bitmap)(updatedLayers[frame.Name])).Draw(resultBitmap,
                                frame.Left, frame.Top,
                                frame.Width, 0,
                                Aurigma.GraphicsMill.Transforms.CombineMode.Alpha, 1.0f,
                                Aurigma.GraphicsMill.Transforms.InterpolationMode.LowQuality);
                        }
                        // If this is not a placeholder, draw the bitmap from PSD file.
                        else
                        {
                            frame.GetBitmap(currentLayerBitmap);
                            currentLayerBitmap.Draw(resultBitmap,
                                frame.Left, frame.Top,
                                0, 0,
                                Aurigma.GraphicsMill.Transforms.CombineMode.Alpha, 1.0f,
                                Aurigma.GraphicsMill.Transforms.InterpolationMode.LowQuality);
                        }
                    }
                }
            }

            // Release resources
            currentLayerBitmap.Dispose();

            // Do not forget to close the reader to release the template file.
            reader.Close();

            return resultBitmap;
        }
    }
}

Edited by user Wednesday, May 26, 2010 11:49:15 PM(UTC)  | Reason: Not specified

Tamila  
#2 Posted : Thursday, May 27, 2010 12:39:45 AM(UTC)
Tamila

Rank: Advanced Member

Groups: Guest
Joined: 3/9/2008(UTC)
Posts: 554

Was thanked: 1 time(s) in 1 post(s)
Hi,

Since the latest version of Graphics Mill, AdvancedPSD add-on supports different layers types. So, to resolve the problem with this sample you need replace this line:
Code:
// Skip layers which we cannot process.
if (frame.Type != Aurigma.GraphicsMill.Codecs.PsdFrameType.Unknown)

with the following one:
Code:
if (frame.Type == Aurigma.GraphicsMill.Codecs.PsdFrameType.Raster || frame.Type == Aurigma.GraphicsMill.Codecs.PsdFrameType.Text)

Aurigma Support Team

UserPostedImage Follow Aurigma on Twitter!
julianmarble  
#3 Posted : Sunday, September 19, 2010 5:31:53 PM(UTC)
julianmarble

Rank: Newbie

Groups: Guest
Joined: 9/19/2010(UTC)
Posts: 1

This post really helpful and useful. Though it's complicated to look at but I would really say that the following sample was informative one.

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.