悪いタイトルでごめんなさい
私はこの機能を持っています:
public Stream PictureStream( int size = 0 )
{
if( size == 0 )
{
return new MemoryStream( PictureFile );
}
else
{
ImageFormat format = null;
if( FileFormat == ".jpg" || FileFormat == ".jpeg" )
{
format = ImageFormat.Jpeg;
}
else if( FileFormat == ".png" )
{
format = ImageFormat.Png;
}
else
{
format = ImageFormat.Png;
}
var ms = new MemoryStream( PictureFile );
var returnImage = Image.FromStream( ms );
var img = returnImage.Resize( size );
img.Save( ms , format );
return ms;
}
}
そしてこのActionResult :
public FileStreamResult Image( long userkey , int? size )
{
var image = UserImagesService.Find( userkey );
image.Size = size == null ? 0 : ( int )size;
return new FileStreamResult( image.Stream , image.ContentType );
}
私のサイズがnullの場合、画像は正常にロードされますが、Firefoxでサイズを渡すと、次のエラーが表示されます:
The image “http://localhost:8609/Profiles/Image/4006242570097652224/150” cannot be displayed because it contains errors.
その罰金はディスクに保存されます
私の問題は何ですか?
アップデート
私のサイズ変更機能:
public static Image Resize( this Image imgToResize , int size )
{
int sourceWidth = imgToResize.Width;
int sourceHeight = imgToResize.Height;
float nPercent = 0;
float nPercentW = 0;
float nPercentH = 0;
nPercentW = ( ( float )size / ( float )sourceWidth );
nPercentH = ( ( float )size / ( float )sourceHeight );
if( nPercentH < nPercentW )
{
nPercent = nPercentH;
}
else
{
nPercent = nPercentW;
}
int destWidth = ( int )( sourceWidth * nPercent );
int destHeight = ( int )( sourceHeight * nPercent );
Bitmap b = new Bitmap( destWidth , destHeight );
Graphics g = Graphics.FromImage( ( System.Drawing.Image )b );
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.DrawImage( imgToResize , 0 , 0 , destWidth , destHeight );
g.Dispose();
return ( System.Drawing.Image )b;
}