|
Hi All
how to create new bitmap ?
~~~~~~~~~~~~~Raju~~~~~~~~~~~~~
|
|
|
|
|
By selecting 'New' from the file menu.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
~~~~~~~~~~~~~Raju~~~~~~~~~~~~~
|
|
|
|
|
Please provide a bit more information about what you mean because otherwise we won't be able to help.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
i have one image file which contains 5 buildings ..i want to cut and save only the 5th building ,other four 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...
this is my code snippet::
<code>
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);
_image.Save( _T("D:\\newy.jpg"), Gdiplus::ImageFormatBMP);
::ReleaseDC(NULL,pDC);
</code>
~~~~~~~~~~~~~Raju~~~~~~~~~~~~~
|
|
|
|
|
So let me get this right, you open a tif file, draw a rectangle on it that is suposed to overlap some part of the picture and then you save the image to another file, right? (Btw why do you specify Gdiplus::ImageFormatBMP for the Save call while you are trying to save a jpg?) Your problem is that not the part of the image is overlapped you want? Why don't you move the rectangle then?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
how to create one rectangle piece of image from existing image??
this is doubt
~~~~~~~~~~~~~Raju~~~~~~~~~~~~~
|
|
|
|
|
Ah well, create a new bitmap in memory with the required size, blit from the source image to the target image the part you want to cut out and then save this new bitmap.
So something like this:
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);
int newWidth = width/2;
int newHeight = height/2;
HDC NewDC = CreateCompatibleDC(TmpDC);
HBITMAP NewBitmap = CreateCompatibleBitmap(TmpDC, newWidth, newHeight);
HGDIOBJ NewTmpObj = SelectObject(NewDC, NewBitmap);
BitBlt(NewDC, 0, 0, newWidth, newHeight, TmpDC, 0, 0, SRCCOPY);
SelectObject(NewDC, NewTmpObj);
DeleteDC(NewDC);
SelectObject(TmpDC,TmpObj2);
::ReleaseDC(NULL,pDC);
CImage newImage;
newImage.Attach(NewBitmap);
newImage.Save( _T("D:\\newy.jpg"), Gdiplus::ImageFormatJPEG);
DeleteObject(NewBitmap);
I am not saying this code works or if it compiles at all, but it can be a starting point for you to get the idea, good luck.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
Hi,
I saw (from your posts) that you are using CImage class. So if you need to copy the loaded image to the new one you can use the BitBlt() method of CImage .
Here is the code fragment to create a copy of given original image:
CImage imageOriginal;
imageOriginal.Load(_T("Here is the path to your original image"));
CImage imageNew;
imageNew.Create(imageOriginal.GetWidth(), imageOriginal.GetHeight(), imageOriginal.GetBPP());
imageOriginal.BitBlt(imageNew.GetDC(), CPoint(0,0));
imageNew.ReleaseDC();
....
The above example makes an exact copy of the loaded image.
If you need to copy the specific part of the loaded image, for instance a rectangular part, then you can use the BitBlt() method again, but this time the code could be something like this:
CImage imageOriginal;
imageOriginal.Load(_T("Here is the path to your original image"));
CRect rectCopy(0, 0, imageOriginal.GetWidth() / 2, imageOriginal.GetHeight() / 2);
CImage imageNew;
imageNew.Create(rectCopy.Width(), rectCopy.Height(), imageOriginal.GetBPP());
imageOriginal.BitBlt(imageNew.GetDC(), rectCopy, rectCopy.TopLeft());
imageNew.ReleaseDC();
I hope this helps!
Nuri Ismail
|
|
|
|
|
CImage imageOriginal;
imageOriginal.Load(_T( "read.tif" ));
<code>CRect rectCopy(9177,68, 10566, 635);</code>
CImage imageNew;
imageNew.Create(rectCopy.Width(), rectCopy.Height(), imageOriginal.GetBPP());
imageOriginal.BitBlt(imageNew.GetDC(), rectCopy, rectCopy.TopLeft());
imageNew.Save(_T("D://imgnew.jpg"));
imageNew.ReleaseDC();
when i gave this rect portion ..the saving images contains ..full black
~~~~~~~~~~~~~Raju~~~~~~~~~~~~~
|
|
|
|
|
rajugis wrote: when i gave this rect portion ..the saving images contains ..full black
I think this problem could occur when your original image is indexed. You can read about indexed colors here[^].
If we want to copy indexed images we have to copy their color tables too. We can easily do this with CImage class.
First we have to check if the image is indexed and if it is than copy its color table, just like that:
if(imageOriginal.IsIndexed())
{
const int nMaxColors = imageOriginal.GetMaxColorTableEntries();
RGBQUAD* pColorTable = new RGBQUAD[nMaxColors];
imageOriginal.GetColorTable(0, nMaxColors, pColorTable);
imageNew.SetColorTable(0, nMaxColors, pColorTable);
delete [] pColorTable;
}
This code must be inserted after the creation of the new image. I've made a test application and it works fine for me for both indexed and on-indexed TIFFs. Here is the complete method:
void CTestCImageAppDlg::OnBnClickedButtonTest()
{
CImage imageOriginal;
HRESULT hrLoad = imageOriginal.Load(_T("D:\\testImg1.tif"));
if(FAILED(hrLoad))
{
CString msg;
msg.Format(_T("Error on load. Code:%08x"), hrLoad);
AfxMessageBox(msg);
return;
}
CRect rectCopy(0, 0, imageOriginal.GetWidth() / 2, imageOriginal.GetHeight() / 2);
CImage imageNew;
imageNew.Create(rectCopy.Width(), rectCopy.Height(), imageOriginal.GetBPP());
if(imageOriginal.IsIndexed())
{
const int nMaxColors = imageOriginal.GetMaxColorTableEntries();
RGBQUAD* pColorTable = new RGBQUAD[nMaxColors];
imageOriginal.GetColorTable(0, nMaxColors, pColorTable);
imageNew.SetColorTable(0, nMaxColors, pColorTable);
delete [] pColorTable;
}
CRect rect(rectCopy);
rect.OffsetRect(-rectCopy.left, -rectCopy.top);
imageOriginal.BitBlt(imageNew.GetDC(), rect, rectCopy.TopLeft());
imageNew.ReleaseDC();
HRESULT hrSave = imageNew.Save(_T("D:\\testImg2.tif"), Gdiplus::ImageFormatTIFF);
if(FAILED(hrSave))
{
CString msg;
msg.Format(_T("Error on save. Code:%08x"),hrSave);
AfxMessageBox(msg);
return;
}
}
I hope this helps you.
Regards
Nuri Ismail
modified on Thursday, September 17, 2009 4:12 AM
|
|
|
|
|
wow ..its great ...
thanks for your help ...............
really thanks Nuri !!!!!!11
~~~~~~~~~~~~~Raju~~~~~~~~~~~~~
|
|
|
|
|
You are welcome!
|
|
|
|
|
Could someone give me a hint on how I could show one view full screen on a second monitor while the app with all the navigation pane, toolbars, menus, etc. stays on the main monitor?
Ideally, this would just be a second view opened for the current document that can escape the apps frame and go over to the other monitor and make itself full screen.
I've considered just using a second app with sockets for communications between the two apps.
I've considered using a secondary GUI thread with a CWnd derived object that is sort of operating outside of MFC's doc/view architecture.
|
|
|
|
|
It's quite a good question! I think there's an article in it somewhere!
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/[ ^]
|
|
|
|
|
Hi all,
I have build a MFC single document app, which is not show in full screen at run time. Now in which class will i change the code and what code (Frame, or in App) for show it full screen when i click at run button.
Thanks to all
Shaheen
|
|
|
|
|
Have you looked at the call to ShowWindow() in the app's InitInstance() method?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
|
Hi,
This is John, i am developing one application in VC++ using TAPI 3.0 sdk. I am developing this application for to get some call center features. In call centers they will have phones with some dedicated extensions. Agents will logging onto the phones. Now i want to get agent login and log out events from TSP.
Can any one help me how to retreive those evets from TSP.?
If any one provide me some sample TAPI 3.0 applications, that could be great..
Thanks in advance..
Thanks
John.
|
|
|
|
|
Hi,
Here is one more basic question from my side.
What are the files created when we compile a C++ program.
And what the .obj file contains exactly?How do we debug it?
Thanks in advance.
-----------------------------
I am a beginner
|
|
|
|
|
When you compile a .CPP or .C file an .OBJ file (object file) is produced. There are also .LIB files (library files) which can be regarded as a collection of .OBJ files. These files cannot be loaded or executed by the OS. When you link the input is .OBJ and .LIB files and the output is an executable (generally a file with the .EXE or .DLL extensions). These files can be loaded and executed by the OS. What I'm describing is how things work in Windows, but the same principles hold for other systems.
Steve
|
|
|
|
|
thanks you for your answer...
But what is the content of this .Obj fle?....how we compile them?
-----------------------------
I am a beginner
|
|
|
|
|
hrishiS wrote: how we compile them?
You don't. They are the result of the compilation. The linker uses one or more of them to create the final EXE or DLL.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Imaging the following program (in a imaginairy programming language):
Local int x,y
x=5
y=sin(x)
Now assume the function Sin() is not specified in this program, but in a library. When the program is compiled the compiler knows how to compile the first 2 statements (it can replace these statements to machine code that does functionally the same). This is written to the OBJ-file. The compiler can not compile the last line because this is an external defined function. So the compiler writes in the obj-file the machine code to jump to an unknown adress. In the next pass the linker will fill this unknown adress to the adress of the function Sin().
As said before: the compiler creates for each C-file a equivalent obj-file. The linker merges these and other obj's and/or lib's to an exe. Essentially an obj-file is an exe-file that have jumps to external defined functions not filled in. This is the reason you can't run obj-files (it will crash as soon as it wants to call the external function). An obj-file is an intermediate file in the compile/link process.
Aside: The above is over simplified, in reality it is more complex as described: actually tables of unknown adresses are writen to the obj-file so the linker knows which adresses it must fill in.
Rozis
|
|
|
|
|
Hi to all,
Could anyone please give me a hint, why we say, C follows top down and C++ bottom up approach.
Thanks
-----------------------------
I am a beginner
|
|
|
|
|