|
I always get an argumentexception on the following code, and I don't know why.
bmp = new Bitmap(typeof(Form1), "toProcess.bmp"); //Read an image from hdd
MemoryStream mstream = new MemoryStream();
bmp.Save(mstream, ImageFormat.Jpeg); //Save image into MemoryStream in jpeg
jpegByteArray = new byte[mstream.Length];
mstream.Read(jpegByteArray, 0, (int)mstream.Length); //Read mstream into byte[]
MemoryStream jpegStream = new MemoryStream();
jpegstream.Write(jpegByteArray, 0, jpegByteArray.Length); //Write byte[] back to another MemoryStream
jpegstream.Position = 0;
Image newimg = Image.FromStream(jpegstream); //THIS throws an ArgumentException
I checked in debugging mode and every variable has the exact same number of bytes, and if I only save the image into a stream and read it right back, then it works. Please save me from pulling my hair out and shoot me with any help you can think of!
-- modified at 18:50 Monday 29th October, 2007
|
|
|
|
|
using System.IO;
private byte[] bImage;
private string strImagePath;
private FileStream objFileStream;
private MemoryStream objMemoryStream;
private Image objImage;
private void convertImageToByteArray()
{
strImagePath = "C:\\toProcess.bmp";
objFileStream = new FileStream(strImagePath, FileMode.OpenOrCreate, FileAccess.Read);
bImage = new byte[objFileStream.Length];
objFileStream.Read(bImage, 0, Convert.ToInt32(objFileStream.Length));
objFileStream.Close();
}
private void convertByteArrayToImage()
{
objMemoryStream = new MemoryStream(bImage);
objMemoryStream.Flush();
objImage = Image.FromStream(objMemoryStream);
objMemoryStream.Close();
}
|
|
|
|
|
Thank you! In the meantime I managed to solve my problem. Instead of using
mstream.Read(jpegByteArray, 0, (int)mstream.Length);
to read the MemoryStream's content into the byte[] I should have used
jpegByteArray = mstream.ToArray();
Don't ask me why this works and the other method doesn't, thereotically both should work. Anyway, I had to do this using only in-memory objects, because this is for realtime video stream processing.
Cheers
-- modified at 6:51 Tuesday 30th October, 2007
|
|
|
|
|
Hi
I have created dll using C# and add reference to another project that was written in VB.net.
so I have two project, one is using C#, the other one is using VB.net. Both written in Visual Studio.net 2005.
When I set break point of my function from dll project because that's what I want to debug.
So I started running CallingDll VB project in debug mode, I got following message
<br />
The following module was built either with optimizations enabled or without debug information:<br />
C:\myDll.dll<br />
<br />
To debug this module, change its poject build configuration to Debug mode. To supress this message, disalbe the "Warn if no user code on launch" debugger option.<br />
Where should I change it?
I went to Project\Properties, I couldnt' find anything that said Debug Mode.
I looked into Debug, I found StartAction, Start Options, enable debuggers.
I changed put Start external program: "c:\CallDll.exe" and then build and run the project in debug mode. but I still got the same message and I couldnt' debug myDll.dll at all neither from myDll project nor callDll project.
I also looked into Build.. I dont 'see anything that is saying debug mode.
I check the MSDN and saying the same thing.. to change it to Debug mode. But where should I go and change it so myDll.dll can be debug.
I recreated myDll.dll and CallDll.exe using visual studio 2003. I had no prolem debugging. but not with visual studio 2005.
Would anyone please tell me how to debug myDll.dll from another project like CallDll??
Thanks
|
|
|
|
|
[Build][Configuration Manager] ?? Just a guess.
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
"This time yesterday, I still had 24 hours to meet the deadline I've just missed today."
|
|
|
|
|
I found [Build][Comfiguration Manager] in Vistual Studio 2003. But not in visual studio 2005. I'm using Visual Studio 2005. I need to know how to debug myCShart.dll from different program that could be written in VB.Net, C# or C++.
|
|
|
|
|
Hey ya'll,
I've got a user control where I set the background to some color and when its disabled I want to lighten the color just a tad when its disabled. I know the ARGB value. I tried just setting the alpha value and the userControl didn't care for that.
[Question]Is there a formula, given the RGB value that calculates the lightened value for that color?
Thanks
MIke
Life is not measured by the number of breaths we take, but by the
moments that take our breath away. "George Carlin"
|
|
|
|
|
To lighten a colour, just increase the R, G, and B values by a set amout (say for example 10). But of course, don't go over 255.
So, say you had blue: 0,0,255; and you wanted to make it lighter: 40,40,255
Or if you had a dark yellow: 150,150,0; a little lighter: 190,190,40;
Aha, here it is. There's also this:
ControlPaint.Light(color, percentageBrighter);
Of course, changing the values yourself gives you more control.
There's also ControlPaint.Dark
My current favourite word is: Waffle
Cheese is still good though.
|
|
|
|
|
Duh, so obvious that I completely overlooked it guess I'm gettin tired.
Thanks for the input....worked like a charm!
Mike
Life is not measured by the number of breaths we take, but by the
moments that take our breath away. "George Carlin"
|
|
|
|
|
Hi,
I have always used the following coding when formatting dates for use with SQL:
bookingMadeDateTime.ToString("yyyy-MM-dd hh:mm:ss tt") <-- or very similar
however I have now been advised by a prospective user that they are using the following formats and the sql insert is failing:
Date: dd.MM.yy
Long date: dddd, dd' de 'MMMM' de 'yyyy
Time: hh:mm tt
The error is:
There was a syntax error in the date format. [ Expression = 2007-10-29 12:32:33 p.m. ]
The dates are entered using a datetime picker and I thought that by formatting the way I have, internationalization would be an issue. Also, the actual expression looks fine to me.
Can someone help me with this please.
Thanks.
Glen Harvy
|
|
|
|
|
Glen Harvy wrote: I have always used the following coding when formatting dates for use with SQL:
bookingMadeDateTime.ToString("yyyy-MM-dd hh:mm:ss tt") <-- or very similar
however I have now been advised by a prospective user that they are using the following formats and the sql insert is failing
Why would you be formatting dates for SQL Statements. Surely you would be passing this as a parameter? If you didn't use parameters your code would be highly susceptable to SQL Injection attacks, which would not be good.
Please read SQL Injection Attacks and Tips on How to Prevent Them[^] to secure your application. Incidentally it will also solve your current date formatting problem.
|
|
|
|
|
Colin Angus Mackay wrote: Why would you be formatting dates for SQL Statements. Surely you would be passing this as a parameter? If you didn't use parameters your code would be highly susceptable to SQL Injection attacks, which would not be good.
As the input is from a datetime picker and the user has no option but to select a date, I wasn't concerned with injection attacks.
I am happy to rewrite the code as you suggest ie paramaterized however I don't see this as solving the problem at hand ie the user hast his computer to use non-US English.
Does .Net automatically tanslate date formats?
Glen Harvy
|
|
|
|
|
Glen Harvy wrote: I am happy to rewrite the code as you suggest ie paramaterized however I don't see this as solving the problem at hand ie the user hast his computer to use non-US English.
Does .Net automatically tanslate date formats?
My PC is set to use Standard English rather than US English and I have no problems. If you use parameters then you don't have to worry about date formats, you just pass a DateTime object in to the parameter and set the SQL type of the parameter to DATETIME or SMALLDATETIME and that's all you need to do.
|
|
|
|
|
Thanks for this confirmation.
I have made some changes to the program as you suggest and it certainly seems to be working OK.
Glen Harvy
|
|
|
|
|
Further to your suggestion regarding parameters, how do I add this in an Insert Statement. I currently have the following Stingbuilder:
....
commandRecDetails.Append(" VALUES ( '");
commandRecDetails.Append(bookingMadeDateTime.ToString("yyyy-MM-dd hh:mm:ss tt") + "',");
commandRecDetails.Append(" " + courtNumber + ", ");
commandRecDetails.Append(" " + thisBookingNumber.ToString() + ", '");
etc etc....
recordBookingDetails.CommandText = commandRecDetails.ToString();
I can define the paramater
recordBookingDetails.Parameters.Add("DateMade", bookingMadeDateTime);
but how do I include it to replace the DateTime value in the string above?
Thanks.
Glen.
Glen Harvy
|
|
|
|
|
Your SQL String will look like this:
... VALUES(@dateMade, @courtNumber, @thisBookingNumber)
everything beginning with an @ is a parameter name.
Then add it with
recordBookingDetails.Parameters.AddWithValue("@dateMade", bookingMadeDateTime);
or
recordBookingDetails.Parameters.Add("@dateMade", SqlDbType.DateTime).Value = bookingMadeDateTime;
|
|
|
|
|
It doesn't get any better than this ...
Thanks again.
Glen Harvy
|
|
|
|
|
Always insist on ISO 8601 compliant date and time formats.
|
|
|
|
|
Within the multithreading enviroments, there is an exclusive lock provided by the .Net, which will block all other threads trying to enter the critical section if currently there is a threading holding this critical section.
But I'm trying to find a unblocking lock whick is exclusive but won't block other threads, just let them return and inform them the critical section is not available for them to access. Anyone knows if there is this kind of lock?
Thanks a lot;)
|
|
|
|
|
lock (obj) {
}
is just a syntax sugar for:
System.Threading.Monitor.Enter(obj);
try {
} finally {
System.Threading.Monitor.Exit(obj);
}
You should take a look at the other Monitor methods, there's a method called "TryEnter".
|
|
|
|
|
Thanks very much, it's really helpful!
|
|
|
|
|
Hi guys
Does anyone know how to cast the text of a textBox into a integer in C#?
Thanks and best wishes
|
|
|
|
|
You can't cast it. Use Int32.TryParse method.
[ My Blog] "Visual studio desperately needs some performance improvements. It is sometimes almost as slow as eclipse." - Rüdiger Klaehn "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe
|
|
|
|
|
Look at the Convert class. Type "Convert." and see what comes up in IntelliSense. You'll find Convert.ToInt32() is probably what you want. While it is not as save as Int32.TryParse(), it is quick and dirty.
Hogan
|
|
|
|
|
Most native numeric types in c# 2.0 have a "TryParse" method attached. An example method that would return the integer from a TextBox.Text property would be something like this:
<br />
public static int GetIntFromTextBox(TextBox textbox)<br />
{<br />
if(textbox != null && !string.IsNullOrEmpty(textbox.Text))<br />
{<br />
int myInt;<br />
<br />
string myNumberString = textbox.Text;<br />
int.TryParse(myNumberString, out myInt);<br />
<br />
return myInt;<br />
}<br />
return 0;<br />
}<br />
This will work for floats, doubles, etc as well. Just change the "datatype" in the TryParse line (double.TryParse() instead of int for instance). In the cases where the string is not a number, I believe it assigns zero (0), so the evaluation may not be neccessary.
-------------------------
Spiffdog Design
It's ok.. he's no ordinary dog...
|
|
|
|