【发布时间】:2019-06-14 20:18:20
【问题描述】:
我想在 UI 中加载扫描的第一页(在附加的扫描仪中),但现在在此代码中,最后一页加载到 UI 中。任何人都可以分析代码并告诉我究竟要重组什么以显示第一页吗? enter image description here
/// <summary>
/// Loads the invoice in the UI, with its associated data.
/// </summary>
private void ShowImFromPDF()
{
IoC.Main.InvoiceCount = IoC.Main.Invoices.Count;
GlobalVars.WriteLog("Updating image and data");
if (IoC.Main.InvoiceIndex >= 0 && IoC.Main.InvoiceIndex < IoC.Main.Invoices.Count)
{
IoC.Main.LoadInfo = true;
PdfDocument document = PdfReader.Open(IoC.Main.Invoices[IoC.Main.InvoiceIndex].Path);
foreach (PdfPage page in document.Pages)
{
foreach (System.Drawing.Image image in page.GetImages())
{
pictureBox1.Source = HelperMethods.ToBitMapImage(image);
}
}
【问题讨论】:
-
它看起来像
foreach循环覆盖所有图像,为什么看起来你得到最后一张图片,你应该使用类似page.GetImages().FirstOrDefualt -
@styx .FirstOrDefault 不会在 foreach 循环上运行。我收到这个错误。 Foreach 不能对“方法组”进行操作。您是否打算调用“方法组”?
-
不,我的意思是删除 foreach 循环并改写 page.GetImages().FirstOrDefault()
-
但这也可以返回我不想要的 null。
-
你可以在
foreach循环中得到null,如果你害怕null,你可以随时使用?opreator检查值是否不为null
标签: c# xml wpf visual-studio c#-4.0