コード例 #1
0
ファイル: Input.cs プロジェクト: spoolrd/CeNiN
        private Bitmap resizeBitmap(Bitmap b, ResizingMethod resizingMethod)
        {
            Bitmap   resizedBmp = new Bitmap(inputSize[1], inputSize[0], PixelFormat.Format24bppRgb);
            Graphics gr         = Graphics.FromImage(resizedBmp);

            if (resizingMethod == ResizingMethod.Stretch)
            {
                gr.DrawImage(b, 0, 0, inputSize[1], inputSize[0]);
            }
            else
            {
                float inputAspRatio = inputSize[0] / inputSize[1];

                int   newHeight, newWidth;
                float multiplier = (float)b.Width / b.Height;
                if (multiplier > inputAspRatio)
                {
                    multiplier = inputAspRatio / multiplier;
                    newWidth   = inputSize[1];
                    newHeight  = (int)(newWidth * multiplier);
                }
                else
                {
                    newHeight = inputSize[0];
                    newWidth  = (int)(newHeight * multiplier);
                }

                gr.DrawImage(b, (inputSize[1] - newWidth) / 2.0f, (inputSize[0] - newHeight) / 2.0f, newWidth, newHeight);
            }

            gr.Dispose();

            return(resizedBmp);
        }
コード例 #2
0
        public void setInput(Bitmap input, ResizingMethod resizingMethod)
        {
            outputTensorMemAlloc();

            Bitmap iBitmap = (Bitmap)input.Clone();

            resizedInputBmp = resizeBitmap(iBitmap, resizingMethod);
            iBitmap.Dispose();
        }