私たちはあなたの問題の正確な性質にもう少し周囲のコード、またはより多くの情報が必要かもしれませんが、私はこの問題の原因として最も可能性が高いがResizeImageで起こっているものは何でもある疑い。
System.Drawing.Image
のサイズを変更する機能はありますか?恐らくそれを試して問題が解決したかどうかを確認してください。ここで
public static Image ResizeImage(int newWidth, int newHeight, Image image) {
int sourceWidth = image.Width;
int sourceHeight = image.Height;
//Consider vertical pics
if (sourceWidth < sourceHeight) {
int buff = newWidth;
newWidth = newHeight;
newHeight = buff;
}
int sourceX = 0, sourceY = 0, destX = 0, destY = 0;
float percent = 0, percentW = 0, percentH = 0;
percentW = ((float)newWidth/(float)sourceWidth);
percentH = ((float)newHeight/(float)sourceHeight);
if (percentH < percentW) {
percent = percentH;
destX = System.Convert.ToInt16((newWidth -
(sourceWidth * percent))/2);
} else {
percent = percentW;
destY = System.Convert.ToInt16((newHeight -
(sourceHeight * percent))/2);
}
int destWidth = (int)(sourceWidth * percent);
int destHeight = (int)(sourceHeight * percent);
Bitmap bitmap = new Bitmap(newWidth, newHeight,
PixelFormat.Format24bppRgb);
bitmap.SetResolution(image.HorizontalResolution,
image.VerticalResolution);
Graphics graphic = Graphics.FromImage(bitmap);
graphic.Clear(Color.Black);
graphic.InterpolationMode =
System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
graphic.DrawImage(image,
new Rectangle(destX, destY, destWidth, destHeight),
new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight),
GraphicsUnit.Pixel);
graphic.Dispose();
image.Dispose();
return bitmap;
}
Hey Samuelさん、こんにちは。構文エラーの場合や単にイメージを作成しない場合のように、問題に関するさらに詳しい情報を提供する必要があります。 –
あなたはResizeImageのコードを共有してください。 –
_働いていませんが役立つ問題の説明ではありません! – TaW