예제 #1
0
        public static void Generate(string filePathToPatch, string outputFolder, string filename)
        {
            using (var bitmap = new Bitmap(filePathToPatch))
            {
                var basicSplashNinePatch = new NinePatch();

                var topAndBottomSegmentHeight = 1d / 26d;
                var leftAndRightSegmentWidth  = 1d / 18d;

                // stretch (these values should be the same for both left and both top, to ensure that the image stays centered when resizing)
                // LeftRanges represent the NinePatch lines appearing on the left side of the image, it represents the top and bottom part
                // TopRanges represent the NinePatch lines appearing on the top side of the image, it represents the left and right part
                basicSplashNinePatch.LeftRanges.Add(NinePatchRange.CreateFromStart(0, topAndBottomSegmentHeight));
                basicSplashNinePatch.LeftRanges.Add(NinePatchRange.CreateFromEnd(1, topAndBottomSegmentHeight));
                basicSplashNinePatch.TopRanges.Add(NinePatchRange.CreateFromStart(0, leftAndRightSegmentWidth));
                basicSplashNinePatch.TopRanges.Add(NinePatchRange.CreateFromEnd(1, leftAndRightSegmentWidth));

                // scale
                basicSplashNinePatch.RightRanges.Add(NinePatchRange.CreateFromStart(topAndBottomSegmentHeight, 1d - 2 * topAndBottomSegmentHeight));
                basicSplashNinePatch.BottomRanges.Add(NinePatchRange.CreateFromStart(leftAndRightSegmentWidth, 1d - 2 * leftAndRightSegmentWidth));

                // output
                SaveDrawable(outputFolder, filename, "xxhdpi", bitmap, basicSplashNinePatch, 1.5);
                SaveDrawable(outputFolder, filename, "xhdpi", bitmap, basicSplashNinePatch, 1);
                SaveDrawable(outputFolder, filename, "hdpi", bitmap, basicSplashNinePatch, .75);
                SaveDrawable(outputFolder, filename, "mdpi", bitmap, basicSplashNinePatch, .5);
                SaveDrawable(outputFolder, filename, "ldpi", bitmap, basicSplashNinePatch, .375);
            }
        }
예제 #2
0
        private static void SaveDrawable(string folder, string filename, string suffix, Bitmap bitmap, NinePatch patch, double scale)
        {
            var newFilename = BuildFilename(folder, suffix, filename);

#if DEBUG
            //Todo Fonts dont work on Mac
            //TagImage(bitmap, suffix);
#endif
            Directory.CreateDirectory(Path.GetDirectoryName(newFilename));

            using (var newImage = Resizer.ResizeBitmap(bitmap, scale))
            {
                patch.DrawOn(newImage);
                newImage.Save(newFilename);
            }
        }