What would be a quick way to transfer the contents from an array of int[,] to UInt16[]?
I am loading up the UInt16[] array for use in a BitmapSource object. The BitmapSource object is then associated with a WPF control image.Source to render it.
Ideas appreciated. It is currently taking an extremely long time.
Thanks for the replies. This is in C# so slightly preferred in that language/.NET, but open to anything that works. The copy is doing it pixel value by pixel value for a camera and is taking over 90 seconds. It would be great to get the copy/convert down to 2 seconds or less if possible (or somehow use the original array in the created bitmap). The total size is 8 megapixels. I am getting the source/original int[,] array data from the camera driver. The UInt16 is needed (or so I think) to create the bitmap used for display in the image control. It would be great if I could find a way to use the int[,] array directly without having to convert/copy it to the UInt16 array. The prototype code looks like:
//Loop that transfers "int" camera data in 2d array (from camera) to "UInt16" array. UInt16 array is needed for the bitmap used by the image control for display.
//Loop (most details of loop not shown)
...
//Core line in loop that copies/converts 1 camera value from the int[,] array to the UInt16[] array.
img2Array[i] = (UInt16)(imgArray[iYPosition, iXPosition]
...
//Destination array is put into the bitmap
BitmapSource bitmap = BitmapSource.Create(width, height,
96, 96, pf, null,
img2Array, rawStride);
//Newly created bitmap with destination array is associated with the image control for display
image1.Source = bitmap;
Maybe you could implement only this part in a C DLL. It will probably be faster than anything you can achieve with .NET. You could also make use of SSE.
By the way, I'm wondering why do you have to convert from int to Uint16?
UInt16 is used since I know it works in the Bitmapsource derived object for display within an image control (WPF). The very prototype code is as follows. This is very rough just wanted to get something that would convert the data from one source array to the destination. The 90+ seconds is in debug mode.
int i = 0;
int ImageSize= CameraXSize * CameraYSize;
while (i < ImageSize)
{
iXPosition = 0;
//Go across row doing copy/conversion
while (iXPosition < CameraXSize)
{
img2Array[i] = (UInt16)(imgArray[iYPosition, iXPosition]);//Note: x and y position appear reversed for preloaded array from driver
i++;
iXPosition++;
}
//Increment row
iYPosition++;
}
Wow this sounds like real slow performance times. You may want to look at using some multi-threaded approaches. Computers take advantage of multiple cores and a multi-threaded approach is key here. In any case, sometimes at the very least decreasing image resolution may not degrade user experience significantly in every case.
Bookmarks