PRB: Image Functions Fail with Image Outside of Viewport

Last reviewed: July 22, 1997
Article ID: Q118682
7.00 | 1.00 1.50 MS-DOS | WINDOWS kbprg kbprb

The information in this article applies to:

  • The C Run-time (CRT), included with:

        - Microsoft C/C++ for MS-DOS, version 7.0
        - Microsoft Visual C++ for Windows, versions 1.0 and 1.5
    

SYMPTOMS

The GRAPHICS.LIB image functions _putimage, _getimage(), _putimage_w(), and getimage_w() fail when the specified image falls outside the current viewport. Calling _grstatus() in this instance returns _GRERROR.

CAUSE

Though it is not documented anywhere else, this behavior is by design. The functions listed above fail when you attempt to place even part of an image outside the viewport. Images are never clipped to the viewport.

RESOLUTION

Do not attempt to place images outside of the current viewport. Either make the viewport larger or work with partial (smaller) images.

MORE INFORMATION

The following program shows common mistakes that cause _getimage and _putimage to fail:

Sample Code

   /* Compile options needed: none
   */

   #include <stdio.h>
   #include <conio.h>
   #include <malloc.h>
   #include <graph.h>

   main()
   {
      char __huge *buffer;     // image buffer
      long buff_size;          // size of the image
      struct _videoconfig vc;

      if (!_setvideomode(_VRES16COLOR))
      {
         printf("Can\'t set video mode\n");
         exit(1);
      }

      _getvideoconfig(&vc);

    // error - should go to vc.numxpixels-1 and vc.numypixels-1
    // however _imagesize will just return a larger buffer as needed

      buff_size = _imagesize( 0,0,vc.numxpixels,vc.numypixels );
      buffer = (char __huge *) _halloc( buff_size, sizeof( char ) );
      if (buffer == (char __huge *) NULL)
      {
         printf("halloc failed allocating %ld bytes\n", buff_size);
         _getch();
         _setvideomode(_DEFAULTMODE);
         exit(1);
      }

    // error - should go to vc.numxpixels-1 and vc.numypixels-1

      _getimage( 0, 0, vc.numxpixels, vc.numypixels, buffer );
      if (_grstatus() < _GROK)
      {
         printf("Getimage error %d\n",_grstatus());
         _getch();
         _setvideomode(_DEFAULTMODE);
         exit(1);
      }

      _setvieworg( vc.numxpixels/2, vc.numypixels/2 );

    // error - we've translated the origin so vc.numxpixels-1 and
    // vc.numypixels-1 are out of range

      _getimage( 0, 0, vc.numxpixels-1, vc.numypixels-1, buffer );
      if (_grstatus() < _GROK)
      {
         printf("Getimage error %d\n",_grstatus());
         _getch();
         _setvideomode(_DEFAULTMODE);
         exit(1);
      }
      _setvideomode(_DEFAULTMODE);
   }


Additional reference words: 7.00 1.00 1.50
KBCategory: kbprg kbprb
KBSubcategory: CRTIss GraphicsIss
Keywords : kb16bitonly


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 22, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.