728x90
반응형
728x170
■ MemoryStream 클래스의 Write 메소드를 사용해 스트림에서 바이트 배열을 구하는 방법을 보여준다.
▶ 예제 코드 (C#)
#region 바이트 배열 구하기 - GetByteArray(sourceStream)
/// <summary>
/// 바이트 배열 구하기
/// </summary>
/// <param name="sourceStream">소스 스트림</param>
/// <returns>바이트 배열</returns>
public byte[] GetByteArray(Stream sourceStream)
{
byte[] bufferByteArray = new byte[16384]; // 16×1024
using(MemoryStream targetStream = new MemoryStream())
{
int countRead;
while((countRead = sourceStream.Read(bufferByteArray, 0, bufferByteArray.Length)) > 0)
{
targetStream.Write(bufferByteArray, 0, countRead);
}
return targetStream.ToArray();
}
}
#endregion
728x90
반응형
그리드형(광고전용)
댓글을 달아 주세요