Answered by:
Why are SetPixel and GetPixel so slow ? 为什么SetPixel和GetPixel这厮如此龟速?

Question
-
Why are SetPixel and GetPixel so slow ? But if I put bmpdata to a byteArray, and do something, and copy them back to bitmap, the speed would quickly. Why ?
为什么SetPixel和GetPixel这厮如此龟速?如果我把bmpdata先放到byte数组里,然后做一些处理,最后拷贝回bitmap,速度就灰常快,为神马?
What did SetPixel and GetPixel do ??
SetPixel和GetPixel这厮究竟在背后做了些神马?
- Edited by 蛋疼喵咪 Saturday, January 22, 2011 1:48 PM FixWords
Saturday, January 22, 2011 1:45 PM
Answers
-
>if I put bmpdata to a byteArray, and do something, and copy them back to bitmap
That is what SetPixel does, with "something" changed to "change one pixel"
If you have more than one pixel to change with SetPixel. You are just creating and discarding extra intermediate bitmaps for no benefit except code readablity.
The following is signature, not part of post
Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
Visual C++ MVP- Proposed as answer by Leo Liu - MSFT Thursday, January 27, 2011 3:19 AM
- Marked as answer by Leo Liu - MSFT Friday, January 28, 2011 2:50 PM
Saturday, January 22, 2011 5:43 PM -
If you want speed, try locking the bitmap and using bitmapdata.
It is unsafe code and requires pointers, but you will see a huge improvement in speed.
- Proposed as answer by Leo Liu - MSFT Thursday, January 27, 2011 3:20 AM
- Marked as answer by Leo Liu - MSFT Friday, January 28, 2011 2:50 PM
Saturday, January 22, 2011 7:16 PM
All replies
-
>if I put bmpdata to a byteArray, and do something, and copy them back to bitmap
That is what SetPixel does, with "something" changed to "change one pixel"
If you have more than one pixel to change with SetPixel. You are just creating and discarding extra intermediate bitmaps for no benefit except code readablity.
The following is signature, not part of post
Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
Visual C++ MVP- Proposed as answer by Leo Liu - MSFT Thursday, January 27, 2011 3:19 AM
- Marked as answer by Leo Liu - MSFT Friday, January 28, 2011 2:50 PM
Saturday, January 22, 2011 5:43 PM -
If you want speed, try locking the bitmap and using bitmapdata.
It is unsafe code and requires pointers, but you will see a huge improvement in speed.
- Proposed as answer by Leo Liu - MSFT Thursday, January 27, 2011 3:20 AM
- Marked as answer by Leo Liu - MSFT Friday, January 28, 2011 2:50 PM
Saturday, January 22, 2011 7:16 PM