Using STRETCHBLT in VC will encounter some problems related to bitmap size scaling. When you extend a bitmap, StretchBlt must copy the pixel rows or columns. If the magnification is not an integer multiple of the original, then this operation causes some distortion in the resulting image.
If the destination rectangle is smaller than the source rectangle, then StretchBlt must merge the two rows (or columns) or rows (or columns) of the graph into one row (or column) when the image is zoomed out. There are four ways to do this, depending on the appliance content stretching mode property to select one of these methods. You can use the Setstretchbltmode function to modify this property.
Setstretchbltmode (hdc, IMode);
IMode the following values are desirable:
Blackonwhite or Stretch_andscans (default): If two or more graphs are merged into one, then StretchBlt performs a logical AND operation on the voxel. The result is that only the entire original voxel is white when the figure Socai to white, and its practical significance is that the black pigment controls the white pigment. This applies to monochrome bitmap images that are predominantly black in white background.
Whiteonblack or Stretch_orscans: If two or more graphs are merged into one, the STRETCHBLT performs a logical OR operation. The result is that only all of the original voxel is black, that is, the color is determined by the white pigment. This applies to a monochrome bitmap that is predominantly white in the black background.
Coloroncolor or Stretch_deletescans:stretchblt simply eliminates the rows or columns of the graph, without any logical combination. This is usually the best way to deal with color bitmap images.
The halftone or stretch_halftone:windows calculates the average color of the purpose based on the combined source color. This will be used in conjunction with a halftone palette, and the 16th chapter will show this procedure.
Color distortion sometimes occurs when you use StretchBlt to narrow a picture. The steps to resolve are as follows:
12003, Last call to CImage's StretchBlt
For example:
img. Detach (); img. Load (M_testinfo.m_stdpicutre);:: Setstretchbltmode (*pDc, halftone);:: Setbrushorgex (0 0, NULL); img. StretchBlt (198, srccopy);
Perfect solution!
or This solution:
Hbit = (hbitmap) loadimage (Null,cbmppath,image_bitmap,0,0, lr_loadfromfile); if (Hbit! = NULL) { Bitmap.attach (hbit); Dccompatible.createcompatibledc (GetDC ()); Dccompatible.selectobject (&Bitmap); Bitmap.getobject (sizeof(BM), &BM);}
2. OnPaint ():
Pdc->Setstretchbltmode (halftone); PDC--StretchBlt (map_left,map_top,map_width,map_height,&dccompatible,0, 0, bm.bmwidth,bm.bmheight,srccopy);
Solution to the problem of StretchBlt image distortion in VC + +