System.Drawing.Bitmap
을 사용하면이 작업을 수행 할 수 있습니다. CoreCompat.System.Drawing
nuget 패키지에 대한 참조를 추가 (베타 버전에서의) 한 다음이 코드를 사용 : 아직 해제되지 않습니다 ImageSharp
알고 지금까지
BarcodeWriterPixelData writer = new BarcodeWriterPixelData()
{
Format = BarcodeFormat.EAN_13
};
var pixelData = writer.Write(barcodeModel.BarcodeNumber);
using (var bitmap = new System.Drawing.Bitmap(pixelData.Width, pixelData.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb))
{
using (var ms = new System.IO.MemoryStream())
{
var bitmapData = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, pixelData.Width, pixelData.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
try
{
// we assume that the row stride of the bitmap is aligned to 4 byte multiplied by the width of the image
System.Runtime.InteropServices.Marshal.Copy(pixelData.Pixels, 0, bitmapData.Scan0, pixelData.Pixels.Length);
}
finally
{
bitmap.UnlockBits(bitmapData);
}
// PNG or JPEG or whatever you want
bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
var base64str = Convert.ToBase64String(ms.ToArray());
}
}
합니다. 나는 this answer을 기반으로 CoreCompact를 추천했다.
오류가 발생합니다. 호출 할 수없는 멤버 인 '사각형'을 메서드처럼 사용할 수 없습니다. – Cieja
죄송합니다, 어떻게 든 새 부분을 삭제했습니다. 수정되었습니다. 지금 시도하십시오. –
그것은 작동하지만 지금은 첫 번째 using 문에 다른 오류가 있습니다. 'System.Drawing.GDIPlus'의 형식 이니셜 라이저에서 예외가 발생했습니다. 전체 오류 메시지 : Message = "DLL을로드 할 수 없습니다 'gdiplus': 지정한 모듈을 찾을 수 없습니다. \ n (예외 : HRESULT : 0x8007007E)" – Cieja