@@ -220,8 +220,8 @@ public static unsafe Bitmap ToBitmap(this NDArray nd, int width, int height, Pix
220220
221221 //if flat then initialize based on given format
222222 if ( nd . ndim == 1 && format != PixelFormat . DontCare )
223- nd = nd . reshape ( 1 , height , width , format . ToBytesPerPixel ( ) ) ; //theres a check internally for size mismatch.
224-
223+ nd = nd . reshape ( 1 , height , width , format . ToBytesPerPixel ( ) ) ; //theres a check internally for size mismatc
224+
225225 if ( nd . ndim != 4 )
226226 throw new ArgumentException ( "ndarray was expected to be of 4-dimensions, (1, bmpData.Height, bmpData.Width, bytesPerPixel)" ) ;
227227
@@ -237,6 +237,9 @@ public static unsafe Bitmap ToBitmap(this NDArray nd, int width, int height, Pix
237237
238238 var ret = new Bitmap ( width , height , format ) ;
239239 var bitdata = ret . LockBits ( new Rectangle ( 0 , 0 , width , height ) , ImageLockMode . WriteOnly , format ) ;
240+ if ( bitdata . Stride != width * format . ToBytesPerPixel ( ) )
241+ nd = np . concatenate ( ( nd , np . zeros ( ( 1 , height , 1 , format . ToBytesPerPixel ( ) ) ) . astype ( NPTypeCode . Byte ) ) , 2 ) ;
242+
240243 try
241244 {
242245 var dst = new ArraySlice < byte > ( new UnmanagedMemoryBlock < byte > ( ( byte * ) bitdata . Scan0 , bitdata . Stride * bitdata . Height ) ) ;
0 commit comments