これを行うには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を推奨しました。
エラーが発生しました非呼び出し可能メンバー 'Rectangle'はメソッドのように使用できません。 – Cieja
申し訳ありませんが、私は何とか "新しい"部分を削除しました。編集して、今すぐお試しください。 –
これは動作しますが、最初のusingステートメントで別のエラーが発生しました。 'System.Drawing.GDIPlus'の型初期化子が例外をスローしました。メッセージ= "DLLを読み込めません 'gdiplus:指定されたモジュールが見つかりませんでした。\ n(HRESULTの例外:0x8007007E)" – Cieja