|
Hi. I am writing picture editor which will work with all file types, that are used by Bitmap class. The program will use filters and other functions that will be alterring image.
I wrote a function to check if everything is ok and I can go on with my work, but I came to a problem.
The function below is just inverting pixels in Image and it works well... but only with 24Bpp>= images. What do I have to do, so that it will work with 8 and 16 Bpp Images ?
Thank you for any help!
Bitmap * bitmap.
{
UINT* pixels;
BitmapData bitmapData;
Rect rect(0, 0, pImg->GetWidth(), pImg->GetHeight());
pImg->LockBits(
&rect,
ImageLockModeWrite | ImageLockModeRead,
PixelFormat24bppRGB ,
&bitmapData);
pixels = (UINT*)bitmapData.Scan0;
int stride = bitmapData.Stride;
byte * p = (byte *)(void *)pixels;
int nOffset = stride - pImg->GetWidth() *3;
int nWidth = pImg->GetWidth() * 3;
for(int y=0;y < pImg->GetHeight();++y)
{
for(int x=0; x < nWidth; ++x )
{
p[0] = (byte)(255-p[0]);
++p;
}
p += nOffset;
}
pImg->UnlockBits(&bitmapData);
}
Cheers!
|
|
|
|
|
u need to do many reserches before u write code above.
the part which edits bitmap is less than 1/1000000000000000000000000000 of whole program which can edits "with all file types".
I suggest u stop now.
|
|
|
|
|
But you don't have to mess up with file types do you?
From what I know Bitmap class does everything for you. You just put
Bitmap bitmap("Filename") ;
And that's all, isn't it ?
I will do this editor for file types that are associated with Bitmap class, and they are(according to MSDN):
BMP, GIF, JPEG, PNG, TIFF, Exif, WMF, and EMF
The access to all pixels is not the same for all those file types(Of course depending on pixel depth)
So now my problem is only with different functions for different pixel depths images.
ps. I can't stop , as it's my school project. Thx for your reply though.
|
|
|
|
|
hi all
please look at 2 situations below
Items in underline outline the difference between both samples
1)
CString sPath = _T("c:\\file.txt");
FILE *pFile;
if( 0 != fopen_s( &pFile,(LPCSTR)sPath.GetBuffer(0),"w+b") )
throw _T("Error creating new file");
2)
FILE *pFile;
if( 0 != fopen_s( &pFile,"c:\\file.txt","w+b") )
throw _T("Error creating new file");
Problem is that 2- nd sample works fine, when 1- st throws exception.
Why ?
thank you in advance
-- modified at 12:13 Monday 15th May, 2006
|
|
|
|
|
big_denny_200 wrote: sPath.GetBuffer(0)
Getting Zero characters.
sPath.GetBuffer(sPath.GetLength())
"What classes are you using ? You shouldn't call stuff if you have no idea what it does" Christian Graus in the C# forum
led mike
|
|
|
|
|
(Dumb statment due to brain freeze removed.)
Since the second parameter to fopen_s is a const char* , you can simply do:
if (0 != fopen_s(&pFile, sPath, "w+b"))
To be more picky; since you are using the _T macros, the proper code should be:
if (0 != _tfopen_s(&pFile, sPath, _T("w+b")))
EDIT:
To be even more picky; CString indicates you are using MFC, so why not use the CStdioFile class?
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
-- modified at 14:04 Monday 15th May, 2006
|
|
|
|
|
thanks for reply.
What does it mean clearing buffer ?
I thought I was getting const pointer to wchar_t of sPath variable and then was casting it to const char * .
Was I wrong ?
I wanted to read(write) file data, per n bytes(first n bytes then second n bytes,..)
I thought using FILE would be good solution. As I would call fread() metod in loop.
Do you think using CFile is better ? in this case I will have to use Seek() methods.
Or better CStdioFile ?
thanks
-- modified at 14:08 Monday 15th May, 2006
|
|
|
|
|
I had a temporary brain freeze and mispoke; CString::GetBuffer returns a non-const pointer to memory with length at least that passed. Since you then cast it to a const pointer, the first call should have worked. It may have failed because the file was already open and locked or some other reason unrelated to the actual call.
(You should still just have passed sPath as the second parameter.)
If you are reading small amounts of data, the FILE based functions are a good way since they cache the reads/writes. CStdioFile encapsulates these functions.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Joe Woodbury wrote: I had a temporary brain freeze and mispoke;
why ?
Joe Woodbury wrote: CStdioFile encapsulates these functions
I am sorry for being so silly but I do not really fully understand meaning of word encapsulate.
Thank's for your attention.
|
|
|
|
|
big_denny_200 wrote: ...I do not really fully understand meaning of word encapsulate.
Wraps 'em up in a nice little package[^]
"The largest fire starts but with the smallest spark." - David Crow
|
|
|
|
|
big_denny_200 wrote: Joe Woodbury wrote:
I had a temporary brain freeze and mispoke;
why ?
GetBuffer() returns a pointer to a buffer of at least n characters long; it does not truncate that buffer if the passed value is less than the currently allocated buffer.
Still you should only call CString::GetBuffer() when you need to directly modify the contents of the string.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
big_denny_200 wrote: if( 0 != fopen_s( &pFile,(LPCSTR)sPath.GetBuffer(0),"w+b") )
The call to GetBuffer() is not necessary.
if (0 != fopen_s(&pFile, (LPCSTR) sPath, _T("w+b")))
"The largest fire starts but with the smallest spark." - David Crow
|
|
|
|
|
then i get error :
Error 1 error C2440: 'type cast' : cannot convert from 'CString' to 'LPCSTR'
|
|
|
|
|
Just realized that you are compiling in UNICODE but using the MBCS version of the function.
The proper code should read:
if (0 != _tfopen_s(&pFile, sPath, _T("w+b")))
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Neither is the cast. The problem is, I finally realized, is that he is compiling in UNICODE but using the MBCS version of the function.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Joe Woodbury wrote: Neither is the cast.
I don't know the parameter list for fopen_s() so I wasn't for sure if it would be required or not. I errored on the side of caution.
"The largest fire starts but with the smallest spark." - David Crow
|
|
|
|
|
|
Hello.
I've looked all over the place, but I can't find a function that you can give a shell command, have it execute it, and then return the results of the shell command to you as a string. Is there such a command, and if so, what is it?
Actually i wanna code a server to receive command from a remote client then process it and send result.but i dont know how can i work with command and send the result through socket.for example when u wanna see a list of files in dir how u can send the list using socket.should i change it to string?is it a kind of pipe?
Thanks,
f.f
-- modified at 11:24 Monday 15th May, 2006
|
|
|
|
|
See here and here.
"The largest fire starts with but the smallest spark." - David Crow
|
|
|
|
|
You can always "pipe" any output from command line to a filepath, e.g. "dir < COM1".
If you don't tell where to put the output from a command line executed program, it will usually use STDOUT, which is usually the screen.
STDOUT is a file pointer that is constant, i.e. you cannot change its value. You can, however, redirect the information written to STDOUT to another "file" using freopen().
I don't know much about your needs and what's suitable for you, but I would try creating a named pipe and either "pipe" the program output to that pipe with command line arguments, or try to redirect STDOUT to the named pipe.
Hope this helps
--
Roger
It's supposed to be hard, otherwise anybody could do it!
Regarding CodeProject: "resistance is pointless; you will be assimilated"
|
|
|
|
|
My recent work content involved some exception handling, __try/__except to be specific. And the following is the questions that confused me.
int filter()
{
puts("Filter()");
return EXCEPTION_EXECUTE_HANDLER;
}
int _tmain(int argc, _TCHAR* argv[])
{
int a = 1;
int *p = NULL;
char s[10];
__try
{
__try
{
a = 2;
*p = a;
puts("After exception raised");
a = 3;
}
__finally
{
puts("Finally");
a = 4;
}
}
__except(filter())
{
puts("_except");
a = 5;
}
sprintf(s, "%d", a);
puts(s);
_getch();
return 0;
}
My questions focused on the return statement in exception filter function:
if it is return EXCEPTION_EXECUTE_HANDLER ,why the statement a = 3; never gets excuted?
if it is return EXCEPTION_CONTINUE_EXECUTION ,why the filter keeps getting called. according to MSDN EXCEPTION_CONTINUE_EXECUTION The system stops its search for a handler and returns control to the point at which the exception occurred.return control to *p = a ? only to cause another same exception? what's the point here?
if it is return EXCEPTION_CONTINUE_SEARCH , the system keeps searching for exception handlers on and on and on for access violation? until the handlers were exhausted? another seemingly endless function call?
|
|
|
|
|
LiYS wrote: if it is return EXCEPTION_EXECUTE_HANDLER,why the statement a = 3; never gets excuted?
A quote from MSDN: "A __finally statement does not block searching for an appropriate exception handler". You raise the exception with the following statement:
*p = a;
The system will then looks for an exception handler calling any __finally blocks on the way (actually this isn't quite true but it's good enough for now). When it gets to the __except block the filter expression returns EXCEPTION_EXECUTE_HANDLER so it enters the block and the exception is handled.
LiYS wrote: if it is return EXCEPTION_CONTINUE_EXECUTION,why the filter keeps getting called.
The idea of EXCEPTION_CONTINUE_EXECUTION is that the code first takes some action to correct the problem then execution is resumed and the operation is retried: you are performing no such correction thus the problem keeps recurring. In short everything is working as it should. Note that the __finally handler will not be called in this case (this is where real life differs slightly from my explaination as alluded to in my, "this isn't quite true" comment above).
LiYS wrote: If it is return EXCEPTION_CONTINUE_SEARCH, the system keeps searching for exception handlers on and on and on for access violation?
If you return this you're telling the system that the particular __except block should not be entered and to continue searching for a handler. If no handler is encountered that handles the exception execution is aborted.
Steve
|
|
|
|
|
Hi all,
Are you concentrating?
Yes, good!
Please read this carefully
An example of my problem is I have three controls.
- Control A
- Control B1
- Control B2
I want to be able to either B1 or B2 to be a child window of A depending on how I set the properties. Of course I know A is child window. when I place it on the a driver (demo) app, it crashing my system. I want to know to do this safely?
Many thanks,
alton
|
|
|
|
|
Hi Alton!
If you find the part below hard to understand, please let me know and I'll repost typing it slower.
Alton Williams wrote: Of course I know A is child window. when I place it on the a driver (demo) app, it crashing my system.
How does it crash your system? Error messages? Some info from debug sessions?
The "system" could crash from a zillion reasons, give or take a few, it's quite hard to guess what your problem is.
--
Roger
It's supposed to be hard, otherwise anybody could do it!
Regarding CodeProject: "resistance is pointless; you will be assimilated"
|
|
|
|
|
Hi Roger,
Thanks for your prompt reply!
Roger Stoltz wrote: How does it crash your system? Error messages? Some info from debug sessions?
When I build and register the control. When I place it on another form (in VB) or Dialogue box (in VC++) for testing. it seems to bring down VB or VC++. If I'm lucky if my final app comes down or doesn't respond at run-time.
Is that any clearer?
Alton
|
|
|
|