Microsoft KB Archive/168743

From BetaArchive Wiki
< Microsoft KB Archive
Revision as of 11:29, 21 July 2020 by X010 (talk | contribs) (Text replacement - "&" to "&")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Using HALFTONE Stretching with COLORADJUSTMENT

Q168743



The information in this article applies to:


  • Microsoft Win32 Application Programming Interface (API), used with:
    • Microsoft Windows NT Server versions 3.5, 3.51, 4.0
    • Microsoft Windows NT Workstation versions 3.5, 3.51, 4.0
    • Microsoft Windows 95
  • Microsoft Windows 2000 Advanced Server
  • Microsoft Windows 2000 Server
  • Microsoft Windows 2000 Professional





SUMMARY

This sample demonstrates how to use the HALFTONE stretch mode and some of the effects that can be generated by using it.

The following file is available for download from the Microsoft Download Center:


Halftone.exe

For additional information about how to download Microsoft Support files, click the article number below to view the article in the Microsoft Knowledge Base:

Q119591 How to Obtain Microsoft Support Files from Online Services

Microsoft used the most current virus detection software available on the date of posting to scan this file for viruses. Once posted, the file is housed on secure servers that prevent any unauthorized changes to the file.



The following files are a contained in Halftone.exe:

  • Palette.h Palette.C - Contains all of the functions relating to creating and manipulating Windows palettes.
  • DIB.h DIB.c - Contains all of the code for loading and converting DIBs and DDBs.
  • HALFTONE.h HALFTONE.c - Contains the UI and the code demonstrating halftone stretching and COLORADJUSTMENT.



MORE INFORMATION

In many cases it is necessary to display bitmaps or DIBs that have a greater bit depth than your current display mode. To account for this, GDI has to remap the colors your bitmap uses into the colors that are available. This remapping process can be slow and often produces unsatisfactory results. A simple way to produce high quality representations of your original image is to ask GDI to dither the image into the palette selected into the target DC. To get GDI to dither the image you need to use the SetStretchBltMode() API and specify the target DC and the HALFTONE flag. Now, when you want to display your bitmap into the target DC, all you have to do is use StretchBlt() or StretchDIBits() rather than BitBlt() or SetDIBits(). For example:

   SetStretchBltMode(hdcTarget, HALFTONE);
   StretchBlt(hdcTarget, 0,0,dwWidth,dwHeight,

                   hdcSource, 0,0,dwWidth,dwHeight, SRCCOPY); 

When you use the HALFTONE stretch mode, it is possible to apply a filter that alters the way GDI processes the color information from the source image. This makes it possible to not only lighten or darken the image but also apply more complex image filters. To specify a filter you use the SetColorAdjustment() API and pass it the target DC and a pointer to a COLORADJUSTMENT record. The COLORADJUSTMENT structure defines the color adjustment values used by the StretchBlt() and StretchDIBits() functions when the stretch mode is HALFTONE. For example:

   SetColorAdjustment(hdcTarget, &caFilter); 

After you build the sample, run it, and then load a .bmp file. Once the file is loaded, you can use "adjust the halftone properties" and see the effects on the bitmap.

Additional query words:

Keywords : kbfile kbprogramming kbOSWinNT350 kbOSWinNT351 kbOSWinNT400 kbOSWin2000 kbOSWin95 kbSDKWin16
Issue type : kbinfo
Technology : kbAudDeveloper kbWin32sSearch kbWin32API


Last Reviewed: December 16, 2000
© 2001 Microsoft Corporation. All rights reserved. Terms of Use.