Click to See Complete Forum and Search --> : Problem in Stretching the Drawn image


kingslee
December 1st, 2005, 11:41 AM
Dear Friends,
I am doing a project - in which i have an array of points world coordinates. Using that I Draw the image using SetPixel(). After that using rectangle tool in the menu, User select on the image to get the coordinates, on which the measurement should take place

The problem is now I wanna increase the image size ,like increasing the individual pixel size or increasing the scaling factor in a Graph.

For your kind view, I attach the project here.(visual c++ 6.0)

Please help me in this regard.

cheers
kingsly

Marc G
December 1st, 2005, 03:45 PM
You can use StretchBlt (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/bitmaps_9cok.asp) or StretchDIBits (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/bitmaps_1ppv.asp) to stretch an image and use SetStretchBltMode (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/bitmaps_6cth.asp) to change the quality of the scaling.

Note: using SetPixel is generally not a good idea because it's pretty slow. It's much beter to work directly into the memory buffer for the image. You can get the pixel array from an existing bitmap with GetDIBits (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/bitmaps_7gms.asp) or you can create your bitmap withCreateDIBSection (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/bitmaps_233i.asp) which returns the HBITMAP and a pointer to the pixel buffer which you can manipulate.

kingslee
December 1st, 2005, 08:02 PM
Thank you Marc G for your info.

As I am newbie, I find little bit difficult in implementing this. But I try maximum and get back to you.

Once again thankyou for your help

cheers
kingsly

golanshahar
December 2nd, 2005, 10:53 AM
you can look at this thread:
Bitmap in CStatic (http://www.codeguru.com/forum/showthread.php?t=366031).
it demonstrates how to use ::StretchDIBits(..).

Cheers

kingslee
December 3rd, 2005, 08:16 PM
Thankyou golanshahar for your info..

I am workin on it. I have some basic doubts

1. If we zoom the object, will the coordinates changes accordingly to the
window or what?- Hope my question is clear (so that I can get the
same coordinates as in original size when its in enlarged mode)

2. I tried to use CreateDIBSection()... which has lot and lot of parameters
which I dont know how to pass... For Setpixel() I just pass the window
coordinates and the color.

Is that, for zooming a painted operation should be a bitmap? because my application is small paint operation.

Sorry! if I'm asking too many questions...

Waiting for your reply guys--

cheers

kingslee
December 4th, 2005, 08:10 PM
hallo,
sorry for asking again and again ..

I dont have a file which contains bitmap data.

the text file i have , just give the coordinate of the object from the world coordinates..

so that, i used setpixel to display the image..

can any one please help me in making the object full screen..

waiting for your reply.

Marc G
December 5th, 2005, 03:24 AM
Start by learning how to use CreateDIBSection.
There are some samples in the MSDN that uses CreateDIBSection. Perhaps you can look at them to try to understand how they work:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcsample/html/_sample_mfc_FIRE.asp
or
http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/Q94/3/26.ASP&NoWebContent=1

When you use CreateDIBSection you'll get a pixel buffer. You can then simply write pixel data into that buffer. For example: if your pixel buffer is called pBuff, you can do the following:
pBuff[0] = 255;
pBuff[1] = 0;
pBuff[2] = 0;
Which will set the first pixel to blue. Remember that bitmap buffers in windows are BGR(A) and not RGB(A).

Once you've done that, you can use StretchDIBits (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/bitmaps_1ppv.asp) to blit and stretch your image.