Home > Net >  CSV data generation grayscale
CSV data generation grayscale

Time:09-16

CSV file stored in the LMI, highly direction data were collected by c # will be highly direction data into image pixel gray value
A high degree of data size is 150 * 1470

When this code runs an error, not the result is what problem,
 
Private unsafe void SetData (IntPtr PTR, float step, ArrayList numlist)
//
{
Var p=(byte * PTR);
The foreach (int item in numlist)
{
* p=(byte) (step * item).
P++;

}
//var data=https://bbs.csdn.net/topics/line.Split (', ');
//for (var I=0; I & lt; Data. The Length; I++)
//{
//* p=(byte) (step * float in the Parse (data [I]));
//p++;
//}
}

Private void button1_Click (object sender, EventArgs e)
{
Int width=150, height=1470;
Var FMT=PixelFormat. Format8bppIndexed;
Var BMP=new Bitmap (width, height, FMT);
Var the palette=BMP. The palette;
ArrayList numlist=new ArrayList ();
for (int i=0; I & lt; 256; I++)
{
The palette. Entries [I]=Color. FromArgb (I, I, I);
}
BMP. The Palette=the Palette;
Var step=1;
Var count=height;
Var bmpdata=https://bbs.csdn.net/topics/bmp.LockBits (new Rectangle (0, 0, width, height), ImageLockMode. ReadOnly, FMT);
Using var (sr=new StreamReader (@ "C:/Users/asus/Desktop/LMI20200408/encoder trigger - copy. CSV"))
{
Var PTR=bmpdata. Scan0;
//
List Strlist=new List (a);
//
While (! The sr. EndOfStream)
{
Var line=sr. ReadLine ();
//
Strlist. Add (line);
//
Var p=PTR.
Task. Factory. StartNew (()=& gt;
{
//SetData (p, step, line);
//
SetData (p, step, numlist);
//

});
PTR +=bmpdata. Stride; Interlocked. Decrement (ref count);
}
//
for (int i=0; I & lt; Strlist. Count; I++)
{
String [] number=strlist [I] the Split (', ');
The int value.
For (int j=0; J & lt; Number. Length; J++)
{
Double d=double. Parse (number) [j].
If (d!=0)
{
Value=https://bbs.csdn.net/topics/(int) (d + 290) * 6;
}
The else
{
Value=https://bbs.csdn.net/topics/0;
}

Numlist. Add (value);
}
}
//
}
While (the count & gt; 0 {thread.sleep (20); }

BMP. UnlockBits (bmpdata);
BMP. Save (@ "C: \ Users \ asus \ Desktop \ LMI20200408\01 JPG", System. Drawing. The Imaging. ImageFormat. Jpeg);//the specified image format

PictureBox1. Image=BMP;
}


The read and the actual shape how completely different is really didn't understand
 private void btn1_Click (object sender, EventArgs e) 
{
Z////read data, as subsequent grayscale values

OpenFileDialog of=new OpenFileDialog ();
Of the Filter="| *. CSV";
Of the RestoreDirectory=true;
Of. FilterIndex=1;
If (of ShowDialog ()==DialogResult. OK)
{
Path=of. The FileName;
}
FileStream fs=new FileStream (path, FileMode. Open, FileAccess. Read, FileShare. ReadWrite);
StreamReader sr=new StreamReader (fs, System. Text. The Encoding. The Default).
List Strlist=new List (a);
While (! The sr. EndOfStream)
{
String STR=sr. ReadLine ();
Strlist. Add (STR);
}
Length=strlist. Count;
BMP=new Bitmap (150, 1470);
for (int i=0; I & lt; length; I++)
{
Number=strlist [I]. The Split (new char [] {', '});
Length1=number. Length;
For (int j=0; J & lt; Length1; J++)
{
//height=(int) (Math) between (0.15 * length1));
//width=(int) (Math) between (0.628 * length));
//Bitmap BMP=new Bitmap (height, width);
Double d=double. Parse (number) [j].
If (d!//0=0) is the value of filled
{
Value=https://bbs.csdn.net/topics/(int) (d + 290) * 6;//to convert numerical [0255]
}
The else
{
Value=https://bbs.csdn.net/topics/0;
}
//int value=https://bbs.csdn.net/topics/(int) (Math) between (d/(400 * 255)));
Numlist. Add (value);

Piel=value;
Color=c Color. FromArgb (piel 0, 0);
BMP. SetPixel (I, j, c);

[j]//the Console. WriteLine (number);
}

}

BMP. Save (@ "C: \ Users \ asus \ Desktop \ LMI20200408\01 JPG", System. Drawing. The Imaging. ImageFormat. Jpeg);//the specified image format
PBox1. ImageLocation=@ "C: \ Users \ asus \ Desktop \ LMI20200408\01 JPG";
BMP. The Dispose ();
Fs. The Close ();//close the data flow, free memory
The sr. The Close ();



}


CodePudding user response:

You need to ask each other bit depth

CodePudding user response:

????? What do you mean

CodePudding user response:

Error but found the reason why the figure is all black???????
 
Task. Factory. StartNew (()=& gt;
{
//SetData (p, step, line);
//
SetData (p, step, numlist); Interlocked. Decrement (ref count);
//

});
PTR +=bmpdata. Stride;
  •  Tags:  
  • C#
  • Related