convert image and save as byte array
I would like to convert simple picture to byte array and then save this array to .txt
I tried to do this but I'm lost.. I can't convert this ... I would like to have array and at the place where are figures in my array should appear 1. If there is nothing should be 0.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Image image = Image.FromFile(@"D:Stackimage1.png");
var ms = new MemoryStream();
image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
var bytes = ms.ToArray();
string tab = new string[1000000];
for (int i = 0; i < 1000000; i++)
{
tab[i] = "" + bytes;
}
MessageBox.Show("start");
using (System.IO.StreamWriter writer = new System.IO.StreamWriter(@"D:data.txt"))
{
foreach (string elem in tab)
{
writer.WriteLine(elem);
}
}
MessageBox.Show("stop");
}
I add here my image.
My picture
c# arrays file-conversion
add a comment |
I would like to convert simple picture to byte array and then save this array to .txt
I tried to do this but I'm lost.. I can't convert this ... I would like to have array and at the place where are figures in my array should appear 1. If there is nothing should be 0.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Image image = Image.FromFile(@"D:Stackimage1.png");
var ms = new MemoryStream();
image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
var bytes = ms.ToArray();
string tab = new string[1000000];
for (int i = 0; i < 1000000; i++)
{
tab[i] = "" + bytes;
}
MessageBox.Show("start");
using (System.IO.StreamWriter writer = new System.IO.StreamWriter(@"D:data.txt"))
{
foreach (string elem in tab)
{
writer.WriteLine(elem);
}
}
MessageBox.Show("stop");
}
I add here my image.
My picture
c# arrays file-conversion
Possible duplicate of Reliable way to convert a file to a byte
– Liam
Nov 13 '18 at 10:01
1
Why do you have a loop where you set"" + bytes
? Shouldn't you convert the bytes list to a string list instead?
– Haytam
Nov 13 '18 at 10:02
1
What your doing doesn't really make a lot of sense. Why would you want this? You'll just end up with an unreadable text file.
– Liam
Nov 13 '18 at 10:02
Are you trying to encode the bytes into a a readable format of some kind? What format do you want?
– Liam
Nov 13 '18 at 10:05
I am going to program a small mobile robot with collision detection. I have 512 lines (it will be a robot sensor) and 2 figure in different places (obstacles). I have 1000 pictures with different figure positions. And then I have to check where the figure are (where they are cutting with the line). Generally, I need to know where the line obstacle is and where the circle obstacle is, and I need this data because then I will teach the neural network.
– Kim
Nov 13 '18 at 10:16
add a comment |
I would like to convert simple picture to byte array and then save this array to .txt
I tried to do this but I'm lost.. I can't convert this ... I would like to have array and at the place where are figures in my array should appear 1. If there is nothing should be 0.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Image image = Image.FromFile(@"D:Stackimage1.png");
var ms = new MemoryStream();
image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
var bytes = ms.ToArray();
string tab = new string[1000000];
for (int i = 0; i < 1000000; i++)
{
tab[i] = "" + bytes;
}
MessageBox.Show("start");
using (System.IO.StreamWriter writer = new System.IO.StreamWriter(@"D:data.txt"))
{
foreach (string elem in tab)
{
writer.WriteLine(elem);
}
}
MessageBox.Show("stop");
}
I add here my image.
My picture
c# arrays file-conversion
I would like to convert simple picture to byte array and then save this array to .txt
I tried to do this but I'm lost.. I can't convert this ... I would like to have array and at the place where are figures in my array should appear 1. If there is nothing should be 0.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Image image = Image.FromFile(@"D:Stackimage1.png");
var ms = new MemoryStream();
image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
var bytes = ms.ToArray();
string tab = new string[1000000];
for (int i = 0; i < 1000000; i++)
{
tab[i] = "" + bytes;
}
MessageBox.Show("start");
using (System.IO.StreamWriter writer = new System.IO.StreamWriter(@"D:data.txt"))
{
foreach (string elem in tab)
{
writer.WriteLine(elem);
}
}
MessageBox.Show("stop");
}
I add here my image.
My picture
c# arrays file-conversion
c# arrays file-conversion
edited Nov 13 '18 at 9:56
Saurabh Solanki
1,365623
1,365623
asked Nov 13 '18 at 9:47
KimKim
132
132
Possible duplicate of Reliable way to convert a file to a byte
– Liam
Nov 13 '18 at 10:01
1
Why do you have a loop where you set"" + bytes
? Shouldn't you convert the bytes list to a string list instead?
– Haytam
Nov 13 '18 at 10:02
1
What your doing doesn't really make a lot of sense. Why would you want this? You'll just end up with an unreadable text file.
– Liam
Nov 13 '18 at 10:02
Are you trying to encode the bytes into a a readable format of some kind? What format do you want?
– Liam
Nov 13 '18 at 10:05
I am going to program a small mobile robot with collision detection. I have 512 lines (it will be a robot sensor) and 2 figure in different places (obstacles). I have 1000 pictures with different figure positions. And then I have to check where the figure are (where they are cutting with the line). Generally, I need to know where the line obstacle is and where the circle obstacle is, and I need this data because then I will teach the neural network.
– Kim
Nov 13 '18 at 10:16
add a comment |
Possible duplicate of Reliable way to convert a file to a byte
– Liam
Nov 13 '18 at 10:01
1
Why do you have a loop where you set"" + bytes
? Shouldn't you convert the bytes list to a string list instead?
– Haytam
Nov 13 '18 at 10:02
1
What your doing doesn't really make a lot of sense. Why would you want this? You'll just end up with an unreadable text file.
– Liam
Nov 13 '18 at 10:02
Are you trying to encode the bytes into a a readable format of some kind? What format do you want?
– Liam
Nov 13 '18 at 10:05
I am going to program a small mobile robot with collision detection. I have 512 lines (it will be a robot sensor) and 2 figure in different places (obstacles). I have 1000 pictures with different figure positions. And then I have to check where the figure are (where they are cutting with the line). Generally, I need to know where the line obstacle is and where the circle obstacle is, and I need this data because then I will teach the neural network.
– Kim
Nov 13 '18 at 10:16
Possible duplicate of Reliable way to convert a file to a byte
– Liam
Nov 13 '18 at 10:01
Possible duplicate of Reliable way to convert a file to a byte
– Liam
Nov 13 '18 at 10:01
1
1
Why do you have a loop where you set
"" + bytes
? Shouldn't you convert the bytes list to a string list instead?– Haytam
Nov 13 '18 at 10:02
Why do you have a loop where you set
"" + bytes
? Shouldn't you convert the bytes list to a string list instead?– Haytam
Nov 13 '18 at 10:02
1
1
What your doing doesn't really make a lot of sense. Why would you want this? You'll just end up with an unreadable text file.
– Liam
Nov 13 '18 at 10:02
What your doing doesn't really make a lot of sense. Why would you want this? You'll just end up with an unreadable text file.
– Liam
Nov 13 '18 at 10:02
Are you trying to encode the bytes into a a readable format of some kind? What format do you want?
– Liam
Nov 13 '18 at 10:05
Are you trying to encode the bytes into a a readable format of some kind? What format do you want?
– Liam
Nov 13 '18 at 10:05
I am going to program a small mobile robot with collision detection. I have 512 lines (it will be a robot sensor) and 2 figure in different places (obstacles). I have 1000 pictures with different figure positions. And then I have to check where the figure are (where they are cutting with the line). Generally, I need to know where the line obstacle is and where the circle obstacle is, and I need this data because then I will teach the neural network.
– Kim
Nov 13 '18 at 10:16
I am going to program a small mobile robot with collision detection. I have 512 lines (it will be a robot sensor) and 2 figure in different places (obstacles). I have 1000 pictures with different figure positions. And then I have to check where the figure are (where they are cutting with the line). Generally, I need to know where the line obstacle is and where the circle obstacle is, and I need this data because then I will teach the neural network.
– Kim
Nov 13 '18 at 10:16
add a comment |
1 Answer
1
active
oldest
votes
I see what you are trying to do. A similar approach is used in terrain rendering with an heightMap. The idea is to map an image as grey scale into a text file, which in turn is used to generate the height of a terrain.
In your case you can just map it as 0s and 1s(where 1s is the colour of your obstacles).
You can then upload the mapped text file into a 2D array which will be your map bird-eye view.
As the bot moves across the scene you can detect whether it can safely move or not by checking the current position on the 2D array map.
Hope it helps.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53278138%2fconvert-image-and-save-as-byte-array%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I see what you are trying to do. A similar approach is used in terrain rendering with an heightMap. The idea is to map an image as grey scale into a text file, which in turn is used to generate the height of a terrain.
In your case you can just map it as 0s and 1s(where 1s is the colour of your obstacles).
You can then upload the mapped text file into a 2D array which will be your map bird-eye view.
As the bot moves across the scene you can detect whether it can safely move or not by checking the current position on the 2D array map.
Hope it helps.
add a comment |
I see what you are trying to do. A similar approach is used in terrain rendering with an heightMap. The idea is to map an image as grey scale into a text file, which in turn is used to generate the height of a terrain.
In your case you can just map it as 0s and 1s(where 1s is the colour of your obstacles).
You can then upload the mapped text file into a 2D array which will be your map bird-eye view.
As the bot moves across the scene you can detect whether it can safely move or not by checking the current position on the 2D array map.
Hope it helps.
add a comment |
I see what you are trying to do. A similar approach is used in terrain rendering with an heightMap. The idea is to map an image as grey scale into a text file, which in turn is used to generate the height of a terrain.
In your case you can just map it as 0s and 1s(where 1s is the colour of your obstacles).
You can then upload the mapped text file into a 2D array which will be your map bird-eye view.
As the bot moves across the scene you can detect whether it can safely move or not by checking the current position on the 2D array map.
Hope it helps.
I see what you are trying to do. A similar approach is used in terrain rendering with an heightMap. The idea is to map an image as grey scale into a text file, which in turn is used to generate the height of a terrain.
In your case you can just map it as 0s and 1s(where 1s is the colour of your obstacles).
You can then upload the mapped text file into a 2D array which will be your map bird-eye view.
As the bot moves across the scene you can detect whether it can safely move or not by checking the current position on the 2D array map.
Hope it helps.
answered Nov 13 '18 at 11:37
Alex LeoAlex Leo
551213
551213
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53278138%2fconvert-image-and-save-as-byte-array%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Possible duplicate of Reliable way to convert a file to a byte
– Liam
Nov 13 '18 at 10:01
1
Why do you have a loop where you set
"" + bytes
? Shouldn't you convert the bytes list to a string list instead?– Haytam
Nov 13 '18 at 10:02
1
What your doing doesn't really make a lot of sense. Why would you want this? You'll just end up with an unreadable text file.
– Liam
Nov 13 '18 at 10:02
Are you trying to encode the bytes into a a readable format of some kind? What format do you want?
– Liam
Nov 13 '18 at 10:05
I am going to program a small mobile robot with collision detection. I have 512 lines (it will be a robot sensor) and 2 figure in different places (obstacles). I have 1000 pictures with different figure positions. And then I have to check where the figure are (where they are cutting with the line). Generally, I need to know where the line obstacle is and where the circle obstacle is, and I need this data because then I will teach the neural network.
– Kim
Nov 13 '18 at 10:16