Re: SetBitmapBits fails - why?



Kevin wrote:
In this code snippet....


void TForm1::DisplayFrame(void) {

     FindMinMax();

    int i;

    // copy the raw data to the bitmap while applying contrast adjustment
    for(i = 0; i < rows * cols; i++)
    {
          pBitmapPixels[i] = Contrast(pRawPixels[i], PixMin, PixMax) *
0x010101;
     }

     SetBitmapBits(pbitmap, rows * cols * 4, pBitmapPixels);

    Form2->Canvas->Draw(0, 0, pbitmap);

}

occasionally the function SetBitmapBits(...) fails, it returns zero. Anybody
know why?

No, but why are you not checking the return value? All return values should always be checked. When it fails just do it again.

Also, the 4 in "rows * cols * 4" should really be
replaced with something like sizeof(*pbitmap).

--
Regards,
Martin Leese
E-mail: please@xxxxxxxxxxxxxxxxxxxxxxxxxx
Web: http://members.tripod.com/martin_leese/
.



Relevant Pages

  • Re: New version of John Hayes tester
    ... and the absolute test passes. ... But zero is special -- there's no way to say that a nonzero x is ... The above F= test is superfluous unless ABS-NEAR is set to zero. ... = y and relative comparison fails in which I wouldn't want to ...
    (comp.lang.forth)
  • Re: when can realloc fail?
    ... But a call to realloc() with size set to zero is equivalent to free, ... All we're told is that realloceither fails or it ...
    (comp.lang.c)
  • Re: TStringGrid
    ... >is thrown if it fails. ... I think that code was written in dubious mode ... - silent errors are tricky ... - I've just checked and it looks for Zero write bytes before writing ...
    (alt.comp.lang.borland-delphi)
  • Re: division by 7 without using division operator
    ... integer for which it fails? ... It depends on the implementation's precision and the rounding mode. ... the exact difference ... towards zero, ...
    (comp.lang.c)
  • Re: .999... ?= 1
    ... >>value zero, no matter whether it is seen from the left or from the right. ... > Mathematics", by Chris Mortensen? ... > fails). ... at least as concerns the practical needs. ...
    (sci.math)