|
Yes, I was commenting what another member wrote about "redundant." I did look up the streamwriter and saw that it would not work for me. Thank you.
|
|
|
|
|
StreamWriter is for text. BinaryWriter is for binary files or did you make a typ-o?
|
|
|
|
|
computerpublic wrote: It is not redundant if you want to see a file in a way that looks simple. It still is redundant.
computerpublic wrote: Decimal is very simple. A byte is a small integer number, without any decimals. What good does it do to convert it to a decimal? How does it make things simpeler?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
computerpublic wrote: It is not redundant if you want to see a file in a way that looks simple. Decimal is very simple.
Just a guess, but are you trying to view the bytes as decimal (base-10) numbers? You don't need to convert to the decimal type for that.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
computerpublic wrote: t is not redundant Of course it is, you convert bytes to decimal and then immediately convert them back to bytes, so it serves no purpose.
computerpublic wrote: Is there anyway to do with binary chunks for one file? Yes, use the Read method[^] of the BinaryReader class[^], and read in blocks as I suggested previously.
More importantly, you still have not explained why you want to convert these bytes to decimal in the first place. Perhaps if you did, we would be able to make some more useful suggestions.
|
|
|
|
|
Honestly, how are decimals easier to understand?
Note, a byte is a value from 0 to 255. You convert it to decimal and it is a value from 0 to 255.
Maybe you are getting confused by the term "binary".
Binary means 2 things:
A value that can be only 0 or 1. So, instead of seeing 255 you see 11111111.
A representation of data that's not text-only.
So, a byte is usually used to read binary data. This doesn't mean it only reads 0 or 1. It can still be seen as 0, 1, 2, 3, 100 etc... limited to 255. It is actually not limited to visible characters (so, it is not text).
Your conversion from byte to decimal is only converting 8 bit values to 128 bit values that contain the same important data (a value from 0 to 255)... and then you are converting it back.
So, it is not redundant. It is completely useless.
Redundant is for those cases that it actually generates a result that could be easily obtained. In this case you are doing completely useless work.
If what you want is to read a file that has lines like this:
01010101
11111111
00010001
And you want to understand those values, you need to:
Read each line as string.
Convert each string to a byte.
Then, you convert the numeric value back to a string.
So, 11111111 (binary) will become 255 (decimal). This is a decimal representation, not the decimal type.
|
|
|
|
|
Hi,
Im looking for a simple way to convert byte array 32bits to byte array 16bits... I already asked in stackoverflow but the response was bad.
byte [] data = Convert.FromBase64String("-- my string encoded")
var skipBytes = 0;
byte[] data16bit;
int samples ;
skipBytes = 0;
samples = data.Length / 4;
data16bit = new byte[samples * 2];
int writeIndex = 0;
int readIndex = 0;
for(var i = 0; i < samples; ++i)
{
readIndex += skipBytes;
data16bit[writeIndex++] = data[readIndex++];
data16bit[writeIndex++] = data[readIndex++];
}
Please help or enlighten me 
|
|
|
|
|
Member 10607992 wrote: I already asked in stackoverflow but the response was bad.
That's probably because your question isn't clear. A byte is always 8 bits; there are no 16-bit or 32-bit byte arrays.
From your title, I'd guess you're trying to resample an audio file? If that's the case, you can either P/Invoke the Audio Compression Manager[^], or use a third-party library like NAudio[^].
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Mmm you are right, It's my wave file encoded in 32 bits... but not the byte arrays.
Im working on Wave header with MemorySream . If it doesn't work i 'll check Audio Compression ManagerM . Anyway when i get trough this, i will reply the answear. All example with resample are kinda easy but Im beginng with byte array and i need to change Wave Header for my new byte array, Im not working with Files like all Naudio example. Thanks
|
|
|
|
|
|
Wave format does not know about "byte arrays". The format is specified by samples per second (in your case: 11025 vs. 8000), bits per sample (32 vs. 16), sample type (floating point vs. whole number - 32 bit is typically float while 16bit is typically an Int16), and channels (you did not provide any information about that - mono, stereo, something else?).
Look at the source code of NAudio, though they start with files, they soon continue with streams.
|
|
|
|
|
hi guys,
I used memery stream to resample with Naudio.
I write all wave header but i have a problem, my Subchunk2ID (offset 36 ) is too big.
My length wave file is about 20 Hours but when Im playing it's the good lenght (4/3 second).
i checked and its when i write "Data"... what am I missing
bwl.Write(new char[4] { 'R', 'I', 'F', 'F' });
bwl.Write(length);
bwl.Write(new char[8] { 'W', 'A', 'V', 'E', 'f', 'm', 't', ' ' });
bwl.Write((int)16);
bwl.Write((short)1);
bwl.Write(program.channels);
bwl.Write(program.samplerate);
bwl.Write((int)(program.samplerate * ((program.BitsPerSample * program.channels) / 8)));
bwl.Write((short)((program.BitsPerSample * program.channels) / 8));
bwl.Write(program.BitsPerSample);
bwl.Write(new char[4] { 'd', 'a', 't', 'a' });
bwl.Write(buffer);
This line
bwl.Write(new char[4] { 'd', 'a', 't', 'a' });
is 10 times bigger than the initial file !!!!
|
|
|
|
|
How to get the dns suffix name I need to add this suffix to hostname. 
|
|
|
|
|
Which DNS suffix? Please give proper details of what you are trying to do, and what part of your code is not working.
|
|
|
|
|
my current machine dns suffixname.I would like to connect to remote host through tcp protocol socket.
|
|
|
|
|
Your DNS suffix is not going to help you to connect to a remote host; you need to know the name or IP address of the remote system itself.
|
|
|
|
|
anyone know how to use ref to make this work?
i keep getting error on load<item3>(i.Item2);
i tried using ref but it didnt work.
public static List<Tuple<object,string,Type>> DBlist;
DBlist.Add(new Tuple<object, string, Type>(A, "A", typeof(List<Car>)));
DBlist.Add(new Tuple<object, string, Type>(B, "B", typeof(List<Boat>)));
foreach (Tuple<Object, string, Type> i in DBlist)
{
Type temp = i.Item3;
i.Item1 = load<Item3>(i.Item2);
}
public static T load<T>(string tablename)
|
|
|
|
|
What error are you getting? "It didn't work" is hardly enough information for anyone to help you.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
i.Item1 = load<Item3>(i.Item2);
i.Item1 = load<Type>(i.Item2);
|
|
|
|
|
It should be rather
i.Item1 = load<temp>(i.Item2);
or
i.Item1 = load<i.Item3>(i.Item2);
The good thing about pessimism is, that you are always either right or pleasently surprised.
|
|
|
|
|
So you want to call a generic method with a dynamic type parameter? You'll need to use reflection to do that.
Try something like this:
MethodInfo baseMethod = typeof(YourClass).GetMethod("load",
BindingFlags.Public | BindingFlags.Static,
null,
new[] { typeof(string) },
null);
foreach (Tuple<object, string, Type> i in DBlist)
{
MethodInfo realMethod = baseMethod.MakeGenericMethod(i.Item3);
i.Item1 = realMethod.Invoke(null, new[] { i.Item2 });
}
Where YourClass is the name of the class which contains the load<T> method.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
You have several problems, as Richard Deeming noted you can't use the load that way, you'll need to use Reflection.
Also, it looks like you intend to assign the result of the load into the variable referenced by the .Item1 object of the Tuple.
What your code actually does is try to assign into the .Item1 property of the Tuple.
Tuples, once created, cannot be changed. The .Item1 property is get-only.
You might be better off changing the DBList to hold delegates that actually do what you seem to want to happen.
Something like:
public static List<Action> DBList;
DBList.Add(() => A = load<<Car>>("A"));
DBList.Add(() => B = load<Boat>("B"));
foreach (var loader in DBList)
{
loader();
}
public static List<T> load<T>(string tablename)
|
|
|
|
|
I have a web service where I need to create a very large bitmap 15,000 x 15,900 x 32bpp. Code fails on my machine (Parameter is not valid exception). On the IIS server, I can create about 85 or so before I get the Parameter is not valid exception. I do NOT keep all 85 in memory if that was your next question .
Workflow is pretty much:
1) Get image request
2) Create 15,000 x 15,900 x 32bpp bitmap
3) Do stuff to it
4) Convert it to 1bpp and return the bytes
I've changed my code around so I call Dispose() on the various Graphics objects every step of the way the second I don't need them anymore, but no luck. The bitmap in Step #2 has to be 32bpp.
Originally I had 10,000 x 10,900 bitmaps and I could process a whole set without crashing (710+). Unfortunately, QA requested the bitmaps to be 15,000 x 15,900. Trying to see how far I get by dropping to 14,000 x 14,900.
I suspect this has to do with the Large Object Heap fragmentation?
One of the recomendations I've seen on the net is to just create a single 15,000 x 15,900 object and re-use it.
Not sure how that would work in a web service. Each simultaneous request needs a 15,000 x 15,900 bitmap of its own.
Saw there is something in .NET 4.5.1 to compact the large object heap... might try that next if the 14k images don't work.
|
|
|
|
|
Check your project, are you compiling it for x64, or using AnyCPU? In order to make it be a 64 bit app, everything must be set to x64, or AnyCPU and running on a 64 bit box. Then make sure that the process is a 64 bit process.
I am assuming you have already done that.
|
|
|
|
|
Yeah, I'm compiling everything as AnyCPU. I think it's something with the fragmentation.
|
|
|
|
|