|
That's what I just discovered, and above all, there is a HResult property in the System.Exception
Thanks.
This signature was proudly tested on animals.
|
|
|
|
|
|
baai koel
|
|
|
|
|
ja lekker hehe
|
|
|
|
|
Well I didnt really know, well maybe I did, I have been grinding on .NET for almost 7 years so I cant really recall. Anyways just follow the element of least surprise principle
|
|
|
|
|
I am using StreamWriter to write out some jpeg data in byte[] to a file.
The result of my file is always "System.Byte[]"
byte[] jpegData = new byte[img.Length];
jpegData = Convert.FromBase64String(img);
using (StreamWriter sr1 = new StreamWriter("C:\\123.jpg"))
{
sr1.Write(Convert.ToString(jpegData));
sr1.Flush();
sr1.Close();
}
|
|
|
|
|
Why don't you use BinaryWriter instead?
Giorgi Dalakishvili
#region signature
my articles
#endregion
|
|
|
|
|
System.IO.File.WriteAllBytes()
|
|
|
|
|
Thanks, this worked great.
Do you know how i would write this jpeg data in the form of byte[] to a form instead of to a file? So in other words i would like to display jpg on the form. Would i need a picture control?
|
|
|
|
|
You can simply do:
myform.BackgroundImage = Image.FromStream(new MemoryStream(jpegbytes));
|
|
|
|
|
thanks, i'll try that.
If i would like to put 4 images on the form, i would have to write them to a control write?
|
|
|
|
|
Hello I have one question regading the conversion of Hex String into Decimal number.
Hex Number is in format
“aaaaaa”
This 24-bit field is the direction “A” counter stored LS-byte first.
Example is, take this hex string "100000" which is decimal equivalent is 16
But i don't know how to convert this number into decimal number. If i give this number to C# function it is not giving me the exact 16 equivalent.
Another exanples are
060100= 262
1C0000= 28
Can any body please help me how to convert these numbers into decimal equivalent using C#
Thanks
Shailesh
|
|
|
|
|
int.Parse(hexValue, System.Globalization.NumberStyles.HexNumber);
Hogan
|
|
|
|
|
Thanks Hogan but i think you did not read the question. It is writing the LS byte first when i use your solution it is giving me 1048576 not 16.
Any body please help me
Thanks in advance
shailesh
|
|
|
|
|
shailesh,
Sorry about that. I usually thing of "LS" as a different model of a car, not part of definition of the problem. I assume LS means "Left Side" then?
Hogan
|
|
|
|
|
snorkie wrote: I assume LS means "Left Side" then?
Close It means Least Significant.
|
|
|
|
|
I felt bad about giving a bad answer, so I wrote a whole program to do this. Hope this helps... Sorry I was too lazy to comment the code.
using System;
using System.Collections.Generic;
using System.Text;
namespace ReverseHex
{
class Program
{
static void Main(string[] args)
{
string hexValue = Console.ReadLine();
int finalNumber = 0;
int multiplyCount = 0;
for (int x = hexValue.Length - 1; x >= 0; x--)
{
int tempAdd = multiplyCount * 15;
switch (hexValue[x])
{
case '1':
finalNumber += tempAdd + 1;
break;
case '2':
finalNumber += tempAdd + 2;
break;
case '3':
finalNumber += tempAdd + 3;
break;
case '4':
finalNumber += tempAdd + 4;
break;
case '5':
finalNumber += tempAdd + 5;
break;
case '6':
finalNumber += tempAdd + 6;
break;
case '7':
finalNumber += tempAdd + 7;
break;
case '8':
finalNumber += tempAdd + 8;
break;
case '9':
finalNumber += tempAdd + 9;
break;
case 'A':
case 'a':
finalNumber += tempAdd + 10;
break;
case 'B':
case 'b':
finalNumber += tempAdd + 11;
break;
case 'C':
case 'c':
finalNumber += tempAdd + 12;
break;
case 'D':
case 'd':
finalNumber += tempAdd + 13;
break;
case 'E':
case 'e':
finalNumber += tempAdd + 14;
break;
case 'F':
case 'f':
finalNumber += tempAdd + 15;
break;
}
multiplyCount++;
}
Console.WriteLine("Int Value:" + finalNumber.ToString());
}
}
}
Hogan
|
|
|
|
|
snorkie wrote: I felt bad about giving a bad answer
Dude, this is a coding horror!
Go improve it now!!! Surely you can spot the pattern
|
|
|
|
|
Its already bad enough that I did his homework for him... I don't want to make it too nice!
Hogan
|
|
|
|
|
|
|
Snorkie
Thanks for the solution but it is not giving me the correct number still.
for Hex string 100000 value should be 16.
060100= 262
1C0000= 28
Any other suggestion please. I am running out of my module time. Please reply.
Thanks
Shailesh
|
|
|
|
|
aman2006 wrote: This 24-bit field is the direction “A” counter stored LS-byte first.
I suggest, shuffle the bytes, then use the int.Parse method as suggested by the other poster.
|
|
|
|
|
Hi,
this would be my approach in pseudo-code:
int result=0;
while(stringLength!=0) {
int oneByte=0;
int.TryParse(rightmost2characters, hexSpecifier, out=oneByte);
result=(result<<8)+oneByye;
drop2charsFromString;
}
<pre>
:)
<div class="ForumSig">Luc Pattyn <a href="http://www.codeproject.com/KB/scrapbook/ForumGuidelines.aspx">[Forum Guidelines]</a> <a href="http://www.codeproject.com/script/Articles/MemberArticles.aspx?amid=648011">[My Articles]</a>
<hr />Voting for dummies? No thanks. X|
<hr /></div>
|
|
|
|
|
I'd convert the hex digits into a byte array, figure out what your target Type is, pad/swap as necessary. 24 bit types are a curse on the land handed down from angry gods to punish us for the sins of BIT-BANGERS.... sorry....
class Program {
static void Main(string[] args) {
String s = "100000";
Byte[] temp = new Byte[4];
Array.Copy(GetBytes(s), 0, temp, 0, 3);
Int32 value = BitConverter.ToInt32(temp, 0);
Console.WriteLine(value.ToString());
Console.ReadLine();
}
public static byte[] GetBytes(string hexFormat) {
int byteLength = hexFormat.Length / 2;
byte[] bytes = new byte[byteLength];
for (int i = 0; i < byteLength; i++) {
bytes[i] = AsciiAsHexToByte(new String(new Char[] { hexFormat[i * 2], hexFormat[i * 2 + 1] }));
}
return bytes;
}
public static byte AsciiAsHexToByte(string hex) {
return byte.Parse(hex, NumberStyles.HexNumber, NumberFormatInfo.CurrentInfo);
}
}
As you can see, it's a pain to do the conversion.
Scott P
“It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration.”
-Edsger Dijkstra
|
|
|
|