노주현 개인 블로그
Bitmap & Byte[] 본문
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
// Camera 등에서 buffer 값을 가져온다.
byte[] buffer = 버퍼값
// Parameter
int width;
int height;
// bmp LockBits 실행
Bitmap bmp = new Bitmap(width, height, PixelFormat.Format8bppIndexed);
BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, bmp.PixelFormat);
// byte[] to bmp
Marshal.Copy(buffer, 0, bmpData.Scan0, width * height); // buffer 에 값을 bmp 가장 첫 주소부터 length 길이 만큼 복제한다.
Marshal.Copy(buffer, 0, bmpData.Scan0, buffer.Length);
// bmp to byte[]
Marshal.Copy(bmpData.Scan0, buffer, 0, width * height);
// 복사가 완료되면 bmp 파일을 UnLock 시킨다.
bmp.UnlockBits(bmpData);
'프로그래밍 > C#' 카테고리의 다른 글
문자열 인코딩 (0) | 2022.01.21 |
---|---|
클래스 상속 - Interface (0) | 2022.01.18 |
Thread 관련 내용 총정리 (0) | 2022.01.05 |
Momory Copy 여러가지 방식 (0) | 2022.01.03 |
Process 실행 여부 확인 (0) | 2021.12.30 |
Comments