Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I want to convert .wav audio file to byte and then convert this byte array to string.
I do this using c# but the string it return is not in valid format i.e. not in readable form.
How can i get the string in readable format?
var bytes = File.ReadAllBytes("SomeAudio.wav");
string result = System.Text.Encoding.UTF8.GetString(bytes);
In result the data is not readable i.e. it returns �𣻰��𠀁걄𫄐�𣻌
You should use System.Text.Encoding.ASCII instead
var bytes = File.ReadAllBytes("SomeAudio.wav");
string result = System.Text.Encoding.ASCII.GetString(bytes)
and for write some sample you can use
FileStream f = new FileStream("a.wav", FileMode.Create);
BinaryWriter wr = new BinaryWriter(f);
wr.Write(System.Text.Encoding.ASCII.GetBytes("RIFF"));
If you want to create blob here is good example "MSSQL" later you can put blob to table in database.
DECLARE #BLOB varbinary(MAX)
SET #BLOB = (SELECT *
FROM OPENROWSET(BULK 'C:\Users\AAAAAAA\Desktop\master\templates\miusic.wav', SINGLE_BLOB) AS BLOB)
SELECT #BLOB
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 days ago.
This post was edited and submitted for review 3 days ago.
Improve this question
Thanks everyone. I understand that I can't do a conversion this way. Thanks for your answers.
İn Visual Studio;
Byte[] byt1 = File.ReadAllBytes(textBox1.Text);
string str = Encoding.ASCII.GetString(byt1);
Byte[] byt2 = Encoding.ASCII.GetBytes(str);
When I convert byte values to string with this (Encoding.ASCII.GetString), the string value I get is not the same when I convert it back to bytes with (Encoding.ASCII.GetBytes).
For example;
Byte[] byt1 = {78,12,23};
string str = Encoding.ASCII.GetString(byt1);
Byte[] byt2 = Encoding.ASCII.GetBytes(str);
I expect byt1 and byt2 to be the same byte arrays,but different byte arrays.
I read MyFile.png as bytes (variable byt1)
The final result when I convert byt1 to string and convert back to byte array again. Input and output byte array is not same
Here you can see online compiler result;
https://dotnetfiddle.net/45naA0 - online compiler
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed last month.
Improve this question
I want to edit raw data from files (Hex) but i don't know how can i do it
Is there any package that can help me?
Also how do i convert strings in raw bytes?
I've tried some solutions out of google but none of these worked
Here's a function that:
Reads all the bytes from a file
Changes the second byte to the decimal value 8
Writes the bytes back to the file
Note, this is not the most efficient way to do this, but it's an example.
public async Task ChangeSomeBytesInFileAsync(string path)
{
var bytes = await File.ReadAllBytesAsync(path);
bytes[2] = 0b0000_01000;
await File.WriteAllBytesAsync(path, bytes);
}
To get the bytes of a string use the Encoding class and the appropriate encoding In this example, I'm using UTF-8.
var bytes = Encoding.UTF8.GetBytes(#"some value");
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 months ago.
Improve this question
I have 5 picture boxes and would like to add images on them.
I am looking for to check the images of those if any one of the image is same on them then not to insert just display alert message else it gets inserted into database
Help appreciate!
Assuming you want perform a pixel to pixel between img1 and img2, you can do this:
public byte[] ToByteArray(Image image, ImageFormat format)
{
using (MemoryStream ms = new MemoryStream())
{
image.Save(ms, format);
return ms.ToArray();
}
}
public bool ImageEquals(Image img1, Image img2)
{
var array1 = ToByteArray(img1, ImageFormat.Bmp);
var array2 = ToByteArray(img2, ImageFormat.Bmp);
return array1.SequenceEqual(array2);
}
Than you can add them to your DB, keep in mind that usually they are not stored directly in the DB (even if could be possible using the BLOB field type) but they are stored as a link to the file.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
Is there a posiblity to store and load a guid list in a file?
List<Guid> targetFaceIds = new List<Guid>();
foreach (var imageFileName in targetImageFileNames)
{
List<DetectedFace> detectedFaces = await DetectFaceRecognize(client, _imagePath + imageFileName, recognitionModel);
targetFaceIds.Add(detectedFaces[0].FaceId.Value);
}
In my programm I want to store 'targetFaceIds' in a file is that possible and how can I load it back form the file in my programm.
In my 'targetFaceIds' is this:
You can use guid.ToString to convert it to a string and Guid.Parse to parse it back to a Guid:
File.WriteAllLines(path, targetFaceIds.Select(g => g.ToString())); // write
targetFaceIds = File.ReadAllLines(path).Select(Guid.Parse).ToList(); // read
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have string "my string" taken from excel value, I used GemBox.Spreadsheet library. But the result I have """my string""". How to get back my real string value as "my string
Thanks
Use the hex escape \x22 such as:
Console.WriteLine ("\x22Literally\x22");
Outputs "Litterally"
okay I just go to GemBox Convert I try upload my excel file, then convert into csv file, and the result is same as my convert file. So the problem is not coming from my script but in GemBox.Spreadsheet library. Thank you for your participate guys!