|
Christian Graus wrote:
You have bitmap data, I'm suggesting you iterate through it and modify it, not that you turn it into a HBITMAP or use any GDI functions on it.
How can I do that? What I have to write is a text that can be on any size, angle, color, font, and more over I want it to be transparent so that text and bitmap both are seen.
So how can I modify the bitmap data directly without using GDI API's
Thanks
|
|
|
|
|
Naveen_mah wrote:
How can I do that? What I have to write is a text that can be on any size, angle, color, font, and more over I want it to be transparent so that text and bitmap both are seen.
The fact that you want to merge text with the bitmap underneath DEMANDS that you do it directly, unless you use GDI+, in which case you can create a semi transparent brush to draw the text for you.
Naveen_mah wrote:
So how can I modify the bitmap data directly without using GDI API's
Well, you have the bitmap data as a byte array, so you would figure out where you want to put something, and iterate through the bits, placing it on. I didn't realise you wanted to rotate your text, or change it's colour, I assumed you had a standard watermark you wanted to add, in which case you could store it in a resource bitmap, and use the values in that bitmap to merge into your source image.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
So what do u think is the best way to do this? As my watermark is dynamic and can be of any kind.
Below is the code I have simplified and pasted here, But I am not able to BitBlt bitmap and getting insuficient memory error...
Can anybody help me out ...where I have gone wrong?
My bitmap is 1 bit bitmap and is top down bitmap 2275x3300 (file size 928 KB)
<br />
void AddText(HWND hWnd)<br />
{<br />
HDC hdc = GetDC(hWnd); <br />
FILE * fp = NULL;<br />
fp = _wfopen(L"d:\\bmp.bmp",L"r+");<br />
int width,height; <br />
if (fp)<br />
{<br />
BITMAPFILEHEADER bmFileHeader;<br />
BITMAPINFOHEADER bmInfoHeader;<br />
PBYTE pBmData = NULL;<br />
fread(&bmFileHeader,sizeof(BITMAPFILEHEADER),1,fp);<br />
fread(&bmInfoHeader,sizeof(BITMAPINFOHEADER),1,fp);<br />
BITMAPINFO* pBmInfo;<br />
int size;<br />
<br />
if (bmInfoHeader.biBitCount == 24)<br />
{<br />
size = sizeof(BITMAPINFOHEADER);<br />
}<br />
else size = sizeof(BITMAPINFOHEADER) + 2 * sizeof(RGBQUAD);<br />
<br />
pBmInfo = (PBITMAPINFO)new BYTE[size];<br />
<br />
fseek(fp,sizeof(BITMAPFILEHEADER),SEEK_SET);<br />
fread(pBmInfo,size,1,fp);<br />
pBmInfo->bmiHeader.biHeight*= -1;<br />
width = pBmInfo->bmiHeader.biWidth;<br />
height = pBmInfo->bmiHeader.biHeight;<br />
<br />
<br />
pBmData = new BYTE[bmInfoHeader.biSizeImage];<br />
fread(pBmData,1,bmInfoHeader.biSizeImage,fp);<br />
fclose(fp);<br />
<br />
pBmInfo->bmiHeader.biClrImportant = 2;<br />
pBmInfo->bmiHeader.biClrUsed = 2;<br />
<br />
DWORD fdwInit = CBM_INIT;<br />
HBITMAP hBitmap = CreateBitmap(width,height,bmInfoHeader.biPlanes,bmInfoHeader.biBitCount,pBmData);<br />
DWORD err = GetLastError();<br />
<br />
BITMAP bitmap; GetObject(hBitmap,sizeof(BITMAP),&bitmap);<br />
<br />
HDC TmpDC = CreateCompatibleDC(hdc);<br />
BYTE *pbase;<br />
HBITMAP TmpBmp=CreateDIBSection(TmpDC,<br />
pBmInfo,DIB_PAL_COLORS,(void**)&pbase,0,0);<br />
HGDIOBJ TmpObj=SelectObject(TmpDC,TmpBmp);<br />
<br />
HDC dcBmp=CreateCompatibleDC(TmpDC);<br />
HGDIOBJ TmpObj2 = SelectObject(dcBmp,hBitmap);<br />
int ret = BitBlt(TmpDC,0,0,width,height,dcBmp,0,0,SRCCOPY);<br />
err = GetLastError();<br />
<br />
SelectObject(decBmp,TmpObj2);<br />
DeleteDC(dcBmp);<br />
TextOut(TmpDC,100,100,L"Watermark",lstrlen(L"Watermark"));<br />
<br />
DeleteObject(hBitmap);<br />
hBitmap=TmpBmp;<br />
DIBSECTION dib;<br />
GetObject(hBitmap,sizeof(DIBSECTION),&dib);<br />
<br />
<br />
SelectObject(TmpDC,TmpObj);<br />
DeleteDC(TmpDC);<br />
DeleteDC(hdc);<br />
delete []pBmData;<br />
delete []pBmInfo;<br />
<br />
}<br />
<br />
}<br />
Thanks
|
|
|
|
|
Naveen_mah wrote:
HDC hdc = GetDC(hWnd);
Why ? You realise this means your HDC will have the bit depth of your PC, you won't control it ?
Naveen_mah wrote:
FILE * fp = NULL;
Man, C file reading is ugly....
Naveen_mah wrote:
DIBSECTION dib;
GetObject(hBitmap,sizeof(DIBSECTION),&dib);
/// Dont get any data in dib.dsBm.bmBits
The data is in pbase, you get it out of calling CreateDIBSection.
Naveen_mah wrote:
My bitmap is 1 bit bitmap and is top down bitmap 2275x3300 (file size 928 KB)
How on earth do you hope to create a watermark in a 1 bit bitmap ? If each bit is just on or off, one of two colours, then you just want to write text over it, you don't want a watermark at all. A watermark is a generally invisible signature that's blended into an image. There's no blending when you have only two colours.
Perhaps you need to redefine what you're trying to do here ? If you're using anything less than 16 bit, you need to use GDI functions, because keeping track of palettes and stuff is just too painful.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I have my basic application together what I want to do is call one dialog box from my base application (an about box). The main application is a dialog box itself.
|
|
|
|
|
|
I think you only need some basic MFC Programming book.
Jack
---------------------------------------------------------------------------------
XD++ MFC/C++ Flow/Diagram Library -- http://www.ucancode.net
|
|
|
|
|
i am currently implementing a program where i need to print the screen and take its picture (the same function performed by the print screen key on the keyboard) but i want to do this automaticly so is there any c++ command or any other way that i can use to perform such function
gobar
|
|
|
|
|
depends if you're using MFC or not.
With a multi-doc MFC app it does print screen for you.
|
|
|
|
|
Type print screen in CodeProject's "Search" box.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
|
Repost from COM forum which seems dead.
Question 1:
I have:
1. exe COM client A.
2. exe outofproc COM server B which is also a client to:
3. dll inproc COM server C.
So B creates an instance of C. And passes the pointer to it to A. Can A actualy call C which is in B process space?
Question 2:
I have:
1. A is an exe COM client .
2. B is an exe outofproc COM server.
When A releases all instances of B, B unloads. Good! That's what I need. BUT! If:
2. B is a dll inproc COM server.
Then When A releases all instances of B, dll B still is loaded by A process for a while.
Is there a way to force it to unload?
Thanks a lot!
|
|
|
|
|
Take these with a grain of salt, I am no COM expert...
Question 1: I do not think that is directly possible, but I think that when you pass the interface pointer to another process (from B to A), you will get a marshalled interface pointer, which will not really be the same pointer value you passed over. Instead, it will be one that COM created during the "pass" operation. This new interface pointer will not be in B's address space, it will be in A's. If it pointed to a location in B's address space (for example, you passed over the value of the interface pointer), you would likely crash the instant you tried to use it because it would not point to the same location anymore (if it pointed anywhere valid at all).
Question 2: You have the FreeLibrary function, but you cannot get directly ahold of the handle for the DLL that contains the the InProc COM object*. It was loaded by the COM subsystem, and even if you did manage to get that handle and force an unload, I think you would be basically snatching the rug out from under COM and that might be bad...
* Yes, you could call LoadLibrary again and might get the same instance handle...
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
inner wrote:
Can A actualy call C which is in B process space?
I'm pretty sure you can't do this. Sharing of a COM object must be managed by the object itself.
inner wrote:
Is there a way to force it to unload?
Not easily. Is there any reason why you'd want to though? Windows manages this quite well.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Hi all,
I am using FindFirstFile and FindNextFile to read a folder and get all files properties.
There is a problem. That two functions are reading files and folders sorted by name.
I mean,
c:\test
c:\test\a.txt
c:\test\c
c:\test\c\m.txt
c:\test\k.txt
I'm wondering if I can sort before I read it?
Like sorting file name or size or extension before I read it?
c:\test
c:\test\a.txt
c:\test\k.txt
c:\test\c
c:\test\c\m.txt
|
|
|
|
|
|
For NTFS volumes, the files/folders are enumerated in sorted order. For non-NTFS volumes, the files/folders are enumerated in the order in which they were added. That said, you'll need to add all files/folders into an array, sort the array, and then process it.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Wouldl it make sense to have two code paths, then? One for NTFS and one for others? The NTFS would be optimal, no sorting required. Other storage types could use the slower method
|
|
|
|
|
Blake Miller wrote:
Wouldl it make sense to have two code paths, then?
Given how fast a data structure can be sorted, I would think not.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
I really need some help with this one. I have wasted too much time and not made much progress.
What I am trying to do is to read a timestamp from index.dat generated by Internet Explorer. The timestamp is in the file in the following format "00 14 AC 72 BE 95 C2 01". A document I read takes the value and reverses the order so that the value is "0x01C295BE72AC1400" and then passes it into the w32tm function as follows: "w32tm /ntte 0x01c295BE72AC1400" and gets a return of "146792 02:41:12.0000000 11/26/2002 8:41:12 PM (local time)". I'm trying to accomplish this within my Visual C++ program but just can't get it. I'm certain there are others out there who are smarter and more experienced when it comes to such issues. I just want to be able to read the data from the file and pass it into asctime to get a meaningful date and time stamp.
Does anyone know how to accomplish this?
Many Thanks
|
|
|
|
|
If you know VB, you might take a peek at the ie.vbs file that accompanies this article.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Hi,
I don't know if this is the appropriate forum for this question, but I don't know any other place to post it. I have a Windows service in which I have an embedded binary resource that I want to load at service startup. However, the API functions below fail with an exception or return NULL:
Both of these calls throw an exception when called by my service:
HINSTANCE hInstance = AfxGetInstanceHandle();
HINSTANCE hInstance = AfxGetResourceHandle();
This always returns a NULL when called by my service:
CWinApp* lpApp = AfxGetApp();
hInstance = lpApp->m_hInstance;
How can I access this resource?
Thanks,
Royce
|
|
|
|
|
This might sound like a stupid question, but is it an MFC-based service? For example, if this is an ATL-based service, functions like that will fail because you are likely to not have a real MFC CWinApp around.
You DID check the pointer returned by AfxGetApp to ensure that it is not NULL right?
Move away from the MFC-based resource functions and take a look at the native Win32 ones, like FindResourceEx(...) and LoadResource if you have no useful MFC "state" available in your service.
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
James,
Thanks for your help. No, it is not a stupid question. I should have said that it is a MFC-based service. I tried FindResourceEx() and LoadResource() API functions. They return NULL. AfxGetApp() returns a valid (?) pointer, but the member m_hInstance is NULL. This problem is complicated by the fact that this resource is an encryption key and password and is used by two other applications and numerous DLLs. Difficult to understand, let alone explain to someone else.
Thanks,
Royce
|
|
|
|
|
Have you tried calling FindResourceEx with a NULL instance parameter directly? Also, try using FindResource if language is not an concern (and it sounds like it is not).
Also, how are the resources identified, by number or by string? Are you using the correct Resource Type value?
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|