我越來越F#從內存流創建位圖拋出異常
System.ArgumentException: 'Parameter is not valid.'
出於某種原因。
一條線在那裏我得到它:
let image = Bitmap.FromStream stream
這就是我
let ChangeBitmapColors (bitmap : Bitmap) =
Console.WriteLine bitmap.Size
let width = bitmap.Width
let height = bitmap.Height
let rectangle = new Rectangle(0, 0, width, height)
let bitmapData = bitmap.LockBits(rectangle, Imaging.ImageLockMode.ReadOnly, bitmap.PixelFormat)
let length = bitmapData.Stride * height
let bitmapArray : byte[] = Array.zeroCreate length
Marshal.Copy(bitmapData.Scan0, bitmapArray, 0, length)
bitmap.UnlockBits bitmapData
//todo something with bitmapArray
use stream = new MemoryStream(bitmapArray)
let image = Bitmap.FromStream stream
stream.Dispose |> ignore
image
任何想法,我究竟做錯了什麼?提前致謝。
@ildjarn,哎,initialy bitmap.PixelFormat在那裏,我試圖使用特定的像素格式雖然排除故障,但得到了相同的異常 –
順便說一句,你看到這個? http://stackoverflow.com/questions/5285213/parameter-is-not-valid-error-when-creating-image-from-byte-in-c-sharp –
@FoggyFinder是的,我也試過,以及 –