Click here to Skip to main content
15,891,597 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
Hi to all ,
actually i am developing a paint brush type App where i need to do few editing on the image and now I have to save it to the disk . Now how should I proceed ?
Posted

If you have the device context of the window (for instance inside the OnPaint handler), namely dc:

C++
CDC dcMem;
CBitmap bmp;
CRect rc;
CImage img;

dcMem.CreateCompatibleDC(&dc);
GetWindowRect(&rc);
bmp.CreateCompatibleBitmap( &dcMem, rc.Width(), rc.Height());
dcMem.SelectObject(&bmp);
dcMem.BitBlt(0,0,rc.Width(), rc.Height(), &dc, 0,0, SRCCOPY);

img.Attach(bmp);
img.Save(_T("MyBitmap.bmp"), Gdiplus::ImageFormatBMP);
 
Share this answer
 
Comments
iampradeepsharma 6-Jun-11 23:35pm    
Image is not recognised ... so how to proceed then
CPallini 7-Jun-11 3:47am    
What do you mean? Could you elaborate, please (I've made a test, the provided code is working fine on my system)?
hello

try to replace
img.Attach(bmp);
by
img.Attach((HBITMAP)(bmp->GetSafeHandle()));

Jack
 
Share this answer
 
You should continue working... :rolleyes:

Seriously, you should tell us more things... if you are already working on an app like that one you should tell us what you've achieved, where are you stuck...

In order to store images to disk you should be aware of the fact that each image format has its own way to be stored. So first of all you should decide the target format and therefore you should decide which format do you want to use...

After that you will have to control the mouse events, movements and buttons in order to be able to draw...

Then you will be in the need of drawing into the screen and being able to capture the drawing you've made in memory in order to be able to store it to disk (using the right format).

Depending on the editing you will need a lot of maths to proceed... but...

well... tell us more about the project... which problems you have...
 
Share this answer
 
Comments
CPallini 6-Jun-11 5:51am    
[Moved from OP fake answer]:
@John actually I am currently working such a task , so far what I have achieved is that : its an SDI App (in MFC) .
I can open a file through the direct tool and have managed to render a .jpg image onto the view . Now i can draw few shapes like ellipse thru the drag mouse event , ok that 's too done . Now I want to save that active view as an document on disk . How can i do that ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900