public byte[] scaleStreamImageTo(int outWidth, int outHeight) { int x, y, w, h; int iWoH = mImage.Width * outHeight; int iHoW = mImage.Height * outWidth; if (iWoH < iHoW) { w = (int)((double)(iWoH) / mImage.Height); h = outHeight; x = (int)((outWidth - w) / 2.0); y = 0; } else { w = outWidth; h = (int)((double)(iHoW) / mImage.Width); x = 0; y = (int)((outHeight - h) / 2.0); } using (Bitmap outImage = new Bitmap(outWidth, outHeight)) { drawImage(mImage, outImage, new Rectangle(x, y, w, h)); return(ImageOps.imageToByteArray(outImage)); } }
public byte[] scaleStreamImageBy(float scaleFactor) { int outWidth = (int)(mImage.Width * scaleFactor); int outHeight = (int)(mImage.Height * scaleFactor); using (Bitmap outImage = new Bitmap(outWidth, outHeight)) { drawImage(mImage, outImage, new Rectangle(0, 0, outWidth, outHeight)); return(ImageOps.imageToByteArray(outImage)); } }