c++ - Scaling bitmap output distorts image -



c++ - Scaling bitmap output distorts image -

i have 2752x2200 bitmap image. can display 1/3 of on mfc dialog box (for obvious size issues), if don't scale image top-left 917x733 block (the top-left 1/3 block). want zoom image out factor of 3 whole image dislayed in area size of 1/3 of image. have set grayscale bitmap so:

////////////////////////////////////////////////////////////////////////// ////////// setup bitmap //////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// //// fileheader //// bitmapfileheader* bf = new bitmapfileheader; bf->bftype = 0x4d42; bf->bfsize = 6054400 + 54 + sizeof(bitmapinfo); bf->bfoffbits = 54; //// infoheader //// bitmapinfoheader* bi = new bitmapinfoheader; bi->bisize = 40; bi->biwidth = 2752; bi->biheight = -2200; bi->biplanes = 1; bi->bibitcount = 8; bi->bicompression = 0; //bi->bisizeimage = 6054400; //not required bi->bixpelspermeter = 2835; bi->biypelspermeter = 2835; bi->biclrused = 0; bi->biclrimportant = 0; //// info //// bitmapinfo* pbmi = (bitmapinfo*)alloca( sizeof(bitmapinfoheader) + sizeof(rgbquad)*256); pbmi->bmiheader.bisize = sizeof (pbmi->bmiheader); pbmi->bmiheader.biwidth = 2752; pbmi->bmiheader.biheight = -2200; pbmi->bmiheader.biplanes = 1; pbmi->bmiheader.bibitcount = 8; pbmi->bmiheader.bicompression = bi_rgb; pbmi->bmiheader.bisizeimage = 0; pbmi->bmiheader.bixpelspermeter = 14173; pbmi->bmiheader.biypelspermeter = 14173; pbmi->bmiheader.biclrused = 0; pbmi->bmiheader.biclrimportant = 0; //create grayscale color palette for(int i=0; i<256; i++) { pbmi->bmicolors[i].rgbred = i; pbmi->bmicolors[i].rgbgreen = i; pbmi->bmicolors[i].rgbblue = i; pbmi->bmicolors[i].rgbreserved = 0; } //// image info //// pframe->getimage(m_imagedata); ////////////////////////////////////////////////////////////////////// ////// create image that's printed dialog box ///////////////////// ////////////////////////////////////////////////////////////////////// hdc hdc = ::getdc(null); hbit = createdibitmap(hdc, bi, cbm_init, m_imagedata, pbmi, dib_rgb_colors);

and i'm drawing bitmap onto dialog box this:

bitmap* bi = new bitmap; cbitmap bmp; bmp.attach(hbit); cclientdc dc(pwnd); cdc bmdc; bmdc.createcompatibledc(&dc); cbitmap *poldbmp = bmdc.selectobject(&bmp); bmp.getbitmap(bi); dc.stretchblt(384,21,bi->bmwidth,bi->bmheight,&bmdc,0,0, bi->bmwidth,bi->bmheight,srccopy); bmdc.selectobject(poldbmp);

the image looks fine code, it's top left block of total image:

in effort scale image down, changed line:

dc.stretchblt(384,21,bi->bmwidth,bi->bmheight,&bmdc,0,0, bi->bmwidth,bi->bmheight,srccopy);

to:

dc.stretchblt(384,21,bi->bmwidth/3,bi->bmheight/3,&bmdc,0,0, bi->bmwidth,bi->bmheight,srccopy); // 1/3 original size

now output looks zoomed out , it's showing whole image(good), looks distorted (bad):

(note circular rings around border of image. shouldn't there , when see live video of image stream, pulsate , ruin image).

my question is: what causing distortion , there simple can prepare it?

edit: after trying stretchdibits():

stretchdibits(dc.m_hdc, 384, 21, bi->bmwidth/3, bi->bmheight/3, 0, 0,bi->bmwidth,bi->bmheight, myobv->getimagedata(), myobv->getpbmi(), dib_rgb_colors, srccopy);

my output looked this:

i.imgur.com/da49p8x.png

if zooming bitmap, windows api may not perform visually because designed optimized performance. add together next line before stretchblt enhance bitmap operation:

setstretchbltmode(dc.m_hdc, halftone);

c++ image mfc bitmap

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -