|
Hi,
this is completely wrong in many ways:
1.
your code includes a lot of magical numbers (a width of 300, a height of 200) ?
Good code does not do that. Such numbers are either constants (declare constants then),
or they are variables that get their value somewhere (e.g. int width=bitmap.Width;).
2.
you are nesting five for loops; the inner loop would execute some
300*200*100*100*100 times, thats 60 billion times. How long do you expect this will take ?
Nesting that many loops seldom is the right way to achieve anything.
3.
what is the use of the for loops over r1/r2/r3 ?
you can replace them with:
int r1=p.Color.Red;
int r2=p.Color.Green;
int r3=p.Color.Blue;
and then check whether r1/r2/r3 are in the range [0,100).
Why search for something that you already know ???
4.
Graphics.DrawRectangle with a size of 1*1 is an expensive way to set one pixel.
Cant you use bitmap.SetPixel ?
5.
Why create a new pen for every pixel, you can use the same pen over and over.
6.
I dont think turning some pixels transparant is the right way to achieve
whatever it is you are trying to achieve.
Conclusion:
I strongly suggest you search CodeProjects for some articles on Graphics,
they are plenty and there are some pretty good ones. Then study those and learn
about realistic ways of doing things, before you start creating some weird code
of your own... Have a look at image filtering, edge enhancement, and many more.
And once you think you know what you need, try creating some quality code, and
organize it such that you can test it on much smaller images.
|
|
|
|
|
You should read my articles on image processing. It includes a greyscale filter ( although you can use the built in GDI+ stuff to do that )
Apart from that, I agree with everything Luc said, especially the bit about the nested loops, but this is all very much wrong.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi Christian,
Luc Pattyn wrote: and there are some pretty good ones
I expected you to agree...
|
|
|
|
|
*grin*
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi,
I need help with filling custom structs (members of a control) via designer - like filling Color struct in BackColor member using RGB values.
Thanx
Stevo
|
|
|
|
|
|
That is what I was looking for and couldn't find, thanx very much
|
|
|
|
|
That examples work good with classes, but i would like to use struct and there is something tricky about it, you can't set a property of a struct using designer.
|
|
|
|
|
Hi,
I am trying to use the OWC to edit the cells in an existing excel file. I have done it with Interop.Excel, but that takes up too much memory which is why I am going towards the OWC. My problem is that I cannot seem to figure out how to even open the Excel File for editing. Here is my code of a sample project I am trying to do just to get started:
<br />
<br />
private void EditSpreadSheet()<br />
{<br />
<br />
<br />
spread = new OWC.SpreadsheetClass();<br />
spread.ActiveSheet.ConnectionString = "PR.xls";<br />
spread.Cells[2,"2"] = "Hi";<br />
<br />
<br />
<br />
<br />
<br />
}<br />
<br />
<br />
Sincerely,
The Major Rager
|
|
|
|
|
TheMajorRager wrote: spread.ActiveSheet.ConnectionString = "PR.xls";
You might want to supply the fully qualified path to this file.
|
|
|
|
|
Hi Dave,
Here is the new code I came up with however, this creates a NEW file instead of just changing the cells. Do you know how to make it so that it edits a file instead of creating a new one? Also, how much memory does OWC11 use on the server?
<br />
<br />
private void EditSpreadSheet()<br />
{<br />
<br />
<br />
<br />
spread = new OWC.SpreadsheetClass();<br />
spread.ActiveSheet.Cells[1,1] = "HELLO";<br />
spread.get_Range("A2:A2",Type.Missing);<br />
spread.Export(Server.MapPath(".") + "\\" + "PR.xls",OWC.SheetExportActionEnum.ssExportActionNone,<br />
OWC.SheetExportFormat.ssExportHTML);<br />
<br />
<br />
<br />
<br />
<br />
<br />
}<br />
<br />
<br />
Sincerely,
The Major Rager
-- modified at 17:33 Wednesday 27th June, 2007
|
|
|
|
|
TheMajorRager wrote: Server.MapPath(".") + "\\"
Seperate this line out so you can see the exact path it comes up with. Somehow, I don't think it's valid. Either that, or the ASPNET process doesn't have Write permissions to the path it's showing.
string filepath = Path.Combine(Server.MapPath("."), @"PR.xls");
|
|
|
|
|
Hello,
I have a 2 dimensional array that I need to add more elements to. Array.Copy and Array.Resize only work for one dimensional arrays. Any thoughts as to how I can accomplish this with a 2 dimensional array?
Thanks
|
|
|
|
|
Create a new array of the appropriate size and copy the elements from the old version to the new.
|
|
|
|
|
Hello,
Look at this post[^] from Mark J. Miller[^] where he was so nice to give the link to his job interview project.
In Version 1 you will easily find a method called "Expand2DArray" and also "Trim2DArray".
Hope it helps!
All the best,
Martin
|
|
|
|
|
Ok, thanks for the help. I'll check it out.
|
|
|
|
|
I have one program(app_1) that has only read access to drives and write access only to memory.
the second program(app_2) has access to memory and write access to drive.
How can I load a file or whatever in to memory (buffer) with app_1 and get that file or whatever in app_2
*********************
no access to clipboard,
app_2 can't access the file from app_1 on disk(thats fact)
most be done thru memory
and please don't send me to c++
If you can help then please do
Thanks a Bunch
|
|
|
|
|
Hi,
I am not sure what your app(s) are trying to achieve; maybe this is useful:
Windows supports the concept of "memory mapped files". They are very good at sharing data
between two processes. They support the situation where multiple processes can read/write
the same file, where the file is actually in memory (so it gets mapped in the address
space of each participating process).
I dont think .NET supports this directly; but applying P/Invoke on Win32 functions
such as CreateFile, OpenFile, WriteFile etc. solves this.
I have used this for logging: one app logs to memory, another process actually
consumes the log information and processes it.
|
|
|
|
|
do you have a small code snippet?
|
|
|
|
|
Hi,
I dont have it at hand, and I am not sure anymore about the Win32 function names;
it may well be things like CreateFileMapping, MapViewOfFile, etc.
And it would not be "a small code snippet", it really requires some setup code.
I suggest you search around (Google) for MMF or memory-mapped file.
|
|
|
|
|
|
Hi,
I want to create a demo for an application I have created in C# so as to work for only eight days when installed on a client machine
Kezy
|
|
|
|
|
Hi!
So what's the problem?
You have to either save the date of installation or the initial remaining time somewhere and then, during startup, calculate if your still within the demo time range.
But beware - with registy and file system watching programs it's quite easy to find out the location where you save your time information. That way one can always uninstall your app and re-install it to get another 8 days.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
as mav's said pure clientside solutions can easily be defeated. If you can require demo users to have a net connection and you have a 24/7 server you could have your app phone home with system details such as mac address, harddrive serials, etc to your server to ask for permission to run. Organized hackers will still be able to edit your application to disable the checks. If possible limited functionality in a time unlimited demo is probably more effective at forcing a user to go from the demo to the full version of your application, than a fully featured demo with a time limit.
--
You have to explain to them [VB coders] what you mean by "typed". their first response is likely to be something like, "Of course my code is typed. Do you think i magically project it onto the screen with the power of my mind?" --- John Simmons / outlaw programmer
|
|
|
|
|
Hi, for creating a demo application that runs only for 8 days, u can enter the date/time settings in a text file, that will be created during the application installation. change the ext of the text file to something else, and during the installation , make it a point to install the file in some safe area of the client machine that normally he does not /cannot access. Also make sure to make the file hidden. This will defeat any attempt to uninstall the app and reinstalling it to get 8 more days, since uninstalling the app will delete only the program related files and not the text file that u create from ur C# code. So each time the application is opened up this file will be checked for some status flag, upon not finding the correct value, the app wont start.Just try this technique on ur machine first.
Cheers
|
|
|
|