Skip to content

Bitmap.ToNDArray problem with odd bitmap width #396

Description

@herrvonregen

Hi everyone.
The official micorsoft documenation for Bitmap.Stride says:

The stride is the width of a single row of pixels (a scan line), rounded up to a four-byte boundary.

This could cause an exception here if the loaded bitmap is RGB with an odd width.
Buffer.MemoryCopy(src, dst, bmpData.Stride * image.Height, nd.size);
var ret = nd.reshape(1, image.Height, image.Width, bmpData.Stride / bmpData.Width);

Example:
An RGB image with the size of 227x227 pixels
Stride will be 684. 227*3 = 681 rounded up to four-byte boundary.
Copied data are 155268 bytes.
Reshaped into 277 * 277 * floor(684/227) = 154587 bytes
This will cause an IncorrectShapeException

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions