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);
        }
        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;
        }