|
are you asking how to sort on a custom object? or how to have a child class call a method on a parent class?
|
|
|
|
|
1) Your "class to be sorted" should implement IComparable<t> interface with you T = your class name.
2) You should add an event handler to fire property change events of your "class to be sorted" objects
3) Catch these events in your collection and use Array.Sort(myCollection)
OR
1) you can use a SortedList<tkey, tvalue=""> or SortedDisctionary<tkey, tvalue=""> as the collection of your "class to be sorted" objects and set TKey to the property of your "class to be sorted" but this property should be IComparable!
2) then when this property changes, your collection is automatically sorted
BUT these 2 options fails in your need to do a batch update and then sort + the ability to lock sorting, SO:
1) You should use a BatchUpdate after a number of updates are done for any "class to be sorted" object by keeping a int _updatecount static property in your Collection which is increased by each update to any of your object( if you use my 1st way, then you can increase this value in the property change event handler in your collection )
OR
2) The easiest and best way, do whatever update you want, then call Array.Sort(myCollection) where myCollection is ICollection
Hope this helps...
|
|
|
|
|
I'm putting together a program from various sources, like getting the thumbnail of a Window, and capturing window images using their handles.
However, all the sources that I've found so far are facing the same problem: When capturing the image of a particular Window using its handle, only the client area of the window shows up in the image. The glass title bar and border etc just show up blank. What is causing this problem? Is there a different way to do it on Vista where the entire Window is correctly captured?
Thanks.
|
|
|
|
|
Hi!
i'm trying to convert an image object to string and later bring it back from the string..
My code:
<br />
Image image = Image.FromFile(@"C:\08.jpg");
byte[] obj;<br />
<br />
using(MemoryStream ms = new MemoryStream()) {<br />
image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
obj = ms.ToArray();
}<br />
<br />
string str = System.Text.Encoding.ASCII.GetString(obj);
<br />
<br />
byte[] bytes = System.Text.Encoding.ASCII.GetBytes(str);
<br />
Image newImage;<br />
using(MemoryStream ms = new MemoryStream(bytes))<br />
newImage = Image.FromStream(ms);
in the *** line an exception ArgumentException "Parameter is not valid." is thrown..
if in the *#* line i change from Jpeg to Bmp the exception is not thrown but the image is scrambled..
thanks for any help!!
life is study!!!
|
|
|
|
|
Hi,
it is OK to use a byte[] to hold an image.
it is not OK to try and put that byte[] into a string, unless some
special conversion is applied that ensures a normal string results.
Possible encodings are HEX (which expands each byte to 2 chars,
and base64 (see Convert.To/FromBase64String() methods).
|
|
|
|
|
That's it!! Thanks a lot!!!
life is study!!!
|
|
|
|
|
Look at the BitConverter class, BitConverter.ToString Method (Byte[]).
http://stefanprodan.wordpress.com
|
|
|
|
|
thanks, but there is no overload for GetBytes(string s) in BitConverter class..
life is study!!!
|
|
|
|
|
Here is my code, I've test it with BMP but I think it will work with any image format.
<br />
using System.IO;<br />
using System.Drawing;<br />
using System.Runtime.Serialization.Formatters.Soap;<br />
<br />
Image image = Image.FromFile(file);
SoapFormatter formater = new SoapFormatter();<br />
byte[] obj;<br />
using (MemoryStream ms = new MemoryStream())<br />
{<br />
formater.Serialize(ms, image);<br />
obj = ms.ToArray();<br />
}<br />
<br />
string str = Convert.ToBase64String(obj);
<br />
byte[] bytes = Convert.FromBase64String(str);
<br />
Image newImage;<br />
using (MemoryStream ms = new MemoryStream(bytes))<br />
{<br />
newImage = (Image)formater.Deserialize(ms);<br />
}<br />
<br />
newImage.Save(file + ".bmp");<br />
http://stefanprodan.wordpress.com
|
|
|
|
|
if you use "using keyword" then the MemoryStream, which is in this case your raw image data, disposed. Copy the ms.ToArray() to a new byte[] by Array.Copy(...) method before you exit "using(...) block".
Hope this helps...
|
|
|
|
|
Hi All
I've just joined a project that is going to require a heavy load of optimization. I'm looking for a language that is compatible with C# that compiles into machine code. At the moment, our plan involves a number of nested loops to which we are hoping to write in machine code. Would C++ work for this? Thanks.
|
|
|
|
|
If you look inside a C++ application, there is a lot of overhead and name mangling that goes on. This can lead to loss of performance, but not necessarily. If you are looking to use a third generation language with close to optimal speed, then your best bet is C. If speed is an absolute must, then you need to look at assembly.
Something to keep in mind also is the balance between speed and memory optimization.
Phil
|
|
|
|
|
If you mean C# compiled to machine code, look at the Mono project.
|
|
|
|
|
How does mono compile C# to machine code exactly?
|
|
|
|
|
heavy load of optimization = ANSI C
http://stefanprodan.wordpress.com
|
|
|
|
|
Any .NET language is compatible. In fact there are other languages compatible, callable from managed (.NET) languages but that requires experience in these areas and I don't suggest it because no language is 100% compatible with another one
|
|
|
|
|
Is there such a thing as an infinite array in c#?
If not, does C# give the concept of vectors.
|
|
|
|
|
|
Interesting... Is there such a thing as a multidimensional list , like one that can have 3 columns per row?
|
|
|
|
|
I don't know specifically of a list like you're describing that can have any number of columns per row, other than just a multidimensional array - but that would have a finite size. You may be interested in a Dictionary[^] which allows you to create a dynamically sized list of key-value pairs. Other than that, if you want to store more than one value per element of a list, I usually make a structure/class to hold the values I want and then make a List of those structures.
|
|
|
|
|
LCI wrote: Interesting... Is there such a thing as a multidimensional list , like one that can have 3 columns per row?
How about a list of lists...
|
|
|
|
|
Or if the number of "columns" is constant, a list of arrays may be easier to work with.
---
single minded; short sighted; long gone;
|
|
|
|
|
Or rather an Array of List s...
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
An array of lists? That seems awkward. For example you can't use the built in methods for sorting.
---
single minded; short sighted; long gone;
|
|
|
|
|
Guffa wrote: Or if the number of "columns" is constant, a list of arrays may be easier to work with.
If you have a fixed number of columns and a variable number of rows, I think it's rather an array of lists than the other way 'round, but I guess it depends on the view...
Anyway, a list of lists would be the most flexible solution...
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|