|
I did think abt that befor posting but i found too many people answering in this forum so i thought i will try my luck... Guess i am not that lucky.
|
|
|
|
|
General rant to everyone who posts in the wrong forum (not just you):
What if everyone did what you did? That would mean that everything would be posted in one single forum, and the system of forum would become completely useless.
Also by posting in the wrong forum you reduce your chances of getting help. You annoy a lot of people, and the wrong people also. Think about how you do in real life: If you have a question about banking, do you go the the small bank office, or the big supermarket?
---
b { font-weight: normal; }
|
|
|
|
|
I have two images. One is dynamically create, the other is loaded into memory from an image on the harddrive. They are the same size.
Is there an Image method built into C# to compare the two images for equality? I've looked, but found nothing.
I have another case, also. I have a large bitmap (800,600) and I have a small image (20,20). I want to see if there is a 20x20 section in the large bitmap which matches the small image. The sizes will vary, because I need to do this with more than one image. Basically, is there an effecient way to see if a smaller bitmap is contained within a larger bitmap?
Thanks.
|
|
|
|
|
No there are no predefined functions. But both algorithms should be fearly easy to implement. Its just about looping through two images and comparing their pixel values. To access those the easiest method are the Get/SetPixel methods of the Bitmap class, but they are very slow. For faster processing you will need some code. Have a look at these articles. Part 1 already shows how to go unsafe into a Bitmap but the other parts probably give you some more insight.
|
|
|
|
|
its very simple to do this.
first , check the width/height ration between the both pictures , if they differ they are not the same image
then shrink both pictures to some managble size (eg by making a thumbnail of them both)
this is will make it possible to compare images with the same width/height ration but with different width / height , where one image is smaller than the other
then do a little loop that checks each pixel in both
then compare those pixels with some sort of treashold.
this way you can compare images with different sizes and different quallity.
|
|
|
|
|
Im new to c#. Can you advice me how to code saving text from labels or message boxes to file on hdd?
|
|
|
|
|
There are many many different ways to do this. I would research the System.IO.File and System.IO.TextReader and System.IO.TextWriter classes for more help. I could give you an example, but I don't think it would do any good unless we knew what exactly you're trying to do. It could be good as well to research Serialization as this is a nice easy way to Serialize and object to a file.
|
|
|
|
|
Bryan, what do you do, sit here and refresh the C# forum every three seconds?
You're not trying to beat Nish and CG's post counts, are you?
Picture a huge catholic cathedral. In it there's many people, including a gregorian monk choir. You know, those who sing beautifully. Then they start singing, in latin, as they always do: "Ad hominem..."
-Jörgen Sigvardsson
|
|
|
|
|
Haha, I like to take time during my breaks an help people out
I'll catch up to them some day... when I'm older and wiser
|
|
|
|
|
Could you give me a simple example please? What I want to do is simply to save text to something.txt file from textbox or label on button_click event.
|
|
|
|
|
ok.. a VERY simple example would be as such: (This is not at all the complete or best way to do it, just a simple example to start your building blocks)
<code>
public void WriteFile(string text, string fileName)
{
System.IO.TextWriter tw = null;
try
{
if(System.IO.File.Exists(fileName))
{
System.IO.File.Delete(fileName);
}
tw = System.IO.File.CreateText(fileName);
tw.WriteLine(text);
}
finally
{
if(tw != null)
{
tw.Flush();
tw.Close();
}
}
}
</code>
|
|
|
|
|
Doesn't Close() call Flush() automatically?
|
|
|
|
|
That depends on what you're calling .Close() on. I just find it easier to read, and less "implied", to call it myself, no matter what stream type is in use.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
IS there a list of which streams do/don't call it then?
|
|
|
|
|
No. Only if you research each writable stream type.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I think it does currently but you can never tell what they might change in future releases. So I thought it'd be safe to go ahead and call it anyway.
|
|
|
|
|
Thanx for this, I played around with it and it works. What about if I want to load it back to my form?
|
|
|
|
|
Well, for the simple one line of text in a file you won't need to parse anything. You can simply do just the opposite of what I have above. Check if the file exists but don't delete it. Instead of using File.CreateText you will use File.OpenText. Instead of using System.IO.TextWriter use a System.IO.TextReader. Instead of using WriteLine() use ReadLine(). It's all pretty simple. However, if you're putting multiple lines in the file for multiple objects/properties it does get a little more complex. A more simple way to do this would be to just serialize the label (or whatever other oject you have) into a file and deserialize it back from the file to an object in the code whenever you need it. A good example exists right here on code project:
http://www.codeproject.com/csharp/objserial.asp[^]
|
|
|
|
|
Hi
Is it possible to set values to a property of a structure in the structure's constructor. For eg.
<br />
struct MyStruct<br />
{<br />
int fieldx;<br />
public int Propertyx<br />
{<br />
get { return fieldx; }<br />
set { fieldx = value; }<br />
}<br />
public MyStruct(int i)<br />
{ Propertyx = i; }<br />
}<br /> This is not compiling whats wrong and why ? But i am able to directly assign the value to the field.
Regards
Deepak
-- modified at 12:26 Tuesday 11th October, 2005
|
|
|
|
|
Try this:
<code>
struct MyStruct
{
int fieldx;
public int Propertyx
{
get
{
return fieldx;
}
set
{
fieldx = value;
}
}
public MyStruct(int i)
{
fieldx = i;
}
}
</code>
|
|
|
|
|
He did say that he was able to assign directly to the field. He just wanted to know why he couldn't assign to the property.
Picture a huge catholic cathedral. In it there's many people, including a gregorian monk choir. You know, those who sing beautifully. Then they start singing, in latin, as they always do: "Ad hominem..."
-Jörgen Sigvardsson
|
|
|
|
|
Ahhh.. I read right over that... Well, you can assign the property as long as you assign the field also. When building a struct constructor, the constructor must not exit until all fields have been assigned. Of course, you're thinking to yourself, "It does get assigned when the property is assigned"... unfortunately the compiler doesn't see that
|
|
|
|
|
Right. And that's how I answered him.
I can see the logic behind the compiler not looking through the property to see that the field gets initialized. For instance, what if your property setter utilized another field in the struct that hadn't been initialized yet? If you just make it a hard and fast rule of structs that they must have all their fields initialized before you use any of them, then it simplifies the work that the compiler has to do.
There's always reference types.
Picture a huge catholic cathedral. In it there's many people, including a gregorian monk choir. You know, those who sing beautifully. Then they start singing, in latin, as they always do: "Ad hominem..."
-Jörgen Sigvardsson
|
|
|
|
|
Yessir
|
|
|
|
|
It looks like, from reading the specification, you're not allowed to utilize any instance members of the type until after it's been fully initialized (viz. all of its consituent fields have been initialized). And since Propertyx is an instance member and fieldx hasn't been set yet, you can't use Propertyx. I could be wrong through. Try setting fieldx and then using Propertyx...see what that gives you.
Picture a huge catholic cathedral. In it there's many people, including a gregorian monk choir. You know, those who sing beautifully. Then they start singing, in latin, as they always do: "Ad hominem..."
-Jörgen Sigvardsson
|
|
|
|