Ejemplo n.º 1
0
        public static bool Resize(WriteableBitmap bitmap, Stream stream, Size rSize, bool isCenterCrop)
        {
            bool   isResized = false;
            double dr        = JpegHelper.GetMinRatio(bitmap, rSize);

            //if (dr > 1)
            //{
            //가로/세로를 중심점에 맞추어 잘라내기
            if (isCenterCrop)
            {
                //비트맵도 사이즈 변경
                bitmap = bitmap.Resize((int)(bitmap.PixelWidth / dr), (int)(bitmap.PixelHeight / dr), WriteableBitmapExtensions.Interpolation.Bilinear);
                bitmap = bitmap.Crop(new Rect((bitmap.PixelWidth - rSize.Width) / 2, (bitmap.PixelHeight - rSize.Height) / 2, rSize.Width, rSize.Height));
                stream.Seek(0, SeekOrigin.Begin);
                bitmap.SaveJpeg(stream, (int)rSize.Width, (int)rSize.Height, 0, 100);
            }
            else
            {
                //스트림에만 저장
                stream.Seek(0, SeekOrigin.Begin);
                bitmap.SaveJpeg(stream, (int)(bitmap.PixelWidth / dr), (int)(bitmap.PixelHeight / dr), 0, 100);
            }
            isResized = true;
            //}

            return(isResized);
        }
Ejemplo n.º 2
0
        public static WriteableBitmap Resize(Stream stream, Size rSize, bool isCenterCrop)
        {
            WriteableBitmap bitmap = BitmapFactory.New(0, 0).FromStream(stream);
            double          dr     = JpegHelper.GetMinRatio(bitmap, rSize);

            //if (dr > 1) <= 주석 처리하면 축소 뿐만이 아니라 확대까지 된다.
            //{
            bitmap = bitmap.Resize((int)(bitmap.PixelWidth / dr), (int)(bitmap.PixelHeight / dr), WriteableBitmapExtensions.Interpolation.Bilinear);
            //가로/세로를 중심점에 맞추어 잘라내기
            if (isCenterCrop)
            {
                bitmap = bitmap.Crop(new Rect((bitmap.PixelWidth - rSize.Width) / 2, (bitmap.PixelHeight - rSize.Height) / 2, rSize.Width, rSize.Height));
            }
            //}
            return(bitmap);
        }