サムネイルを作成してからバイト配列に変換するのに時間があります。私は3つの方法を試みましたが、3回すべてエラーが発生します。サムネイルを作成してからバイト配列に変換する
最初は、私が過去に使用したBitmap.GetThumbnailImage、使用し、次いで第二の)のdrawImage(とSystem.Drawing.Graphicsを用いたResponse.OutputStream
に直接保存しました。まだ行きません。
新しいビットマップを作成し、古いビットマップを渡して新しいサイズを設定するだけでした。同じエラー。
Value cannot be null.
Parameter name: encoder
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: encoder
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[ArgumentNullException: Value cannot be null.
Parameter name: encoder]
System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams) +615244
私の方法のコードです。たぶん誰かが私が間違っているのを見るだろう。 GetThumbSizeについてわからない場合は、画像サイズと最大サムサイズを取り込んで、アスペクト比を維持するために実際のサイズを計算する単純な方法です。
thumb.Save(outStream, thumb.RawFormat);
任意のアイデア:
public static System.Drawing.Image.GetThumbnailImageAbort thumbnailCallback = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
public static bool ThumbnailCallback()
{
return false;
}
/// <summary>
///
/// </summary>
/// <param name="image"></param>
/// <param name="size"></param>
/// <remarks>
/// This method will throw a AccessViolationException when the machine OS running the server code is windows 7.
/// </remarks>
/// <returns></returns>
public static byte[] CreateThumbnail(byte[] imageData, Size size)
{
using (MemoryStream inStream = new MemoryStream())
{
inStream.Write(imageData, 0, imageData.Length);
using (System.Drawing.Image image = Bitmap.FromStream(inStream))
{
Size thumbSize = GetThumbSize(new Size(image.Width, image.Height), size);
//do not make image bigger
if (thumbSize.Equals(image.Size) || (image.Width < size.Width || image.Height < size.Height))
{
//if no shrinking is ocurring, return the original bytes
return imageData;
}
else
{
using (System.Drawing.Image thumb = image.GetThumbnailImage(thumbSize.Width, thumbSize.Height, thumbnailCallback, IntPtr.Zero))
{
using (MemoryStream outStream = new MemoryStream())
{
thumb.Save(outStream, thumb.RawFormat);
return outStream.ToArray();
}
}
}
}
}
}
この行はエラーを投げていますか?助けてくれてありがとう!
のMicrosoft Connectのこの問題:http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=98452 –