|
Code doesn't seem to make sense. Could you try this?
private byte[] EncypteXoRImage(byte[] inputImage, byte[] byImage)
{
if (byImage == null)
return (byte[])inputImage.Clone();
byte[] result = new byte[inputImage.Length];
for (int k = 0; k < result.Length; k++)
{
result[k] = (byte)(inputImage[k] ^ byImage[k]);
}
return result;
}
|
|
|
|
|
You can make your method a lot easier to understand by using actual array references instead of GetValue and SetValue - and also by throwing awy unnecessary conversions:
private byte[] EncypteXoRImage(byte[] inputImage, byte[] byImage)
{
byte[] Result = (byte[])inputImage.Clone();
if (byImage == null)
return Result;
for (int k = inputImage.Length / 3; k < inputImage.Length; k++)
{
Result[k] ^= byImage[k % byImage.Length];
}
return Result;
}
However, it will have no affect on your problem - since the code is equivalent.
Out of interest, I tried this with two of my pictures:
private void myButton_Click(object sender, EventArgs e)
{
Image i = Image.FromFile(@"D:\Temp\MyPic.jpg");
Image j = Image.FromFile(@"D:\Temp\MyOtherPic.jpg");
pictureBox1.Image = i;
pictureBox2.Image = j;
MemoryStream msI = new MemoryStream();
i.Save(msI, System.Drawing.Imaging.ImageFormat.Bmp);
MemoryStream msJ = new MemoryStream();
j.Save(msJ, System.Drawing.Imaging.ImageFormat.Bmp);
byte[] res = EncypteXoRImage(msI.ToArray(), msJ.ToArray());
MemoryStream msK = new MemoryStream(res);
Image k = Image.FromStream(msK);
pictureBox3.Image = k;
}
private byte[] EncypteXoRImage(byte[] inputImage, byte[] byImage)
{
byte[] Result = (byte[])inputImage.Clone();
if (byImage == null)
return Result;
for (int k = inputImage.Length / 3; k < inputImage.Length; k++)
{
Result[k] ^= byImage[k % byImage.Length];
}
return Result;
}
Apart from being a pretty useless encryption technique (I could work out what both pictures were from the composite, pretty much, in the same way that I can read Captcha codes), it worked - I did not get a solid grey background with either version of your method.
So I assume it is your conversion from Image to byte array that is at fault.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Hi,
I have this error in my code that am having difficulties in rectifying it. Initially, my code looked like this..
private void CalculateTheMortgage()
{
double loanAmount = (double)txtLoanAmount.CurrentValue;
double taxesPerYear = (double)txtPropertyTax.CurrentValue;
double downPayment = (double)txtDownPayment.CurrentValue;
double interestRate = (double)udInterest.Value / 100;
double termOfLoan = (double)(udTerm.Value * 12);
double propertyTax = (double)txtPropertyTax.CurrentValue;
double insurance = (double)txtInsurance.CurrentValue;
double payment = (loanAmount - downPayment) * (Math.Pow((1 + interestRate/12), termOfLoan) * interestRate)/(12 * (Math.Pow((1+interestRate/12), termOfLoan) - 1));
payment = payment + (propertyTax + insurance) / 12;
txtPayment.CurrentValue = (int)payment;
}
and i changed it a little to this...
private void CalculateTheMortgage()
{
double loanAmount = Convert.ToDouble(txtLoanAmount.Text);
double taxesPerYear = Convert.ToDouble(txtPropertyTax.Text);
double downPayment = Convert.ToDouble(txtDownPayment.Text);
double interestRate = (double)udInterest.Value / 100;
double termOfLoan = (double)(udTerm.Value * 12);
double propertyTax = Convert.ToDouble(txtPropertyTax.Text);
double insurance = Convert.ToDouble(txtInsurance.Text);
double payment = (loanAmount - downPayment) * (Math.Pow((1 + interestRate / 12), termOfLoan) * interestRate) / (12 * (Math.Pow((1 + interestRate / 12), termOfLoan) - 1));
payment = payment + (propertyTax + insurance) / 12;
txtPayment.CurrentValue = (int)payment;
}
which removed the error message below. Now i wanna change this
txtPayment.CurrentValue = (int)payment; piece of code so that the same error cannot occur again. There is a blue line under 'CurrentValue'
This is the error am getting...
'System.Windows.Forms.TextBox' does not contain a definition for 'CurrentValue' and no extension method 'CurrentValue' accepting a first argument of type 'System.Windows.Forms.TextBox' could be found (are you missing a using directive or an assembly reference?)
Please help me here
Thanks
|
|
|
|
|
textbox.Text ?
|
|
|
|
|
When i write it like this
txtPayment.Text = (int)payment; am getting this error
Cannot implicitly convert type 'int' to 'string' with a blue line under '(int)'
|
|
|
|
|
Don't convert it to int when trying to put it into a textbox.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
txtPayment.Text = payment.ToString();
or:
txtPayment.Text = payment.ToString("0.00 $");
|
|
|
|
|
Can't believe it was that simple....
Thanks a lot!
It worked..
|
|
|
|
|
There are many things wrong here.
Convert.ToDouble will work and is preferable of
(double)somevalue but the best method is
double.TryParse or int.TryParse
Secondly you need to use
txtPayment.Text = payment.ToString(); and make sure payment is not null.
If you do want an integer, you need to indeed first cast the double to an integer and then that integer to a string (or use round and floor functions)
Why do you cast to double in these cases?
double interestRate = (double)udInterest.Value / 100;
double termOfLoan = (double)(udTerm.Value * 12);
What is this code for? Own project, a book, homework?
V.
|
|
|
|
|
Very minor, but...
V. wrote: make sure payment is not null
payment is a double (not double? ) so cannot be null
|
|
|
|
|
You're absolutely right.
V.
|
|
|
|
|
V. wrote: and is preferable
No it isn't.
V. wrote: the best method is
Not when a cast will do.
|
|
|
|
|
double.Parse is not equivalent to a double cast. One does a string-to-number conversion, the other does a number-to-number conversion. You can use Convert.ToDouble to do either, but I disagree that it's preferable for either scenario: use the mechanism that makes sense in context. A cast translates to a single IL opcode, not a whole method call, after all.
|
|
|
|
|
Hello!
It's been only a few weeks since I have started to learn WPF, and I came across some assignments that needed color changing in the images being generated. For this, I was able to use radio buttons and get away with it, but I am interested to find out about using colour pickers.
Any idea as to how? Please share with me. I would appreciate it if the app is really simple though, because I am just an enthusiastic beginner.
|
|
|
|
|
You mean something like this[^] one?
|
|
|
|
|
Yes, something like that, but much simpler, so that a beginner can grasp the idea behind it.....
|
|
|
|
|
I don't think you're going to get anything WPF based that's much simpler than that.
|
|
|
|
|
I have to agree with Pete on this one.
"I have a theory that the truth is never told during the nine-to-five hours. "
— Hunter S. Thompson
|
|
|
|
|
Look at the mouse move event on the colour picker control, that's where the 'magic' happens.
And ew, Sasha uses empty catch blocks? heh.
|
|
|
|
|
Hi,
I am using this to refer to the MdiParent:
BrowsePatientForm.MdiParent = this;
is it possible to to refer to specific form instead so it will be something like this:
BrowsePatientForm.MdiParent = frmMain;
|
|
|
|
|
jrahma wrote: is it possible to to refer to specific form instead
Yes it is.
|
|
|
|
|
but I am getting this when I try:
Error 13
|
|
|
|
|
You have to have an instance of frmMain before you can actually use it like this. You can't just give it a type name and hope that it knows how to handle this - what would happen, for example, if you have two instances of frmMain?
|
|
|
|
|
As Pete O'Hanlon has already said, you need to assign it an instance of your form.
Typically in an app, there would be only one MDI Form (although .NET allows you to have more than one). You instantiate it at the start of your program and hold a reference to the instance in a static field somewhere.
Alternatively, you can also make your MDI Form a Singelton.
|
|
|
|
|
So long as variable frmMain is the correct instance of the MDI child form, then yes, its ok.
|
|
|
|