|
never mind what i said, i give up
i'm just going to use a dataview and sort it like that
thx a lot for your help
|
|
|
|
|
Okay, the situation is this: I saved a Bitmap using the Bitmap.Save method into a MemoryStream and then I used the MemoryStream.ToArray() method to turn it into a Byte[] array. I used a Socket to send the the Byte[] (buffer) and recieved the buffer in a remote side (Mostly on a Pocket PC), I cannot seem to find a way to return that Byte[] back to a Bitmap, I tried using the MemoryStream(Byte[]) constructor in order to save it on a memory stream, and then using the Bitmap(System.IO.Stream) constructor but it returns an exception stating that it is an invalid parameter or argument, I would thank all who could help me solve this problem, here's an example of what I have been doing to send and recieve my Bitmap:
//Sending:
Bitmap bmp = new Bitmap(@openDialog1.FileName);
System.IO.MemoryStream memImage = new MemoryStream();
bmp.Save(memImage,System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] data = memImage.ToArray();
IPEndPoint endPoint = new IPEndPoint(this.theIP,651); //this.theIP = my IP
socket.Connect(endPoint);
socket.Send(data,0,data.Length,SocketFlags.None);
//Recieving
IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse("..my Ip.."),651);
this.socket.Bind(endPoint);
this.socket.Listen(10);
Socket connected = socket.Accept();
byte[] byteResponse = new byte[1024];
connected.Receive(byteResponse,SocketFlags.None);
MemoryStream memory = new MemoryStream(byteResponse);
Bitmap bmp = new Bitmap(memory); //generates invalid argument exception
this.pictureBox1.Image = bmp;
Could anyone help me and also point out my errors here, I would be a great help, thanks in advanced.
P.S. I really would prefer a method that would work in the Compact Framework, since I am working with a Pocket PC as a reciever.
|
|
|
|
|
Hi Gakujin,
To construct an image object (in your case a Bitmap, which is derived from Image) from a MemoryStream object use the Image.FromStream static method.
so simply replace:
Bitmap bmp = new Bitmap(memory);
with
Image img = Image.FromStream(memory);
I am not sure about the compact framework, but I presume loading from a stream should work, since you can save to a stream already.
EDIT: Sorry I didn't notice that the Bitmap constructor already does this, so ignore me 
|
|
|
|
|
Yes, you would have to use the Bitmap constructor since Image.FromStream is not supported on .NET CF. Just FYI
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hi, it's possible to include files such ini and dll into a exe as resource???
thanks
Paolo
|
|
|
|
|
You can include every file as a resource, and read it with manifest stream:
Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(namespace.filename.ini);
|
|
|
|
|
sorry for this stupid question.....and for adding a resource? in VS C++ 6.0 that wass add resource.....here where I found? thanks
|
|
|
|
|
In VS.NET it is
- project's context menu
- add existing element
- choose the file
- the file appears in the project tree
- file's context menu
- properties
- build action = embedded resource
The menu titles can be different in your visual studio, because I have only the german version 
|
|
|
|
|
|
I'm not able to write the Assembly stream to file, I've done so
<br />
private void ExtractDLL()<br />
{<br />
<br />
try<br />
{<br />
FileStream sf = new FileStream("config.ini",FileMode.Create);<br />
StreamWriter sw = new StreamWriter(sf);<br />
Stream prova = Assembly.GetExecutingAssembly().GetManifestResourceStream("config.ini");<br />
<br />
sw.Write(prova);<br />
}<br />
<br />
catch (IOException e)<br />
{<br />
MessageBox.Show("Error while accessing to resources -> " + e.Message);<br />
return;<br />
}<br />
}<br />
but I get a 0 byte file.... where I'm wrong??? thanks
Paolo
|
|
|
|
|
You must include the full qualified path of the ressource. The ressource is a part of your assembly, so the namespace belongs to its name:
<br />
Stream prova = Assembly.GetExecutingAssembly().GetManifestResourceStream("yourNamespace.config.ini");<br />
|
|
|
|
|
I'm trying to do this;
I ask;
Console.Writeline("Enter Amount");
Then I enter something like 500.10
and then I get a return value of;
"Five hundred dollars and ten cents"
What is the easiest way to do this?
Thank you for any help..
Karie
karie4@comcast.net
|
|
|
|
|
Hi Karie,
Using simple logic you can generate the desired result. I am not aware of any ready made class and function in .Net, especially dedicated for this sort of problem.
Regards,
Jay.
|
|
|
|
|
Sounds like homework to me!
RageInTheMachine9532
|
|
|
|
|
2.ToString() Shame on you!
KTB wrote that
|
|
|
|
|
A word map and simple subtraction would do, but I agree with Dave that this sounds like homework.
You can get some help, though. See my article, Custom String Formatting in .NET[^], for an example that does something similar to what you need to convert numbers to Roman numerals.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
I'm going to add "Undo" "Redo" function for my project. But I really have no idea to do such things.
Is there any examples for this? Could anyone provide some for me??
Thanks a lot
|
|
|
|
|
You have two options
1. Brute force. Fill memory with copies of your document
2. Build a list of operations performed, and walk through them, changing the state of your document as you go.
What sort of document is it ?
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Actually, the undo-redo option is use for UI changing.
e.g. wrong deleting in listview item,
wrong arranging in listview,
wrong setting of my customer object, position etc...
this is quite a wide range I need to record, looks complex to do this...
|
|
|
|
|
azusakt wrote:
this is quite a wide range I need to record, looks complex to do this...
Yeah, it sounds like you need to build a class heirarchy to do it.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
So, do you know where can I find a good example ?
I really have no idea how to do this ~
Christian Graus wrote:
Yeah, it sounds like you need to build a class heirarchy to do it.
what will the class do ?? can anyone help?
|
|
|
|
|
Examples probably exist on the web, but I don't know of any. I did this years ago, for a paint program. I think we stored small bitmaps that represented the section of the image that was changed, along with a position to draw them back.
azusakt wrote:
what will the class do ??
If there's a wide variety of changes to be done, each class will be able to perform the modifications needed to undo one action. I'd imagine they might use the visitor pattern ? I'd imagine a base class, then a derived class at least for each type of object that can have an undo done on it.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Undo can be done using the Memento pattern. U can get help on this pattern from the internet. Maybe some examples too
« Superman »
|
|
|
|
|
Another couple options - one of which is common - is for each command (which Christian was probably referring to) to store how it undoes itself and then use a linked-list to store each command along with state information.
Another example uses memory protection faults to your advantage. See Undo and Redo the "Easy" Way[^], which also includes links to several other articles that discuss other methods, some of which Christian mentioned.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
What trouble am I gonna get into trying to convert C# code to FORTRAN 95 Code? DOes anyone have a solution to any known issues? Is there a .NET solution?
Jack Connolly
|
|
|
|