How i can Save Cimage file+ shapes & text on it?
-
i load an Cimage file in my SDI MFC (non View/Doc arch.) application & draw some shapes & text on it... tell me how i can save both shapes,texts & CImage in any (jpg,bmp) file format... :confused:
I got the answer to this problem while trying to solve my problem:
CImage image;
// Draw on image...
HRESULT hr = image.Save(_T("C:\\test.jpg"), Gdiplus::ImageFormatJPEG);
-
I got the answer to this problem while trying to solve my problem:
CImage image;
// Draw on image...
HRESULT hr = image.Save(_T("C:\\test.jpg"), Gdiplus::ImageFormatJPEG);
-
i'm drawing shapes on it(like circle,rectangle etc) using OnPaint(); .... will it work now?? :confused:
No; when you use the CDC in OnPaint, your drawing is going to the screen. To draw on a bitmap you need to select the bitmap into a device context, then draw on that device context. Like:
CDC \*mdc = GetDC (); HGDIOBJ tmp = mdc->SelectObject(hbm); // hbm is a handle of a bitmap. // Draw on mdc, e.g. mdc->TextOutW (50, 50, L"Testing..."); image.Attach (hbm); HRESULT hr = image.Save(\_T("C:\\\\test.tif"), Gdiplus::ImageFormatTIFF);
-
No; when you use the CDC in OnPaint, your drawing is going to the screen. To draw on a bitmap you need to select the bitmap into a device context, then draw on that device context. Like:
CDC \*mdc = GetDC (); HGDIOBJ tmp = mdc->SelectObject(hbm); // hbm is a handle of a bitmap. // Draw on mdc, e.g. mdc->TextOutW (50, 50, L"Testing..."); image.Attach (hbm); HRESULT hr = image.Save(\_T("C:\\\\test.tif"), Gdiplus::ImageFormatTIFF);
-
CPaintDC is derived from CDC, so you can perform all the same operations on it. It's an object rather than a pointer, so you have to use "." to invoke methods instead of "->". You can select a bitmap into the CPaintDC:
dc.SelectObject (hbm);
Where hbm is the handle of a bitmap. You can also select a pointer to a CBitmap. (I don't see an overload for CImage). You then use the drawing methods of CDC. Then (as in my example) you can attach your bitmap to a CImage object, and save it. There may be a better way of doing this, but this should work.
-
CPaintDC is derived from CDC, so you can perform all the same operations on it. It's an object rather than a pointer, so you have to use "." to invoke methods instead of "->". You can select a bitmap into the CPaintDC:
dc.SelectObject (hbm);
Where hbm is the handle of a bitmap. You can also select a pointer to a CBitmap. (I don't see an overload for CImage). You then use the drawing methods of CDC. Then (as in my example) you can attach your bitmap to a CImage object, and save it. There may be a better way of doing this, but this should work.
-
hbm is a handle to a bitmap. The Windows type is HBITMAP.
-
hbm is a handle to a bitmap. The Windows type is HBITMAP.
-
Use CreateCompatibleBitmap (): http://msdn.microsoft.com/en-us/library/dd183488%28VS.85%29.aspx[^] In your OnPaint method, you have a device context, which can be used to create a compatible bitmap. You can then draw on this bitmap, then attach it to a CImage object and save it.