/----introduce the required namespacesusingSystem.IO;usingSystem.Drawing.Imaging;//----Code section----// Private byte[] photo;//Public Buffers Public stringSourfilepath;//Source picture file path Public stringObjfilepath;//Destination Picture Path Public intFiletostream ()//file-to-stream conversion{Image img=NewBitmap (Sourfilepath); MemoryStream Stream=NewMemoryStream (); Img. Save (stream, imageformat.bmp); BinaryReader BR=NewBinaryReader (stream); Photo=Stream. ToArray (); Stream. Close (); return 0; } PublicImage Showpic ()//based on flow chart { byte[] bytes =photo; MemoryStream Ms=NewMemoryStream (bytes); Ms. Position=0; Image img=Image.fromstream (MS); Ms. Close (); returnimg; } Public intStreamtofile ()//Reverse Conversions { byte[] bytes =photo; FileStream FS=NewFileStream (Objfilepath, FileMode.Create, FileAccess.Write); Fs. Write (Bytes,0, Bytes. Length); Fs. Flush (); Fs. Close (); return 0; }
C # convert picture file to data stream to picture file--Go