gpt4 book ai didi

c# - 如何将位图图像从自定义程序集返回到 SSRS 报告?

转载 作者:太空宇宙 更新时间:2023-11-03 16:03:01 25 4
gpt4 key购买 nike

我正在使用 QRCode4CS 类 ( http://qrcode4cs.codeplex.com/releases/view/74015 ) 生成二维码。

我可以使用以下代码成功地将位图图像返回到 Windows 窗体应用程序中的图片框。

public class CreateQRCodeClass
{
public static Image CreateQRCodeImage(string inputString)
{
QRCode4CS.QRCode qrcode = new QRCode4CS.QRCode(new QRCode4CS.Options(inputString));
qrcode.Make();
Image canvas = new Bitmap(86, 86);
Graphics artist = Graphics.FromImage(canvas);
artist.Clear(Color.White);
for (int row = 0; row < qrcode.GetModuleCount(); row++)
{
for (int col = 0; col < qrcode.GetModuleCount(); col++)
{
bool isDark = qrcode.IsDark(row, col);

if (isDark == true)
{
artist.FillRectangle(Brushes.Black, 2 * row + 10, 2 * col + 10, 2 * row + 15, 2 * col + 15);
}
else
{
artist.FillRectangle(Brushes.White, 2 * row + 10, 2 * col + 10, 2 * row + 15, 2 * col + 15);
}
}
}
artist.FillRectangle(Brushes.White, 0, 76, 86, 86);
artist.FillRectangle(Brushes.White, 76, 0, 86, 86);
artist.Dispose();
return canvas;
}
}

在尝试调整相同的代码(如下)以在 SSRS 报告中显示 QR 码时,我收到错误消息“自定义代码的第 1 行出现错误:[BC30311] 类型 'System.Drawing.Image 的值' 不能转换为 '一维字节数组'。

这是我正在使用的自定义代码。

Public Function QRCode(ByVal RetailerId As String) as Byte()
Return QRCode4CSCreateQRCode.CreateQRCodeClass.CreateQRCodeImage(RetailerId)
End Function

这是修改后的自定义程序集。

public class CreateQRCodeClass
{
public static byte[] CreateQRCodeImage(string inputString)
{
QRCode4CS.QRCode qrcode = new QRCode4CS.QRCode(new QRCode4CS.Options(inputString));
qrcode.Make();
Image canvas = new Bitmap(86, 86);
Graphics artist = Graphics.FromImage(canvas);
artist.Clear(Color.White);
for (int row = 0; row < qrcode.GetModuleCount(); row++)
{
for (int col = 0; col < qrcode.GetModuleCount(); col++)
{
bool isDark = qrcode.IsDark(row, col);

if (isDark == true)
{
artist.FillRectangle(Brushes.Black, 2 * row + 10, 2 * col + 10, 2 * row + 15, 2 * col + 15);
}
else
{
artist.FillRectangle(Brushes.White, 2 * row + 10, 2 * col + 10, 2 * row + 15, 2 * col + 15);
}
}
}
artist.FillRectangle(Brushes.White, 0, 76, 86, 86);
artist.FillRectangle(Brushes.White, 76, 0, 86, 86);
artist.Dispose();

System.IO.MemoryStream ms = new System.IO.MemoryStream();
canvas.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] imagedata = null;
imagedata = ms.GetBuffer();

return imagedata;
}
}

什么数据类型可以成功返回给SSRS显示图片?

最佳答案

我想出了答案。

您必须将位图图像转换为字节数组才能在 SSRS 中显示它。

这是可以与 SSRS 一起使用的修改后的代码。

    public static Byte[] ReturnByteArray(string inputString)
{
QRCode4CS.QRCode qrcode = new QRCode4CS.QRCode(new QRCode4CS.Options(inputString));
qrcode.Make();
Image canvas = new Bitmap(86, 86);
Graphics artist = Graphics.FromImage(canvas);
artist.Clear(Color.White);
for (int row = 0; row < qrcode.GetModuleCount(); row++)
{
for (int col = 0; col < qrcode.GetModuleCount(); col++)
{
bool isDark = qrcode.IsDark(row, col);

if (isDark == true)
{
artist.FillRectangle(Brushes.Black, 2 * row + 10, 2 * col + 10, 2 * row + 15, 2 * col + 15);
}
else
{
artist.FillRectangle(Brushes.White, 2 * row + 10, 2 * col + 10, 2 * row + 15, 2 * col + 15);
}
}
}
artist.FillRectangle(Brushes.White, 0, 76, 86, 86);
artist.FillRectangle(Brushes.White, 76, 0, 86, 86);
artist.Dispose();

System.IO.MemoryStream ms = new System.IO.MemoryStream();
canvas.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
byte[] imagedata = null;
imagedata = ms.GetBuffer();

return imagedata;
}

关于c# - 如何将位图图像从自定义程序集返回到 SSRS 报告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20528672/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com