PDFsharp图像到XImage

时间:2017-06-03 19:29:41

标签: c# asp.net pdfsharp

我在ASP.NET MVC应用程序中创建了条形码作为图像。

org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.example.djbcdataaccess.JDBCTest] for bean with name 'JDBCTest' defined in class path resource [applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: com.example.djbcdataaccess.JDBCTest
    at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1385)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:641)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:609)
    at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1484)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:425)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:395)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:81)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:686)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:524)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    at com.example.jdbcdataaccess.JdbcdataaccessApplication.main(JdbcdataaccessApplication.java:12)

这将使用BarcodeLib创建条形码 如何将其转换为PDFsharp的XImage?

BarcodeLib.Barcode barcode = new BarcodeLib.Barcode()                   
{                        
    IncludeLabel = false,
    Alignment = AlignmentPositions.LEFT,
    Width = element.BarcodeWidth,
    Height = element.BarcodeHeight,
    RotateFlipType = RotateFlipType.RotateNoneFlipNone,
    BackColor = Color.Transparent,
    ForeColor = Color.Black,
    ImageFormat = System.Drawing.Imaging.ImageFormat.Png
 };

4 个答案:

答案 0 :(得分:1)

如果您使用PDFsharp的GDI版本,则可以调用XImage.FromImage方法。

使用任何版本的PDFsharp,您可以将PNG图像写入MemoryStream,然后从该MemoryStream中获取XImage。

答案 1 :(得分:1)

实际上,.net核心版本中的方法已更改。它以Func作为参数。请注意:这是.net core的非官方版本。

XImage xImage = XImage.FromStream(() => new MemoryStream(yourByte[]));

答案 2 :(得分:0)

解决这个问题:

Image img = barcode.Encode(TYPE.CODE128, Name); // this is the image

MemoryStream strm = new MemoryStream();
img.Save(strm, System.Drawing.Imaging.ImageFormat.Png);

XImage xfoto = XImage.FromStream(strm);

答案 3 :(得分:0)

另外, 如果您知道图片路径,可以使用

XImage xImage = XImage.FromFile(imagePath)