|
IMO it means trouble. Suddenly the lifetime of one thing affects the validity of an other. Very .. manual memory management-like. Completely contrary to the entire idea of garbage collection.
I suppose you could do that too yes, but what's the advantage of that over writing it into an actual bitmap manually?
|
|
|
|
|
Nothing special here, you're passing a pointer into that constructor, hence the data isn't managed by .NET; it is inherently unsafe, just like passing pointers to native code is.
And it is somewhat related to Image.FromFile locking the file for as long as the image lives, which is troublesome as it isn't documented well and the code itself does not provide a clue. The same copy-to-a-second-bitmap trick solves that one too of course.
|
|
|
|
|
Yes I thought of that one.. very annoying. And Image.FromStream wants the stream to be kept open, and on top of that resets the Position to zero. It's actually in the documentation (at least it is now, was it always there?) but I discovered it the hard way, when the first image kept loading over and over and then all bitmaps mysteriously died..
|
|
|
|
|
I agree, I'd do that. Holding the file open for the lifetime of the image definitely seems like the wrong answer and, if you have to load it into memory anyway, I think it's better to very temporarily have two copies and then let the Bitmap own the data.
Also, depending on the order of the data in the file, you may have to reorder it so that it's in a valid 32 bit pixel format for dropping into a bitmap. I think you need ARGB but it might be BGRA in terms of the byte order in the stream.
|
|
|
|
|
Hi Amit,
I tried to run your code but i am not getting any output.
Can you please tell me if i have to do any settings for running the project?My friend told me that project runs in Windows 7 and doesnt require any settings.
I am using Windows XP and Visual Studio 2005.
Thanks in advance.

|
|
|
|
|
Which project and who is Amit? This site has millions of members so it could be anyone. If you are referring to some article then you should use the forum below the article to contact the author.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Hi,
Sorry for posting the query at wrong place.
I was referring to the article "Search Engine for LAN".
|
|
|
|
|
Post this question against the article / tip so that the author can take a look at it.
You mighe be able to get an answer.
|
|
|
|
|
Hello,
I want to search text in a WPF richTextBox. My problem is the text is formatted...
For a normal text I use this:
string wordToSearch = "word";
TextRange tr = new TextRange(this.rtb.Document.ContentStart,
int startPos = tr.Text.IndexOf(wordToSearch);
this.rtb.Document.ContentEnd);
if (startPos > -1)
{
int l = this.GetLinesCount(tr.Text, startPosition);
TextPointer startRtb = this.rtb.Document.ContentStart;
TextPointer start = startRtb.GetPositionAtOffset(startPos + l);
TextPointer end = start.GetPositionAtOffset(wordToSearch.Length);
this.rtb.Selection.Select(start, end);
this.rtb.Selection.ApplyPropertyValue(
TextElement.BackgroundProperty,
this.rtb.SelectionBrush);
}
public int GetLinesCount(string str, int startPosition)
{
int lines = str.Take(startPosition).Count(k =>
k.Equals((char)13) || k.Equals((char)10));
return lines + 2;
}
But, for a formatted text (other color for example), I see a difference between my "word" and my "selection" of X characters.
If somebody has an idea?!?
Thank you for help me...
Bye.
|
|
|
|
|
|
|
i want to built a remote desktop tools or software that can connect and share the desktop.. the graphics quality should be good..
can anyone help me... providing the details of the project .
|
|
|
|
|
Sure I can. In the search box at the top, type in remote desktop c# and make sure the search in articles radiobutton is selected, and Bob's your transgender auntie.
|
|
|
|
|
Palantir - Remote Desktop Manager[^] is always a good article to consult when looking at writing your own desktop program.
Too much of heaven can bring you underground
Heaven can always turn around
Too much of heaven, our life is all hell bound
Heaven, the kill that makes no sound
|
|
|
|
|
I got a question about TDD and unit test using Visual Studio 2008 Pro. One of the TDD requirements reads something like "All tests should fail initially when there is no coding yet!" However, when I generate a test project from VS 2008 Pro, all tests can pass before any coding. Do I have to add code to the test project, in order to make the test fail initially? Or am I missing something here?
Best,
Jun
|
|
|
|
|
Of course you need to write code. The unit test is created with defaults; its up to you, the developer, to actually make it relevant.
No comment
|
|
|
|
|
*bang* *bang* *bang*
The thing I love about banging my head on the desk, is the wonderful feeling you get when you stop...
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Yes, I need to write some code to meet the TDD requirement. I don't want to write code every time I generate a TDD unit test. I think I have a solution here, i.e., adding the minimum TDD code to a new test project template called "TDDUnitTest".
Best,
Jun
|
|
|
|
|
TDD != Unit test. You first need to understand that very important concept.
Jun Du wrote: I don't want to write code every time I generate a TDD
Then you are in the wrong profession and/or don't understand what TDD is
*bang* *bang* *bang* This feels good
No comment
|
|
|
|
|
Mark Nischalke wrote: Then you are in the wrong profession and/or don't understand what TDD is
Both of your assumptions are wrong. That's why we try not to make assumptions during a debate!
My question was "how to make all tests fail initially without manually writing code". I was hoping to apply the Unit Test framework to TDD. I think I got what I was looking for.
Best,
Jun
|
|
|
|
|
Would you care to elaborate. You have got me interested in this TDDUnitTest idea.
"You get that on the big jobs."
|
|
|
|
|
Basically, to meet the specific TDD requirement under discussion, I would create a sample unit test project that handles two initial cases:
1) Check the app.config file and see if the class being tested has been coded. In order to do that, you need to add a key to the config file and set it to false initially. Of course, some more intelligent alternative can be implemented if you feel like to.
2) As Ravi suggested in his message below, have each of the unfinished methods throw an "unimplemented" exception. Add a handler to the test code to capture this and fails aumatically.
After you have the above minimum test code in place, create a project template and an item template, called "TDDUnitTestPlroject" and "TDDUnitTest" respectively. From now on, you can use these templates for TDD unit test projects and you don't need to write the same code again and again.
Best,
Jun
|
|
|
|
|
Yes. One way to do this is to make the methods being tested throw NotImplementedException . As you build out your code, your tests will eventually pass (once you've identified and fixed detected bugs). Of course, you also need to perform system (vs. unit) testing to help ensure product quality.
/ravi
|
|
|
|
|
Ravi Bhavnani wrote: One way to do this is to make the methods being tested throw
NotImplementedException .
Yes, that would work for each of the unfinished methods after the class is coded.
Ravi Bhavnani wrote: Of course, you also need to perform system (vs. unit) testing to help ensure
product quality.
Absolutely. Usually, unit test is tedious and costly. By using some sort of test framework, we could simplify and automate the process significantly.
Best,
Jun
modified 9-Jan-12 9:33am.
|
|
|
|
|
The approach you seem to be describing here is not TDD though. You don't start with a coded class, you start with the tests and build your functionality out of this. What am I missing in your solution that makes it suitable for TDD?
|
|
|
|