回答
這裏是做的非常快,雖然不安全,道:
[編輯]這個例子了0.035毫秒
// Create 2D array of integers
int width = 320;
int height = 240;
int stride = width * 4;
int[,] integers = new int[width,height];
// Fill array with random values
Random random = new Random();
for (int x = 0; x < width; ++x)
{
for (int y = 0; y < height; ++y)
{
byte[] bgra = new byte[] { (byte)random.Next(255), (byte)random.Next(255), (byte)random.Next(255), 255 };
integers[x, y] = BitConverter.ToInt32(bgra, 0);
}
}
// Copy into bitmap
Bitmap bitmap;
unsafe
{
fixed (int* intPtr = &integers[0,0])
{
bitmap = new Bitmap(width, height, stride, PixelFormat.Format32bppRgb, new IntPtr(intPtr));
}
}
和結果:
如果有需要速度看my Kinect sample。基本上它創建一個內存區域,並使用一個不安全的指針向內存生成一個Int32數組。 BitmapSource對象用於將位圖(圖像)直接映射到同一區域。這個特殊的例子也使用非託管內存使其與P/Invoke兼容。
This blogpost描述了使用不安全的性能差異。從 部分看看:
- http://www.bytemycode.com/snippets/snippet/412/
- http://www.jmsoftware.co.uk/blog/c-snippet-for-accessing-bitmap-data-with-unsafe-code
- http://www.vcskicks.com/fast-image-processing.php
注意,您可以一樣好做的Int32 [] - 指針,而不是它使用的例子字節[] - 指針。
如果速度是不是一個問題 - 位圖+ SetPixel比保存到一個文件:
簡單,但正如你所說:慢。令人驚訝的慢! :) – 2011-02-25 05:37:32
Bitmap.LockBits
應該工作,如果你想要一個WinForms圖像。
@ozcanovunc:語法已經很完美了。你可能想閱讀關於現在的進行時態。 – 2016-05-19 15:10:45
將數組投影到base64字符串中以便流入Bitmap
也會變慢嗎?
- 1. 將整數的二維數組轉換爲灰度圖像
- 2. 如何一維數組轉換爲二維數組在C#
- 3. 將二維數組轉換爲二維數組的多個塊
- 4. OpenCV二維數組到圖像轉換
- 5. 在C#中將二維數組轉換爲單維?
- 6. 將二維圖像轉換爲三維圖像的算法
- 7. 將二維數組轉換爲二維數組列表?
- 8. 如何將c#二維數組轉換爲JSON對象?
- 9. 轉換爲二維數組
- 10. 將圖像轉換爲二維數組,然後將圖像返回到Java
- 11. 在python中將二維數組轉換爲三維數組
- 12. 將二維數組轉換爲指針
- 13. 在Python中將二進制圖像轉換爲二維數組或矩陣?
- 14. 如何將映射轉換爲java中的二維數組?
- 15. 將一維數組的索引轉換爲二維數組
- 16. 將圖像轉換爲二進制數組和二進制數組轉換爲java中的圖像
- 17. 如何將二維數組轉換成一個維數組
- 18. 如何在GO中將二維數組轉換爲一維數組?
- 19. 如何二維數組轉換成一維數組中的PHP5
- 20. C#將二維數組轉換爲數據集/數據表
- 21. 將二維數組轉換爲GAMS中的一維
- 22. 將二維numpy數組轉換爲三維數組
- 23. 將二維數組轉換爲一維數組(有條件)
- 24. 將一維數組索引轉換爲二維數組索引
- 25. 將兩個一維數組轉換爲單個二維數組
- 26. 將單個二維數組轉換爲多維數組
- 27. 將二維向量轉換爲二維數組
- 28. 如何將一維數組從數字轉換爲二維數組?
- 29. 轉換二維數組多維數組
- 30. 將Fortran多維數組轉換爲C
WinForms或WPF? – 2011-02-25 05:37:50