Exemple #1
0
        static bool InsertImage(InputBitmap inputImage, OutputBitmap ob)
        {
            foreach (Rectangle rect in ob.AvailableRects)
            {
                bool isRotated = false;
                if (ImageFitsInRect(rect, inputImage.mBitmap, out isRotated))
                {
                    Size  paddingSize = new Size(GetPaddingWidth(rect), GetPaddingHeight(rect));
                    Point locationIncludingPadding = new Point(rect.X + paddingSize.Width, rect.Y + paddingSize.Height);
                    // copy image data
                    ob.CopyImageIntoImage(inputImage.mBitmap, locationIncludingPadding, isRotated);

                    // remove old rect, add 2 new ones
                    // when storing a square inside a larger square, will always leave 2 other rectangles, one on the bottom
                    // and one on the right. These rects are added to a list and then used to see if any future input images can fit
                    ob.AvailableRects.Remove(rect);
                    Size subImageSize = isRotated ? new Size(inputImage.mBitmap.Height, inputImage.mBitmap.Width) : inputImage.mBitmap.Size;
                    SplitRect(ob, rect, subImageSize + paddingSize);

                    ob.SubImages.Add(new SubImage(inputImage.mName, Util.FormatSubImageName(inputImage.mName), new Rectangle(locationIncludingPadding, subImageSize), isRotated));

                    ob.SortRectList();

                    return(true);
                }
            }

            return(false);
        }
        public static List<OutputBitmap> BreakIntoOutputBitmaps( List<InputBitmap> inputBitmaps, string outputName )
        {
            RemoveInvalidInputBitmaps( inputBitmaps );
            SortBySize( inputBitmaps );

            List<OutputBitmap> outputBitmaps = new List<OutputBitmap>();
            while ( inputBitmaps.Count > 0 )
            {
                InputBitmap inputImage = inputBitmaps[ 0 ];
                if ( OutputBitmap.IsInputImageValidSize( inputBitmaps[ 0 ].mBitmap ) )
                {
                    bool imageHasBeenAdded = AddSubImageIfPossible( inputBitmaps[ 0 ], outputBitmaps );

                    // add a new output bitmap if an existing space can't be found
                    if ( !imageHasBeenAdded )
                    {
                        OutputBitmap newOutput = new OutputBitmap( outputName, outputBitmaps.Count );
                        outputBitmaps.Add( newOutput );
                    }
                    else
                        inputBitmaps.Remove( inputBitmaps[ 0 ] );
                }
                else
                {
                    // if larger than target atlas size, just copy the input image over and add it to the page list
                    OutputBitmap newOutput = new OutputBitmap( outputName, outputBitmaps.Count, inputBitmaps[0].mBitmap.Width, inputBitmaps[0].mBitmap.Height );
                    newOutput.CopyImageIntoImage( inputBitmaps[ 0 ].mBitmap, new Point( 0, 0 ), false );
                    newOutput.SubImages.Add( new SubImage( inputImage.mName, Util.FormatSubImageName( inputImage.mName ), new Rectangle( new Point( 0, 0 ), inputImage.mBitmap.Size ), false ) );
                    outputBitmaps.Add( newOutput );
                    inputBitmaps.Remove( inputBitmaps[ 0 ] );
                }
            }
            return outputBitmaps;
        }
Exemple #3
0
        public static List <OutputBitmap> BreakIntoOutputBitmaps(List <InputBitmap> inputBitmaps, string outputName)
        {
            RemoveInvalidInputBitmaps(inputBitmaps);
            SortBySize(inputBitmaps);

            List <OutputBitmap> outputBitmaps = new List <OutputBitmap>();

            while (inputBitmaps.Count > 0)
            {
                InputBitmap inputImage = inputBitmaps[0];
                if (OutputBitmap.IsInputImageValidSize(inputBitmaps[0].mBitmap))
                {
                    bool imageHasBeenAdded = AddSubImageIfPossible(inputBitmaps[0], outputBitmaps);

                    // add a new output bitmap if an existing space can't be found
                    if (!imageHasBeenAdded)
                    {
                        OutputBitmap newOutput = new OutputBitmap(outputName, outputBitmaps.Count);
                        outputBitmaps.Add(newOutput);
                    }
                    else
                    {
                        inputBitmaps.Remove(inputBitmaps[0]);
                    }
                }
                else
                {
                    // if larger than target atlas size, just copy the input image over and add it to the page list
                    OutputBitmap newOutput = new OutputBitmap(outputName, outputBitmaps.Count, inputBitmaps[0].mBitmap.Width, inputBitmaps[0].mBitmap.Height);
                    newOutput.CopyImageIntoImage(inputBitmaps[0].mBitmap, new Point(0, 0), false);
                    newOutput.SubImages.Add(new SubImage(inputImage.mName, Util.FormatSubImageName(inputImage.mName), new Rectangle(new Point(0, 0), inputImage.mBitmap.Size), false));
                    outputBitmaps.Add(newOutput);
                    inputBitmaps.Remove(inputBitmaps[0]);
                }
            }
            return(outputBitmaps);
        }
        static bool InsertImage( InputBitmap inputImage, OutputBitmap ob )
        {
            foreach ( Rectangle rect in ob.AvailableRects )
            {
                bool isRotated = false;
                if ( ImageFitsInRect( rect, inputImage.mBitmap, out isRotated ) )
                {
                    Size paddingSize = new Size( GetPaddingWidth( rect ), GetPaddingHeight( rect ) );
                    Point locationIncludingPadding = new Point( rect.X + paddingSize.Width, rect.Y + paddingSize.Height );
                    // copy image data
                    ob.CopyImageIntoImage( inputImage.mBitmap, locationIncludingPadding, isRotated );

                    // remove old rect, add 2 new ones
                    // when storing a square inside a larger square, will always leave 2 other rectangles, one on the bottom
                    // and one on the right. These rects are added to a list and then used to see if any future input images can fit
                    ob.AvailableRects.Remove( rect );
                    Size subImageSize = isRotated ? new Size( inputImage.mBitmap.Height, inputImage.mBitmap.Width ) : inputImage.mBitmap.Size;
                    SplitRect( ob, rect, subImageSize + paddingSize );

                    ob.SubImages.Add( new SubImage( inputImage.mName, Util.FormatSubImageName( inputImage.mName ), new Rectangle( locationIncludingPadding, subImageSize ), isRotated ) );

                    ob.SortRectList();

                    return true;
                }
            }

            return false;
        }