コード例 #1
0
        public Bitmap[] ResizeImage(string filename)
        {
            Bitmap Source = SourceImageFactory.NonLockingOpen(filename);
            int sourceWidth = Source.Width;
            int sourceHeight = Source.Height;

            PatchFrame SourceFrame = new PatchFrame();
            SourceFrame.Fill(Source);

            PatchFrame ResFrame6 = SourceFrame.Resize(6);
            PatchFrame ResFrame4 = SourceFrame.Resize(4);
            PatchFrame ResFrame3 = SourceFrame.Resize(3);

            #region Crop, Resize and Expand Source Image
            ImageProcessor imgProc = new ImageProcessor();

            //Crop
            Bitmap cropSource = imgProc.Crop(Source);

            //Resize
            Bitmap resizingImage6 = imgProc.Resize(cropSource, sourceWidth * 6 / 8, sourceHeight * 6 / 8);
            Bitmap resizingImage4 = imgProc.Resize(cropSource, sourceWidth / 2, sourceHeight / 2);
            Bitmap resizingImage3 = imgProc.Resize(cropSource, sourceWidth * 3 / 8, sourceHeight * 3 / 8,
                System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic);

            //Expand
            Bitmap expandedImage6 = imgProc.Expand(resizingImage6);
            Bitmap expandedImage4 = imgProc.Expand(resizingImage4);
            Bitmap expandedImage3 = imgProc.Expand(resizingImage3);
            #endregion

            #region Draw Nine_Stamp
            imgProc.Draw9PatchStamp(ResFrame6, expandedImage6);
            imgProc.Draw9PatchStamp(ResFrame4, expandedImage4);
            imgProc.Draw9PatchStamp(ResFrame3, expandedImage3);
            #endregion

            Bitmap[] result = new Bitmap[]{Source, expandedImage6, expandedImage4, expandedImage3};
            return result;
        }
コード例 #2
0
        //TODO:Extract method with x,y parametrs for SetPixel
        public void Draw9PatchStamp(PatchFrame ptFrame, Bitmap expandedImage)
        {
            //horizontal-top
            int total = 0;
            List<int> top = ptFrame.GetTop();
            for (int i = 0; i < top.Count - 1; i++)//resizingMatrix[0].Count - 1; i++)
            {
                if (i % 2 == 1)
                {
                    for (int j = 0; j < top[i]; j++)
                    {
                        {
                            expandedImage.SetPixel(total, 0, System.Drawing.Color.Black);
                            total++;
                        }
                    }
                }
                else
                {
                    total += top[i];//resizingMatrix[0][i];
                }
            }

            //vertical-right
            total = 0;
            List<int> right = ptFrame.GetRight();
            for (int i = 0; i < right.Count - 1; i++)
            {
                if (i % 2 == 1)
                {
                    for (int j = 0; j < right[i]; j++)
                    {
                        {
                            expandedImage.SetPixel(expandedImage.Width - 1, total, System.Drawing.Color.Black);
                            total++;
                        }
                    }
                }
                else
                {
                    total += right[i];
                }
            }
            //horizontal-bottom
            total = 0;
            List<int> bottom = ptFrame.GetBottom();
            for (int i = 0; i < bottom.Count - 1; i++)
            {
                if (i % 2 == 1)
                {
                    for (int j = 0; j < bottom[i]; j++)
                    {
                        {
                            expandedImage.SetPixel(total, expandedImage.Height - 1, System.Drawing.Color.Black);
                            total++;
                        }
                    }
                }
                else
                {
                    total += bottom[i];
                }
            }

            //vertical-left
            total = 0;
            List<int> left = ptFrame.GetLeft();
            for (int i = 0; i < left.Count - 1; i++)
            {
                if (i % 2 == 1)
                {
                    for (int j = 0; j < left[i]; j++)
                    {
                        {
                            expandedImage.SetPixel(0, total, System.Drawing.Color.Black);
                            total++;
                        }
                    }
                }
                else
                {
                    total += left[i];
                }
            }
        }
コード例 #3
0
        public PatchFrame Resize(int k)
        {
            int res;
            PatchFrame resFrame = new PatchFrame();

            for (int i = 0; i < frameMatrix.Length; i++)
            {
                for (int j = 0; j < frameMatrix[i].Count; j++)
                {
                    res = k * frameMatrix[i][j] / 8;

                    if (res < 1)
                    {
                        resFrame.frameMatrix[i].Add(1);
                    }
                    else
                    {
                        if (k * frameMatrix[i][j] % 8 < 5)
                        {
                            resFrame.frameMatrix[i].Add(res);
                        }
                        else
                        {
                            resFrame.frameMatrix[i].Add(res + 1);
                        }
                    }
                }
            }
            return resFrame;
        }