Monday, April 16, 2012

Avoiding cast when using CImage

Recently I have seen a few people telling others that if they need to cast they are doing something wrong. I have this code in C++



byte* pixel = (byte*)image->GetBits();


Here I cast to a byte* because GetBits() returns a void*. So how would I either




  • have pixel hold a byte* without casting

  • use void* (I have never used this type before)



To clarify, I then go on to use pixel similar to this.



*(pixel) += 20;
*(pixel + 1) += 20;
*(pixel + 2) += 20;




No comments:

Post a Comment