找回密码
 立即注册

QQ登录

只需一步,快速开始

gaobowen

中级会员

87

主题

227

帖子

810

积分

中级会员

积分
810

微信认证勋章

gaobowen
中级会员   /  发表于:2015-12-29 16:34  /   查看:7374  /  回复:7
以下是官网的示例代码,执行过后,PictureBox的图片上下颠倒了。请问如何解决?谢谢了。
PictureBox1.Image = Leadtools.Drawing.RasterImageConverter.ChangeToImage(RasterImageViewer1.Image, Leadtools.Drawing.ChangeToImageOptions.None)

7 个回复

倒序浏览
AvoCaDolol活字格认证 Wyn认证
社区贡献组   /  发表于:2015-12-30 17:46:00
沙发
回复 1楼gaobowen的帖子

您好, 您能否将您用的图片发到论坛上我测试一下。
回复 使用道具 举报
gaobowen
中级会员   /  发表于:2015-12-31 08:38:00
板凳

您好,以上是我用的图片。麻烦您了。
我还试了其他类型的图片,都上下颠倒了。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 使用道具 举报
AvoCaDolol活字格认证 Wyn认证
社区贡献组   /  发表于:2016-1-4 15:38:00
地板
回复 3楼gaobowen的帖子

您好,经过调查这个问题重现了。
但目前并不知道这个问题的原因,我将会给厂商发送邮件来询问是一个Bug还是用法的问题。
目前我这里测试的结果是:BMP类图片都是颠倒的,TIF和JPG正常。

目前此问题的解决方法是,请您将ChangeToImage方法替换为:ConvertToImage方法,这个方法是另一个转换的方法,效果和ChangeToImage是一致的。
经过测试,ConvertToImage方法可以正确转换您的图片,如下图:



我也测试了其他图片都正常显示。
使用方法为:PictureBox1.Image = RasterImageConverter.ConvertToImage(RasterImageViewer1.Image, ConvertToImageOptions.None)

请您测试一下,之后我收到回复后会给您结果。

以上,谢谢。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 使用道具 举报
gaobowen
中级会员   /  发表于:2016-1-5 11:09:00
5#
回复 4楼AvoCaDolol的帖子

您好,非常感谢您的回答。
我这边的测试结果(jpg格式):
1,使用ChangeToImage方法,报错:Image is not GDI+ compatible
2,使用ConvertToImage方法,图片显示正常。
那我就按照您的提示,先使用ConvertToImage方法。
另外,我这边发现一个现象:图片如果是通过Load方法得到的,用了ChangeToImage,图片上下颠倒。但是,如果图片是通过SetPicture方法得到的,用了ChangeToImage。图片正常。
以上,谢谢!
回复 使用道具 举报
AvoCaDolol活字格认证 Wyn认证
社区贡献组   /  发表于:2016-1-5 16:18:00
6#
回复 5楼gaobowen的帖子

您好, 今早收到回复。原文如下:
I checked your code and I was able to see the same behavior when calling the RasterImageConverter.ChangeToImage method.
You can resolve this issue using one of the following approaches:

(1) Call the RasterImageConverter.ConvertToImage() method instead of RasterImageConverter.ChangeToImage() method. The difference between these two methods that the ConvertToImage() method creates a GDI+ System.Drawing.Image object that don't share the same image data with the Leadtools.RasterImage object.
The ChangeToImage() method creates a GDI+ System.Drawing.Image object that shares the same data with the Leadtools.RasterImage object, which might causing unexpected errors if the Leadtools.RasterImage object is not GDI+ compatible. The code will be something as follows:
+--------------------------------------------+
this.pictureBox1.Image = RasterImageConverter.ConvertToImage(rasterImageViewer1.Image,ConvertToImageOptions.None);
+--------------------------------------------+

(2) Make sure that the Leadtools.RasterImage object is GDI+ compatible before calling the ChangeToImage() method. You can do this as follows:
+--------------------------------------------+
if (RasterImageConverter.TestCompatible(rasterImageViewer1.Image,true) != ImageIncompatibleReason.Compatible)
{
RasterImageConverter.MakeCompatible(rasterImageViewer1.Image, System.Drawing.Imaging.PixelFormat.DontCare, true);            
}           
           
this.pictureBox1.Image = RasterImageConverter.ChangeToImage(rasterImageViewer1.Image, Leadtools.Drawing.ChangeToImageOptions.None);
+--------------------------------------------+
厂商给的回复跟我的一致,请您使用ConvertToImage方法替代ChangeToImage方法。
但由于图片有可能是压缩的,所以追加了一个判断,
if (RasterImageConverter.TestCompatible(rasterImageViewer1.Image,true) != ImageIncompatibleReason.Compatible)
{
RasterImageConverter.MakeCompatible(rasterImageViewer1.Image, System.Drawing.Imaging.PixelFormat.DontCare, true);            
}           
使得处理图片能够转换。请您将上面的代码追加到您的程序中去。

以上,谢谢。
回复 使用道具 举报
gaobowen
中级会员   /  发表于:2016-1-5 16:35:00
7#
您好,非常感谢您细致耐心的回答,问题得到了解决。谢谢!
回复 使用道具 举报
AvoCaDolol活字格认证 Wyn认证
社区贡献组   /  发表于:2016-1-5 17:49:00
8#
回复 7楼gaobowen的帖子

好的,此问题完结。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部