English 中文(简体)
.NET图。 救助方法在Windows 64bit产生非可再生结果
原标题:.NET Image.Save method produces non - reproducible results on Windows 64 bit

I m using .NET framework (tried 3.5 & 4.0) to load a .TIFF file and save it as .PNG. I expect two subsequent calls to the Save() method (using the same TIFF file) to produce the same PNG file. The produced files are, however, sometimes different.

The C# Code below show the problem:

Image sourceToConvert = Bitmap.FromFile("c:\tmp\F1.tif");
sourceToConvert.Save("c:\tmp\F1_gen.png", ImageFormat.Png);           

for (int i = 0; i < 100; i++)
{
    sourceToConvert = Bitmap.FromFile("c:\tmp\F1.tif");
    sourceToConvert.Save("c:\tmp\F1_regen.png", ImageFormat.Png);

    if (!CompareFileBytes("c:\tmp\F1_gen.png", "c:\tmp\F1_regen.png"))
        MessageBox.Show("Diff" + i);                
}

This will display Diff at iteration 8, 32, 33, 73 114, 155, 196 on Windows 64, while it does not display any errors on 32 bit machines. (I use x86 target; with x64 target, it is worse: diff at iteration 12, 13, 14, 15, ...)

是否有办法从“拯救”获得可再生的成果?

可在

最佳回答

我可以解释为什么会发生这种情况,但看来,在定稿人版上的“代码>ImageImage ImplementsIDisposable,因此,请打电话Dispose,在您重新使用该代码后加以最终清理;否则,该编码今后将任意确定。)

如果我把你的榜样代码改为如下,那么我从每次打电话到<代码>就获得同样的结果。 Save :

using (Image sourceToConvert = Bitmap.FromFile("c:\tmp\F1.tif"))
    sourceToConvert.Save("c:\tmp\F1_gen.png", ImageFormat.Png);           

for (int i = 0; i < 100; i++)
{
    using (Image sourceToConvert = Bitmap.FromFile("c:\tmp\F1.tif"))
        sourceToConvert.Save("c:\tmp\F1_regen.png", ImageFormat.Png);

    // files are the same
}

请注意,我确实发现另一个奇怪之处:在运行一个32比(x86)时,在Windows 7 SP1 x64上,第一个 2<>。 电话Save 退回了不同结果,随后每次打电话到Save ,所产生的产出与第二次访问相同。 为了给测试通行证,我必须重复头两条线(在休息前),以便在进行平等检查之前强迫两个储蓄。

问题回答

暂无回答




相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...