作成日: 2025/04/30 最終更新日: 2025/04/30
文書種別
不具合
発生環境
2024J v1以降
状況
回避方法あり
詳細
C1BarCodeの新規インスタンスで作成したバーコードを画像にエクスポートした場合、画像ファイルが破損します。デザイン時に配置したC1BarCodeを使用してエクスポートにした場合は問題ありません。
回避方法
C1BarCodeのSaveメソッドではなく、独自の画像出力処理を作成して実行します。
◎サンプルコード
C1BarCode barcode = new C1BarCode(); barcode.Text = $"12345"; barcode.Width = 200; barcode.Height = 200; barcode.CodeType = C1.BarCode.CodeType.QRCode; barcode.QRCodeOptions.ErrorLevel = C1.BarCode.QRCodeErrorLevel.High; string saveFilePath = @"\QRCode.png"; FileStream source = File.Open(saveFilePath, FileMode.OpenOrCreate);
//barcode.Save(source, ImageFormat.Png);
int renderWidth = (int)Math.Ceiling(barcode.Width); int renderHeight = (int)Math.Ceiling(barcode.Height); RenderTargetBitmap bitmap = new RenderTargetBitmap(renderWidth, renderHeight, 96, 96, PixelFormats.Pbgra32); barcode.BeginInit(); barcode.EndInit(); barcode.Arrange(new Rect(0, 0, renderWidth, renderHeight)); barcode.UpdateLayout(); bitmap.Render(barcode);
BitmapEncoder encode = new PngBitmapEncoder(); encode.Frames.Add(BitmapFrame.Create(bitmap)); encode.Save(source); source.Flush(); source.Seek(0, SeekOrigin.Begin); source.Close();