64位图像中的System.byte []问题 [英] System.byte[] problem in 64 bit for image

查看:76
本文介绍了64位图像中的System.byte []问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在水晶报告中显示图像。为了那个

我必须在数据集中对图像进行asign,所以我使用了typeof(System.Byte [])。

这在32位系统中可以正常工作,但不是在64位系统中工作。



下面是我使用的代码...

那么64位系统的解决方案是什么工作。 ..?



我尝试过:



public static ReportDocument SetImage(ReportDocument sReport,int ReportIndex,string ReportName,string ImagePath)

{

try

{

FileStream FilStr = new FileStream(ImagePath,FileMode.Open);

BinaryReader BinRed = new BinaryReader(FilStr);

DataSet DsImages = new DataSet();

DataTable ImageTable = new DataTable(img);

//ImageTable.Columns.Add(new DataColumn(path,typeof(string)));

ImageTable.Columns.Add(new DataCol umn(img,typeof(System.Byte [])));

DsImages.Tables.Add(ImageTable);

DataRow dr = DsImages.Tables [ img] .NewRow();

// dr [path] = ImagePath;

//Convert.ToBase64String(imgBytes)

dr [img] = Convert.FromBase64String(Convert.ToBase64String(BinRed.ReadBytes((int)BinRed.BaseStream.Length)));

DsImages.Tables [img]。行.Add(dr);

FilStr.Close();

BinRed.Close();

//sReport.Database.Tables [ 1] .SetDataSource(DsImages.Tables [images]);



sReport.Subreports [ReportIndex] .SetDataSource(DsImages.Tables [0]);



返回sReport;

}

catch(Exception Ex)

{

MessageBox.Show(Error At:Program.SetImage()\ n \ n+ Ex.Message);



return sReport;

}

}

I have to display image in crystal report. For that
I have to asign image in dataset, so i have use typeof(System.Byte[]).
this will work fine in 32 bit system, but not working in 64 bit system.

Below is code i have use...
so what is solution for 64 bit system to work...?

What I have tried:

public static ReportDocument SetImage(ReportDocument sReport, int ReportIndex, string ReportName, string ImagePath)
{
try
{
FileStream FilStr = new FileStream(ImagePath, FileMode.Open);
BinaryReader BinRed = new BinaryReader(FilStr);
DataSet DsImages = new DataSet();
DataTable ImageTable = new DataTable("img");
//ImageTable.Columns.Add(new DataColumn("path", typeof(string)));
ImageTable.Columns.Add(new DataColumn("img", typeof(System.Byte[])));
DsImages.Tables.Add(ImageTable);
DataRow dr = DsImages.Tables["img"].NewRow();
//dr["path"] = ImagePath;
//Convert.ToBase64String(imgBytes)
dr["img"] = Convert.FromBase64String(Convert.ToBase64String(BinRed.ReadBytes((int)BinRed.BaseStream.Length)));
DsImages.Tables["img"].Rows.Add(dr);
FilStr.Close();
BinRed.Close();
//sReport.Database.Tables[1].SetDataSource(DsImages.Tables["images"]);

sReport.Subreports[ReportIndex].SetDataSource(DsImages.Tables[0]);

return sReport;
}
catch (Exception Ex)
{
MessageBox.Show("Error At : Program.SetImage() \n\n" + Ex.Message);

return sReport;
}
}

推荐答案

如果您需要表中的字节,那就去做吧:

If you need bytes in your table, then just do it:
public static ReportDocument SetImage(ReportDocument sReport, int ReportIndex, string ReportName, string ImagePath)
    {
    try
        {
        DataTable imageTable = new DataTable("img");
        imageTable.Columns.Add(new DataColumn("img", typeof(System.Byte[])));
        DataRow dr = imageTable.NewRow();
        dr["img"] = File.ReadAllByes(ImagePath);
        imageTable.Rows.Add(dr);
        sReport.Subreports[ReportIndex].SetDataSource(imageTable); 
        return sReport;
        }
    catch (Exception Ex)
        {
        MessageBox.Show("Error At : Program.SetImage() \n\n" + Ex.Message);
        return sReport;
        }
    }


这篇关于64位图像中的System.byte []问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆