|
GDI+ will copy part of an image on top of another image.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
The GDI+ library works realy fast, how fast it can be, I'll see tomorow
Thanks for indication me the right path, previously I convert a Bitmap to byte array and work with it. It have caused many problems with image stride.
|
|
|
|
|
Yeah, if you access the stride, it will blow up. It's good for image processing, for drawing, you're better off trusting GDI+ to know what it's doing.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Hi,
I would like to deserialized in class and XML document which can be found on this URL : http://ws.audioscrobbler.com/1.0/artist/Metallica/similar.xml
Here is my two class to deserialized this XML but i've got a problem. After deserialization, i've got in attributes SimilarArtists.artists a list of 100 artists (which is good) but all artist's attributes are null (for string) or zero (for int).
There's something wrong but i don't see..
maybe someone can see something that i can't ?
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using System.Net;
using System.IO;
namespace Xtream_ToolBox.Sensors {
[XmlRoot("similarartists")]
public class SimilarArtists {
[XmlIgnore]
public List<Artist> artists = new List<Artist>();
public SimilarArtists() {
}
public static SimilarArtists loadFromUrl(String url) {
SimilarArtists similarArtists = null;
Uri uri = new Uri(url);
XmlSerializer xmlSerializer = new XmlSerializer(typeof(SimilarArtists));
try {
WebResponse webResponse = HttpWebRequest.CreateDefault(uri).GetResponse();
Stream stream = webResponse.GetResponseStream();
similarArtists = (SimilarArtists)xmlSerializer.Deserialize(stream);
stream.Close();
} catch (Exception e) {
Console.WriteLine(e.Message);
}
return similarArtists;
}
[XmlElement("artist")]
public Artist[] artistArray {
get {
Artist[] artistArray = new Artist[artists.Count];
artists.CopyTo(artistArray);
return artistArray;
}
set {
if (value == null) return;
Artist[] artistArray = (Artist[])value;
artists.Clear();
foreach (Artist artist in artistArray) {
artists.Add(artist);
}
}
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
namespace Xtream_ToolBox.Sensors {
public class Artist {
[XmlAttribute("name")]
public String name;
[XmlAttribute("match")]
public int match;
[XmlAttribute("url")]
public String url;
[XmlAttribute("image_small")]
public String imageSmall;
public Artist() {
}
}
}
-- modified at 6:53 Saturday 3rd February, 2007
nobody has an idea ?
|
|
|
|
|
I am pretty new to c# and I'm writing my thesis on Bio Sequence Alignment So I have alot to do with generating random strings.
This is a *very cut down version of my problem, it is the shortest snippet that explains my predicament.
namespace MyConsoleApp
{
class Program
{
static void Main(string[] args)
{
MyClass fred = new MyClass();
MyClass jim = new MyClass();
fred.generate();
jim.generate();
Console.WriteLine(fred.MyString);
Console.WriteLine(jim.MyString);
Console.ReadLine();
}
}
public class MyClass {
private Random rand;
public string MyString;
public MyClass()
{
this.rand = new Random();
}
public void generate()
{
StringBuilder tempString = new StringBuilder();
for (int i = 0; i < 6; i++)
{
tempString.Append(getRandomChar());
}
this.MyString = tempString.ToString();
}
private char getRandomChar()
{
int num;
num = getRandomInt(0, 2);
if (num < 1) { return 'A'; }
else if (num < 2) { return 'B'; }
else { return 'C'; }
}
private int getRandomInt(int lower, int upper)
{
if (lower > upper)
{
int temp = upper;
upper = lower;
lower = temp;
}
else if (upper == lower)
{
return upper;
}
return (rand.Next() % (upper - lower + 1)) + lower;
}
}
}
I believe this should print out two completely different strings but in reality it prints out two identical strings.
Why oh why is this happening?
More than a solution to this exact problem I wouldn't mind learning what subtle point of c# is causing this.
Oh, and a solution would be good too...
Cheers.
|
|
|
|
|
Put a delay in between your constructors. Random is getting seeded with the same time, so it's not very random for each "generated" class.
Better yet, use a common Random class, so it gets seeded only once. There's no reason to create multiple Random classes with what ends up being the same seed because the code executes so fast the time doesn't change.
Marc
Thyme In The CountryPeople are just notoriously impossible. --DavidCrow There's NO excuse for not commenting your code. -- John Simmons / outlaw programmer People who say that they will refactor their code later to make it "good" don't understand refactoring, nor the art and craft of programming. -- Josh Smith
|
|
|
|
|
Well, you're getting the same sequence of random numbers.
You either need to have the constructor specify a seed, or...
What I suggest, in this case, is to make the Random static so all the instances of MyClass use the same instance of Random
private static Random rand = new Random();
You may then need to have MyClass lock the Random when it uses it
<br />
lock ( rand )<br />
{<br />
return (rand.Next() % (upper - lower + 1)) + lower;<br />
}<br />
|
|
|
|
|
Thankyou!
Once you explained it it made perfect sense.
The actual code I have is pretty long and I never thought it would execute the whole thing in under a second.
I've taken all you advice on board.
Just a note:
Is it best practice to instantiate one Random for the whole project and then pass it around to any classes that need to use random numbers/strings and use lock(...) or is that overkill?
Once again thanks very much.
...Pirates are like the new cowboys...
|
|
|
|
|
The random object initialises itself using the time at the time it is created. If you create the 2 instances in the same millisecond they will return the same sequence regardless of how long you leave the objects sitting around.
If you are using a lot of random generation stick the random object inside a static class and instantiate it once for the whole app. Someone else provided the locking code in their post.
Russell
|
|
|
|
|
As a sidenote since the other guys solved your problem, the following code is redundant:
crunchi wrote: private int getRandomInt(int lower, int upper)
Instead, you can use random.Next(lower, upper);
|
|
|
|
|
Thanks,
I'm comming over to c# from Win32ASM and I'm just used to having to do everything myself...
...Pirates are like the new cowboys...
|
|
|
|
|
crunchi wrote: I'm comming over to c# from Win32ASM and I'm just used to having to do everything myself...
Yeah, I remember that stuff. Things are a lot easier with the framework. It comes at a cost, of course (your app uses more memory, takes longer to start up, requires the .NET runtime), but IMO it's worth it.
|
|
|
|
|
Filtering a column in a datatable, but I keep getting a error when the nothing is found in the filter.[Modified]When there are not any results returned.[Modified] Using the filter there will either be a record or not. I do not have to worry about multiple results.
<br />
DataRow[] _dr = _Master.Select("[EU ID]=" + RecID);<br />
if (_dr.Length == 1)<br />
{<br />
}<br />
Does this not cause the DataRow to have 0 rows or 1 row??
What am I missing?
Urgently!!!!!! not in a hurry about this.
-- modified at 12:34 Thursday 1st February, 2007
Well never mind just went ahead and did this way, works just fine.
<br />
for (int i = 0; i < _Master.Rows.Count; i++)<br />
{<br />
if ((string)_Master.Rows[i]["EU ID"] == RecID)<br />
{<br />
}<br />
}<br />
|
|
|
|
|
|
Hello All:
I need to use "Button" as to Browse and being able to select a Directory then display that on a TextBox. I use this -->OpenFileDialog dlg = new OpenFileDialog(); but it allows me to select file instead.
Please help.
Thanks,
Eyungwah
|
|
|
|
|
Look at FolderBrowserDialog class
Luc Pattyn
|
|
|
|
|
Hi,
Just started learning C# last week; I am trying to figure out if there is some sort of standard data structure similar to a vector?
Thanks,
RishiD
|
|
|
|
|
|
Yes, most of the things you found in Java you will find again in .NET, the names may
differ tho.
For your specific question, have a look inside Visual's MSDN under "Collections".
Luc Pattyn
|
|
|
|
|
In particular, look under System.Collections.Generic
Generics are not STL, but they end up having similarities.
Marc
Thyme In The CountryPeople are just notoriously impossible. --DavidCrow There's NO excuse for not commenting your code. -- John Simmons / outlaw programmer People who say that they will refactor their code later to make it "good" don't understand refactoring, nor the art and craft of programming. -- Josh Smith
|
|
|
|
|
hello every one.
well my question is simply this
how to put the gradient effect on the BindingNavigator object's bacground in Windows Forms??
I've noticed that once I've changed the background color of a binding Navigator, it just shows u the color in a plain n simple way u know. and it doesnt look too good either, So plz help if u can,
thanks
Rocky
|
|
|
|
|
I'm having trouble understanding how to work with controls (RTBs for example) on TabPages which I've added to the application programmatically.
I have a C# Windows.Form app with a menustrip including std entries, a TabControl to which I'm adding TabPages and a StatusStrip. Simple stuff.
In the event handler for the "New" menu option, I create the new TabPage and add a control like a RichTextBox to it. Works fine so far.
When I try to access the RTB to do something like Copy or Paste by clicking on their menu options, I seem to lose the plot. I can't seem to get this to work. I suspect I've structured the program wrong but not sure how to resolve this. The app compiles but I get "out scope" types of messages when I run it and try to use menu options to access the controls on the TabPages. I'm using VS2005 BTW.
I've tried looking at many other code examples but they are either far to complex for me to easily work out the proper structure (SharpDev for example) or don't do what I'm trying to do so they don't apply to my situation. Some of them probably hold the answer but I'm just to thick to get it
Any help or advice would be greatly appreciated. Thanks
JimKeating
|
|
|
|
|
Hi,
first and for all there is no fundamental difference between Controls added by using the
Visual Studio Designer, and Controls added programmatically; after all the only thing
Designer does is adding code to yours, so you may want to have a look at how it translater
your interactions into real code.
Second, the trick is in keeping a reference to the Controls you create:
class XXX {
void addALabel() {
Label label1=new Label();
label1.Text="unaccessible";
this.Controls.Add(label1);
}
private Label label2;
void addAnotherLabel() {
label2=new Label();
label2.Text="good";
this.Controls.Add(label2);
}
void changeALabel() {
label2.Text="new text";
}
}
In the above example, label1 is created, added to the form, it will be visible, but
you can not (at least not easoly) change it anymore, since the variable "label1" indeed
is "out of scope" as soon as the {} brackets around it get closed.
On the other hand, label2 is available (as long as its surrounding brackets dont close).
So the changeALabel() method can change its text.
The same applies to all kinds of Controls, in no matter how complex your form gets.
Hope this helps.
Luc Pattyn
|
|
|
|
|
Luc,
Thanks for the reply. I understand your example. Your explaination should put me on the right track. Now I just need to translate your explanationand example into my own code and I should be on my way.
Thanks for the help.
Jim
|
|
|
|
|
I have 3 dlls involved in this. One is a 3rd party enhanced messagebox class. The second is several shared gui components that includes a wrapper to the 3rd party lib (I want to keep the wrapper separate to make updating the lib as easy as possible). The third consists of primarily nonGUI components. A few of those components do however spit out messageboxes in certain error conditions. The shared GUI components dll extensively references the shared nonGUI dll, so that dependency isn't changable. The problem is that when I try to have the nonGUI dll reference the GUIdll, which I only need for the messagebox wrapper, VS won't allow me to do so because it would create a circular dependency.
Am I correct in thinking my only options are to move the messagebox wrapper out of the shared GUI dll so that I can reference its new location from both, or to modify the classes in the nonGUI dll so that they let all their problem reports float up to a higher level before informing the user?
--
Rules of thumb should not be taken for the whole hand.
|
|
|
|