|
<br />
<span style="color: #0000FF;">public static</span> Bitmap BytesToBmp( <span style="color: #0000FF;">byte</span>[] b, <span style="color: color: #00CC99;">Size</span> imageSize )<br />
{<br />
<div style="padding-left: 5px;"><br />
<span style="color: #009933;">
</div><br />
<div style="padding-left: 5px;"><br />
<span style="color: color: #00CC99;">MemoryStream</span> stream = <span style="color: #0000FF;">new</span> <span style="color: color: #00CC99;">MemoryStream</span>( b, <span style="color: #0000FF;">true</span> ); <br />
</div><br />
<div style="padding-left: 5px;"><br />
stream.Write( b, 0, b.Length ); <br />
</div><br />
<div style="padding-left: 5px;"><br />
<span style="color: #009933;">
</div><br />
<div style="padding-left: 5px;"><br />
<span style="color: color: #00CC99;">Bitmap</span> bmp = <span style="color: #0000FF;">new</span> <span style="color: color: #00CC99;">Bitmap</span>( stream ); <br />
</div><br />
<div style="padding-left: 5px;"><br />
stream.Close(); <br />
</div><br />
<div style="padding-left: 5px;"><br />
bmp = <span style="color: #0000FF;">null</span>; <br />
</div><br />
<div style="padding-left: 5px;"><br />
<span style="color: #0000FF;">return new</span> <span style="color: color: #00CC99;">Bitmap</span>( bmp, imageSize ); <br />
</div><br />
}<br />
I'm getting an error: System.ArgumentException: Parameter is not valid.
Then when I use the Stream Object I get:
Cannot create an instance of the abstract class or interface 'System.IO.Stream'.
I'm at a lose on how to create a Bitmap from a Stream if I can not create a Stream.
I was under the impression that a derived class such as: MemoryStream would work.
Any help explaining this would be helpful.
Thanks.
I'm listening but I only speak GEEK.
|
|
|
|
|
I did something like this the other day, using the static Bitmap.FromStream() method. Here's my code - my bitmap was encoded in a string...
<br />
MemoryStream ms = new MemoryStream( Convert.FromBase64String( eImage.InnerText ) );<br />
Bitmap bmp = Bitmap.FromStream( ms ) as Bitmap;<br />
Why do you stream.Write()? Isn't the data already in the MemoryStream from the constructor?
I also don't understand why you set bmp = null, or what the purpose of constructing a new Bitmap on return.
|
|
|
|
|
Nick Hodapp wrote: Why do you stream.Write()?
Basiclly this is the first time I'd used it and based of examples I'd found, I thought I need to perform the write to prepare the stream.
Nick Hodapp wrote: I also don't understand why you set bmp = null
I'll be calling this method hundreds of times with ASP.NET and will need to make sure that Garbage Collector knows I'm done with the variable.
I'm still getting the same error message[^]. I've added a link to a screen shot of the error message. Thanks for your help.
I'm listening but I only speak GEEK.
|
|
|
|
|
Parts of your code are a mess. Also, you don't say where the errors occurred - this is important and I cannot guess where.
Lets examine the code:
MemoryStream stream = new MemoryStream( b, true );
stream.Write( b, 0, b.Length );
I'm not sure about your thought processes here. You create a MemoryStream using the contents of the buffer, b, which contains the data. Then you write the contents of b into the stream. But the stream already contains the contents of b. I suggest that the Write operation is redundant.
Bitmap bmp = new Bitmap( stream );
stream.Close();
This seems reasonable.
bmp = null;
return new Bitmap( bmp, imageSize );
I am curious as to what you think this actually does. I don't mean to be unkind, but I really don't understand your thought process.
The following would seem to be a good way forward:
using(MemoryStream ms = new MemoryStream(b))
{
Bitmap bmp = new Bitmap(ms);
return bmp;
}
|
|
|
|
|
Colin Angus Mackay wrote: Also, you don't say where the errors occurred
Error Message[^]
Understanding the logic behind the MemoryStream basiclly this is the first time I'd used it and based of examples I'd found, I thought I need to perform the write to prepare the stream.
I'm still getting the same error message. I've added a link to a screen shot of the error message. Thanks for your help.
I'm listening but I only speak GEEK.
|
|
|
|
|
Thank you every one for your help.
public static Bitmap BytesToBmp( byte[] b )
{
using ( MemoryStream ms = new MemoryStream(b , true) )
{
Bitmap bmp = Bitmap.FromStream( ms ) as Bitmap;
return bmp;
}
}
Works great. This is was the byte[] that I was sending the method; it was not being recognized by the Bitmap Constructor. I am storing images within an Access 2003 db, (yes, not a good idea), and the way Access had been altering the byte [] so that the Bitmap Constructor couldn't recreate it. I'm not sure n exaclty what Access was doing with the Image but I as inserting a bitmap from file to it. ???
If anyone know the answer to this, please drop me a line. Otherwise, I'm now converting the image and inserting it into the database using a FileStream in and then a FileStream out. If anyone is interested I will post the project when I've completed.
Thanks again!!
I'm listening but I only speak GEEK.
|
|
|
|
|
'Adaptive Resonance Theory'
ART network is a 'Neural network'.
the goal is design an Art with C#,
because Matlab not supprt Art netwok.
in the network is a parameter than named vigilance factor
this factor to care network in front of learned pattern
|
|
|
|
|
Interesting. Do you have a concrete question too or are you simply expecting us to write the whole thing for you?
In case you're looking for some ideas on how to implement neural networks in C#, search the articles. There are some covering the topic.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
hello... i wanted to segment a picture into characters using histograms... i managed to do so but now the code throws exception "image already locked"...
this exception is not thrown all the time but is thrown sometime... i think it is because image although is unlocked (i did unlocking) according to statement but the area might still be captured in ram or so... plz correct me if i am wrong and also show me some way to control the exception as it occurs at times and not all the time....
please provide help
and are there any algos for character segmentation apart from histogram and connected components one... which will work better...
haseeb
|
|
|
|
|
Hi!
i have a problem!
i have a datagrid and when the focu is on it and click on enter, the focu pass to the next row. How i do to take off it! I'd like to disable it to not pass to the next row.
help me!!
Thanks
|
|
|
|
|
Hi,
You could code the following
<br />
private void dataGridView1_KeyDown(object sender, KeyEventArgs e)<br />
{<br />
if (e.KeyCode == Keys.Enter)<br />
e.Handled = true;<br />
}
Hopes this helps...
Greetings
Kaine
|
|
|
|
|
Thanks for help me!
this code was great, it helped a lot.
if (e.KeyCode == Keys.Enter)
e.Handled = true;
Thanks again!!
|
|
|
|
|
Hi, I have a question related to reporting.
Right now I'm trying it with Crystal Reports, but I'm open to other suggestions. I need to make some letters generated from a customer file in a MySQL DB.
The letters would involve some fixed text, some variable field in and under the text.
What are the best ways to generate reports for MS Word or in PDF when I have a class that looks like this f.e.:
Rappel
- customerName
- customerStreet
- customerPostal
- quantityBehindOnPayment
- comments
or little more complex
Invoice
- customerName
- customerStreet
- customerPostal
- customerCode
- InvoiceLines (list)
- total
- comments
If the answer is going to be "use Crystal Reports", can anyone direct me towards a decent tutorial, example or anything for using this kind of reports? Because I'm kind of struggling. Thanks in advance.
The output can be anything as long as its printable (.doc, .pdf, .html,...)
Visual Studio can't evaluate this, can you?
public object moo<br />
{<br />
__get { return moo; }<br />
__set { moo = value; }<br />
}
|
|
|
|
|
Good evening everyone,
I'm trying to write to an existing file using the StreamWriter and I cant replace the entire text in an existing file.. for example if I wrote xxx to file already contains oooo, the result will be xxxo
Please help
Smile: A curve that can set a lot of things straight!
(\ /)
(O.o)
(><)
|
|
|
|
|
You don't really have a choice here. You read the file, modify the contents how you want in memory, then write it back out.
The only opther way to do it would be to treat the file as Binary, not Text and start modifying the individual bytes of the file. But then you'll also have to worry about encoding and Unicode (multi-byte characters).
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Thanks Dave, you're really a MVP, at least to me
Pleased to meet you and thank you for your true help every time.
ps. I liked the first tip and will use it, thanks again Dave
Smile: A curve that can set a lot of things straight!
(\ /)
(O.o)
(><)
|
|
|
|
|
The StreamWriter class provides constructors that allow you to specify whether you want to overwrite or append in case the file already exists. Use one of those to create your StreamWriter .
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
PERFECT!!
StreamWriter sw = new StreamWriter("MyFile.txt", false);
Thank you Stef
BTW: My best friend is called Stefan as well
Smile: A curve that can set a lot of things straight!
(\ /)
(O.o)
(><)
|
|
|
|
|
one thing that u can do is to read the entire file as a single string by using a stream reader and then replace the old string with whatever you want.
u will have to use a StreamWriter in that case.
string OldString = streamReader.ReadToEnd();
string NewString = OldString.Replace(OldString, "NewString");
Keshav Kamat
India
|
|
|
|
|
Thank you for your help Keshav
Smile: A curve that can set a lot of things straight!
(\ /)
(O.o)
(><)
|
|
|
|
|
i have an web application. from here i want start a new process in local mechine. if i start the process it is shown it the task Manager doesn't comes as active window. becase it is runing under ASP.NET user.
is there any way to change the owner for the process before we start?
or
can we bring the aplication intractive with out changing the owner in ASP.NET?
help me
|
|
|
|
|
I have about 3 minutes to dinnertime, so can't look into it too deeply. But here are some links
This forum tells you to go to MSDN and read on Impersonation
http://www.thescripts.com/forum/thread576383.html
Here is the msdn link
http://msdn2.microsoft.com/en-us/library/ms998351.aspx
http://msdn2.microsoft.com/en-us/library/system.security.principal.windowsidentity.impersonate.aspx
hope this gets you going
Visual Studio can't evaluate this, can you?
public object moo<br />
{<br />
__get { return moo; }<br />
__set { moo = value; }<br />
}
|
|
|
|
|
Thank U friends
for u r help
joe
india
|
|
|
|
|
to start a process as a different user, please follow this link
http:
for general process start procedure use this...
http:
Keshav Kamat
India
|
|
|
|
|
Here's an interesting one -- Can someone riddle me this?
Given:
<br />
using System;<br />
<br />
enum Foo { Bar, None }<br />
class Program<br />
{<br />
static void PrintArg(object x) { Console.WriteLine(x.ToString()); }<br />
static void PrintArg(Foo x) { Console.WriteLine(x.ToString()); }<br />
public static void Main()<br />
{<br />
PrintArg(Foo.None);<br />
PrintArg(0);<br />
PrintArg(1);<br />
}<br />
}<br />
Results in the output of:
None
Bar
1
Note: The application of this issue is apparent in the SqlParameter constructors -- If you do SqlParameter param = new SqlParameter("Name", 0); it calls the SqlDbType override, instead of the object value override.
Any ideas why the int 0 isn't acting like the int 1? Is 0 not an int by default?
Chadwick
=============================
I'm a developer, he's a developer, she's a developer, Wouldn'tcha like to be a developer too?
|
|
|
|