| 
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 |