|
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
|
|
|
|
|
I'll 1/2 do your homework for ya
Imports System
Imports System.Globalization
Imports System.Text
Module Module1
Sub Main()
Dim sb As New StringBuilder("1C0000")
Dim str As String
Dim value As Integer
Dim bval As Byte
Dim j As Double
If (sb.Length Mod 2) = 1 Then
sb.Append("0")
End If
str = sb.ToString()
For i As Integer = 1 To str.Length Step 2
j = Math.Pow(16, Convert.ToDouble(i - 1))
bval = Byte.Parse(Mid(str, i, 2), NumberStyles.HexNumber, NumberFormatInfo.CurrentInfo)
value += Convert.ToInt32(Convert.ToDouble(bval) * j)
Next
Console.WriteLine("The string {0} is equal to {1}", sb.ToString(), value)
End Sub
End Module (doh! fixed logic typo)
-Spacix
All your skynet questions[ ^] belong to solved
I dislike the black-and-white voting system on questions/answers.
modified on Friday, June 20, 2008 4:25 PM
|
|
|
|
|
What's the other half? Converting it to C#?
I dislike the black-and-white voting system on questions/answers.
I agree that it's less nuanced, but on the other hand I see a huge increase in the usage of the voting system. It doesn't matter how good a system is, if noone uses it.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Guffa wrote: What's the other half? Converting it to C#?
You are correct sir!
There are a few other "optimizations" to be done which I would assume would garner a better grade from the original...
Guffa wrote: It doesn't matter how good a system is, if noone uses it.
aye, but I think the giant images is what made people start clicking it over the little "Rate this message: {thumb down vote 1} 1 2 3 4 5 {thumb up vote 5}"
-Spacix
All your skynet questions[ ^] belong to solved
I dislike the black-and-white voting system on questions/answers.
|
|
|
|