|
1 Create a memory DC( CreateCompatibleDC )
2 Select the bitmap to that dc ( memdc.SelectObject )
3 Draw your lines/shapes to that DC.
4 Unselect the bitmap from dc.
Now your original bitmap will be having the drawings...
|
|
|
|
|
Hi naveen
Thanks for your replay .. i tried
HDC pDC=::GetDC(0);
HDC TmpDC=CreateCompatibleDC(pDC);
CImage _image;
_image.Load(_T("//read.tif"));
CRect Recto(20, 20, 20, 20);
int width=_image.GetWidth();
int height=_image.GetHeight();
HDC dcBmp=CreateCompatibleDC(TmpDC);
HGDIOBJ TmpObj2 = SelectObject(dcBmp,(HGDIOBJ)_image);
BitBlt(TmpDC,0,0,width,height,dcBmp,0,0,SRCCOPY);
SelectObject(TmpDC,TmpObj2);
DeleteDC(dcBmp);
but its not showing the rectangles in image ..??
plz reply
~~~~~~~~~~~~~Raju~~~~~~~~~~~~~
|
|
|
|
|
You could try changing the line
SelectObject(dcBmp,(HGDIOBJ)_image);
with
SelectObject(dcBmp,(HGDIOBJ)(HBITMAP)_image);
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
its not working "superman"
its not showing any effect on images till the same image ...
~~~~~~~~~~~~~Raju~~~~~~~~~~~~~
|
|
|
|
|
Check are return values for errors.
There was probably some error encountered at Load or one of earlier functions called.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
No its not showing any error msg ...
i dont know why ..??
please
~~~~~~~~~~~~~Raju~~~~~~~~~~~~~
|
|
|
|
|
you said you want to draw some lines and shapes. But the above code is not doing any of that.
rajugis wrote: HDC dcBmp=CreateCompatibleDC(TmpDC); HGDIOBJ TmpObj2 = SelectObject(dcBmp,(HGDIOBJ)_image); BitBlt(TmpDC,0,0,width,height,dcBmp,0,0,SRCCOPY);
What the above code does is copy the image in dcBmp to TmpDC. The dcBmp has your image, but the target dc TmpDC doesnt have any bitmap selected into it. So basically that BitBlt function does nothing. To have a valid image in the TempDC, you have to select one bitmap to that dc. Check the below code(especially the one in the bold ). The hBmp conatins the final image.
HDC dcBmp=CreateCompatibleDC(pDC);
HBITMAP hBmp = CreateCompatibleBitmap(pDC, 20,20);
HGDIOBJ OldBmp = SelectObject(TmpDC,(HGDIOBJ)hBmp);
HGDIOBJ TmpObj2 = SelectObject(dcBmp,(HGDIOBJ)_image);
BitBlt(TmpDC,0,0,width,height,dcBmp,0,0,SRCCOPY);
SelectObject(dcBmp,TmpObj2);
SelectObject(TmpDC,OldBmp);
|
|
|
|
|
hi Naveen
Still its not drawing rectangles in image ...plz mention where i can correct it ..??
HDC pDC=::GetDC(0);
HDC TmpDC=CreateCompatibleDC(pDC);
CImage _image;
_image.Load(_T("read.tif"));
int width=_image.GetWidth();
int height=_image.GetHeight();
HDC dcBmp=CreateCompatibleDC(pDC);
HBITMAP hBmp = CreateCompatibleBitmap(pDC, 20,20);
HGDIOBJ OldBmp = SelectObject(TmpDC,(HGDIOBJ)hBmp);
BitBlt(TmpDC,0,0,width,height,dcBmp,0,0,SRCCOPY);
SelectObject(TmpDC,OldBmp);
please replay me !!!!!!!1
~~~~~~~~~~~~~Raju~~~~~~~~~~~~~
|
|
|
|
|
rajugis wrote: Still its not drawing rectangles in image ...plz mention where i can correct it ..??
Where is the code to draw a rectangle?
rajugis wrote: //HGDIOBJ hgdiobj = SelectObject(TmpDC,(HGDIOBJ)_image);
Why did you comment it? Also correct this line as SuperMan mentioned.
HGDIOBJ hgdiobj = SelectObject(TmpDC,(HGDIOBJ)(HBITMAP)_image);
|
|
|
|
|
Sorry to say naveen ..really i dont know the rectangle code..
~~~~~~~~~~~~~Raju~~~~~~~~~~~~~
|
|
|
|
|
try the below code. If everthing goes fine, it will draw a rectangle on the top left portion of the image;
HDC pDC=::GetDC(0);
HDC TmpDC=CreateCompatibleDC(pDC);
CImage _image;
_image.Load(_T("//read.tif"));
int width=_image.GetWidth();
int height=_image.GetHeight();
HGDIOBJ TmpObj2 = SelectObject(TmpDC,(HGDIOBJ)(HBITMAP)_image);
Rectangle(TmpDC, 0,0, width/2, height/2 );
SelectObject(TmpDC,TmpObj2);
ReleaseDC(pDC);
|
|
|
|
|
ReleaseDC(pDC);
Showing Error message naveen like
error C2664: 'CWnd::ReleaseDC' : cannot convert parameter 1 from 'HDC' to 'CDC *'
~~~~~~~~~~~~~Raju~~~~~~~~~~~~~
|
|
|
|
|
modify
::ReleaseDC(0, pDC);
|
|
|
|
|
its execute completly with out error but its not creating any rectangle in image... naveen ...
HGDIOBJ TmpObj2 = SelectObject(TmpDC,(HGDIOBJ)(HBITMAP)_image);
Rectangle(TmpDC, 0,0, width/2, height/2 );
SelectObject(TmpDC,TmpObj2);
::ReleaseDC(NULL,pDC);
any need to create the new bitmap for this HGDIOBJ TmpObj2 ..??
~~~~~~~~~~~~~Raju~~~~~~~~~~~~~
|
|
|
|
|
How did u verify that no rectangle is coming..?
|
|
|
|
|
just i save the image like read.tif ..its not show the rectangle so that??
~~~~~~~~~~~~~Raju~~~~~~~~~~~~~
|
|
|
|
|
hope you saved the image like the code below
_image.Save( _T("c:\\abcd2.bmp"), Gdiplus::ImageFormatBMP );
|
|
|
|
|
thanks naveen ...i never forget this help
i would like say ..please add my name to your friends list please .
~~~~~~~~~~~~~Raju~~~~~~~~~~~~~
|
|
|
|
|
rajugis wrote: thanks naveen
Your are welcome.
|
|
|
|
|
hi Naveen ..is that any possible for create the rectangle in Color??
~~~~~~~~~~~~~Raju~~~~~~~~~~~~~
|
|
|
|
|
Yes. check MSDN[^]. It says, "The current pen outlines the rectangle and the current brush fills it. ".
so create the brush of desired color, select it to the DC and then draw
|
|
|
|
|
one small doubt naveen ....
i want to show only the cutting image portion ..but the output image contains only the except cutting image portion.
??
~~~~~~~~~~~~~Raju~~~~~~~~~~~~~
|
|
|
|
|
What? I didnt understand..
|
|
|
|
|
u assume ...that
one image file contains 5 buildings ..i want to cut and save only the 5th building ,other buildings are not shown in the image.
but when we are save the image 5th building not shown other four buildings are shown in the image...
~~~~~~~~~~~~~Raju~~~~~~~~~~~~~
|
|
|
|
|
When I'm working with DC's and Bitmaps, and BitBlts, I like to use the following utility from PJ Arends.
Image Viewer Utility[^]
It lets you debug your code, and see the results of image changes like a variable in a watch window.
Very handy, and a shame PJ isn't around CP anymore. (OK, hardly ever)
Iain.
I have now moved to Sweden for love (awwww).
If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), or need cotract work done, give me a job! http://cv.imcsoft.co.uk/[ ^]
|
|
|
|