Page 1 of 1

Crop an Image into 9 tiles

Posted: 08 Mar 2020, 15:31
by tesrt
How can I divide an image into many other tiles ?
What I have at the moment is a "random image generator".
But what I would need is a way to read the bytes of a bitmap image in order to copy only some part of the image I guess.

But how can I access the bytes of a bitmap Image ?

Here is some code I use to create the "random image".
        private BitmapSource CreateImage(BitmapImage image)
        {
            // Define parameters used to create the BitmapSource.
            int width = 200;
            int height = 200;
            int rawStride = (width * 8 + 7) / 8;
            byte[] rawImage = new byte[rawStride * height];

            // Initialize the image with data.
            Random value = new Random();
            value.NextBytes(rawImage);

            return BitmapSource.Create(width, height, 80, 80, rawImage, rawStride, BitmapSource.Format.BGR8);
        }

Re: Crop an Image into 9 tiles

Posted: 10 Mar 2020, 10:37
by jsantos
ImageSource and all descendant classes like BitmapSource do not store the bits in CPU mem, the image is internally stored in a GPU texture. Reading back from the GPU is very slow and we don't provide that functionality. You need to implement this yourself at a higher level

Re: Crop an Image into 9 tiles

Posted: 10 Mar 2020, 16:24
by sfernandez
Perharps you are looking for a solution like this: viewtopic.php?f=12&t=273