Home > Net >  C # how to read in a two-dimensional array to generate images
C # how to read in a two-dimensional array to generate images

Time:12-22

Excuse me each bosses, c # how to read in a two-dimensional array to drawing? I want to use c # for canny edge detection of images, the two dimensional array is equivalent to grayscale image grey value,
The following code USES a pointer, c # also don't know I use right,
 
StreamReader sr;
The String line;
ListString dataFilePath=@ "E: \ \ 0831 afternoon experimental data gap 1 (16922). TXT".//condition 5

//string dataFilePath=@ "C: \ Users \ wufeng \ Desktop \ gap 1 (16922). TXT".//condition 5
The sr=new StreamReader (dataFilePath, Encoding. The Default).
While ((line=sr. ReadLine ())!=null)
{
If (the line!="")
{
String [] strLine=line. The Split (");
Int [] data=https://bbs.csdn.net/topics/Array.ConvertAll (strLine, int. Parse);//an array of type string into an array of type int
Datas. The Add (data);

}
}
Int [] [] all=datas. ToArray ();//to be processed in the two-dimensional array
Int width=all. Length;
Int height=all [0]. Length;
Int stride width=* 4;
The unsafe
{
Fixed (int * intPtr=& amp; All [10] [10])
{
Bitmap=new bitmap (width, height and stride, PixelFormat Format32bppRgb, new IntPtr (IntPtr));

Mat Mat=OpenCvSharp. Extensions. BitmapConverter. ToMat (bitmap);//bitmap mat

Cv2. ImShow (" Demo ", mat);
//Cv2. Canny (mat, mat, 1, 3);
Cv2. WaitKey (0);
}
}


Generated images are the following
The two-dimensional array transpose the following after

But I use MATLAB to draw the image so
Please can you solve, thank you thank you,
  •  Tags:  
  • C#
  • Related