|
Sorry, I was not aware of that method. It seems to be exactly what you need, and
I'm glad to have learned this today.
Cheers.
|
|
|
|
|
Hi,
In my application I am reading an image and storing in the byte[], this value is added in the hashtable for accessing in another class, now i need to access the byte[] present in the hashtable and display the image back,
Can any one give me an idea how this can be done,
I tried doing with the following code
byte[] myByteArray = (byte[])htnew["CoalMill1"];
MemoryStream ms = new MemoryStream(myByteArray,0,myByteArray.Length);
Bitmap bmp = (Bitmap)Bitmap.FromStream(ms);
bmp.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
here htnew is the hashtable which has a byte value of the image.
but i get "Parameter not valid" error.
any other ways to fetch the image back from hashtable
Thanks,
|
|
|
|
|
Why do you need to cast the result as byte[] ? Shouldn't it be that already ?
There's no other way to get data from a hash table, the odds are, your data is broken.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
since my appplication requirement is to create a window service and store the image , I am using the hashtable to maintain the image data, but while fetching using the above given code i get error,
I have a doubt like while storing the image in hashtabel i am initailizing the byte to 1024 , will that create any error of this type.
the code is given here:
ie reading from stream and storing as byte[]
Stream remoteStream = response.GetResponseStream();
byte[] buffer = new byte[1024];
int bytesRead;
do
{
readerWriter.AcquireWriterLock(5000);
bytesRead = remoteStream.Read(buffer, 0, buffer.Length);
readerWriter.ReleaseWriterLock();
} while (bytesRead > 0);
now adding the byte[] value in the hashtable present in another class.
ImageServer.ht.Add(strCameraName, img);
Thanks,
|
|
|
|
|
Why would you decompress the data into a Bitmap, only to compress it into binary data again on the next line? Just write the byte array to the response stream.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hi, i have error" Data type mismatch in criteria expression" when execute : clsADONET.setConnCommand_Close(sCommand) . Can explain for me what's wrong? here is the code. thanks
public void Update()
{
try
{
string cmd;
string field;
string parameter;
field = "Site,Model”;
parameter = "@Site,@model”;
cmd = "INSERT INTO Run(" + field + ") values (" + parameter + ")";
clsADONET.setConnCommand_Open(sCommand);
sCommand.CommandText = cmd;
sCommand.Parameters.Add("@Site", OleDbType.VarChar, 20);
sCommand.Parameters.Add("@Model", OleDbType.VarChar, 20);
sCommand.Parameters["@Site"].Value = CS.site;
sCommand.Parameters["@Model"].Value = CS.DUTSelected.ToString();
clsADONET.setConnCommand_Close(sCommand);
}
catch(Exception e)
{
MessageBox.Show(e.Message);
return;
}
}
class clsADONET
{
public static OleDbConnection sConnection = new OleDbConnection();
public static OleDbCommand sCommand = new OleDbCommand();
public static OleDbDataAdapter sAdapter = new OleDbDataAdapter();
public static void setConnCommand_Open(OleDbCommand sCommand)
{
setConnection(CommunicationSettings .DatabaseonServer);
sConnection.Open();
sCommand.Connection = sConnection;
}
public static void setConnCommand_Close(OleDbCommand sCommand)
{
try
{
sCommand.ExecuteNonQuery();
sCommand.Parameters.Clear();
sCommand.Connection.Close();
sConnection.Close();
}
catch (Exception e)
{
clsLog.LogEvent("Error", "", "Module:setConnCommand_Close(clsADONET.cs) ", e.Message, CommunicationSettings.EventNo);
}
}
public static void setConnection(string dataBaseLocation)
{
if (sConnection.State == ConnectionState.Open) sConnection.Close();
sConnection.ConnectionString = setConnectionString(dataBaseLocation, "");
}
}
|
|
|
|
|
Ok, I am not sure how to explain what i want but i will give it a go. Do you know those electronic circuit analysis programs where you can drag a resistor onto a page and construct a circuit? There are many other engineering programs that work in a similar way and perform calculations based on your design. I want to make an environment where i can construct a circuit. Is there an easy way to do this. Or is there any similar code i can use?
|
|
|
|
|
I'd imagine a base 'object' class, and then derived objects that represent resistors, etc. These would be added to a collection of objects as they are dropped on the screen. Calculating what the circuit created is, and so on, would be a whole bunch of work on top of that, obviously.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Paper clip: I see you are creating a transister radio; would you like some help with that?
|
|
|
|
|
*grin* NOW you're talking.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
PIEBALDconsult wrote: Paper clip
*shotgun* BANG, oh damn another screen gone......
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi,
if shooting monitors is a habit of yours, you should consider buying those new OLED ones.
They are organic, so given the right amount of nutrients and water may make them recover from modest shot wounds.
|
|
|
|
|
much cheaper to banish clippy to the pits of hell....
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
That won't cut it, if you dismiss Clippy then Rocky or one of his friends will haunt you.
|
|
|
|
|
thanks I will give it a go. Does anyone know of any code that i can work from?
|
|
|
|
|
The code below is for a button which saves the details on a form to the xml file. What I'm trying to do is get it so that:
a)It has a "Save" option
b)It also hase a "Save as" and creates a new file(name etc)
but, for the life of me i cant see what i'm doing wrong
private void button1_Click(object sender, EventArgs e)
{
if (openFileDialog1.FileName.Length > 0)
{
string path = openFileDialog1.FileName;
FileStream READER = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
System.Xml.XmlDocument CharDetail = new System.Xml.XmlDocument();
CharDetail.Load(READER);
System.Xml.XmlNodeList NodeList = CharDetail.GetElementsByTagName("Character");
NodeList[0].FirstChild.ChildNodes[0].InnerText = CharName.Text;
NodeList[0].FirstChild.ChildNodes[1].InnerText = Virtue.Text;
NodeList[0].FirstChild.ChildNodes[2].InnerText = Vice.Text;
FileStream WRITER = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
CharDetail.Save(WRITER);
}
}
This is the code for the SAVE function(eg overwrites the current file)..i'm trying to add a SAVE AS functionality to it
Now I know that the SaveFileDialog box should be used but where/how would i intergrate it?
|
|
|
|
|
System.Xml.XmlDocument.Save method does not take any FileStream as its parameter. So CharDetail.Save(WRITER); throws an exception. You can pass a string as your Xml file path to this method.
For Save As... your path will be the saveFileDialog's FileName property.
[Edit] Oops... My apologize... You can pass a FileStream as parameter since it's a Stream
I died as a mineral and became a plant,
I died as plant and rose to animal,
I died as animal and I was Man.
Why should I fear? When was I less by dying?
-- Rumi[^]
My blog
modified on Wednesday, November 26, 2008 3:27 PM
|
|
|
|
|
so is this what ya mean
string path2 = SFD.Filename;
FileStream WRITER = new FileStream(path2, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
CharDetail.Save(WRITER);
and that would create the new file? or am i missing something? (tis late and long dy at work so please treat me like the simpleton i am :-p)
|
|
|
|
|
Hi,
the difference between Save and Save As is that Save saves to a known location without any dialog (e.g. the result of an earlier OpenFileDialog OR an earlier SaveFileDialog), and Save As saves to an explicitly chosen location (e.g. the result of an instantaneous SaveFileDialog).
In all cases, the actual writing code is the same, it is only the path that differs. (In your case the first parameter of the FileStream constructor).
|
|
|
|
|
ok will give that a go later . Thanks
|
|
|
|
|
Yup, that exactly create a new file (assume you filtered SFD to *.xml).
I died as a mineral and became a plant,
I died as plant and rose to animal,
I died as animal and I was Man.
Why should I fear? When was I less by dying?
-- Rumi[^]
My blog
|
|
|
|
|
Chris Kentlea wrote: This is the code for the SAVE function(eg overwrites the current file)..i'm trying to add a SAVE AS functionality to it
The obvious way to do this is to factor out a save method that takes a path, then either show a dialog box to select a path and pass it along, or pass on the existing path, in the two event handlers.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
So I have some sample code, it works fine.
using System;
using System.Threading;
using System.IO;
namespace whatever
{
class t
{
public static TextWriter tw = new StreamWriter("date3.txt");
static void Main()
{
Thread firstThread = new Thread(new ThreadStart(Fun1));
Thread secondThread = new Thread(new ThreadStart(Fun2));
firstThread.Start();
secondThread.Start();
tw.WriteLine("End of Main()");
}
public static void Fun1()
{
for(int i=1; i<=500;i++)
{
tw.WriteLine("Fun1() writes: {0}",i);
}
}
public static void Fun2()
{
for (int i=0; i>= -200; i--)
{
tw.WriteLine("Fun2() writes: {0}",i);
}
}
}
}
From my understanding from what I've read, both firstThread and secondThread should be executed simultaniously, but my output shows that thread one finishes (outputs 0-500), then "End of Main()", followed by the output of Fun2 (0-200).
Shouldn't it have been mixed in there (the output from Fun1 and Fun2), or is each thread executed after the previous terminates?
|
|
|
|
|
Similar results here, although sometimes I get this:
Probable I/O race condition detected while copying memory. The I/O package is not thread safe by default. In multithreaded applications, a stream must be accessed in a thread-safe way, such as a thread-safe wrapper returned by TextReader's or TextWriter's Synchronized methods. This also applies to classes like StreamWriter and StreamReader.
I think it's just a case of the time taken to create the thread is longer than it takes to execute Fun1(). Change it from 500 to 5000000 and -200 to -2000000 and you'll get your interleaving - or would if it was threadsafe of course.
Regards,
Rob Philpott.
|
|
|
|
|
Ahh thanks, I first ran it with extremely small numbers (0 to 10, 0 to -10) and thought my 500/-200 changes would allow me to have the overlapping results I was testing for. Going to try now and if it works, I guess the error on my part is assuming the speed of threads to be higher/ slower then I expected.
Next time I'll test more thoroughly before posting.
Thanks again
|
|
|
|