Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8076151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:12:12+00:00 2026-06-05T15:12:12+00:00

I’m using .NET framework (tried 3.5 & 4.0) to load a .TIFF file and

  • 0

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 shows 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, …)

Is there a way to get a reproducible result from Save()?

A sample image can be found on this FTP site

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T15:12:13+00:00Added an answer on June 5, 2026 at 3:12 pm

    I can’t explain why this is happening, but it appears that non-deterministic finalization of the Image objects on the finalizer thread is affecting the encoding of images on the main thread. (Image implements IDisposable, so you should call Dispose on it to deterministically clean it up when you’re finished using it; otherwise, it will be finalized at an arbitrary time in the future.)

    If I change your example code to the following, I get the same results from every call to 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
    }
    

    Note that I did find one further oddity: when running a 32-bit (x86) build on Windows 7 SP1 x64, the first two calls to Save returned different results, then every subsequent call to Save produced the same output as the second call. In order to make the test pass, I had to repeat the first two lines (before the loop) to force two saves before performing the equality checks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I am using parse_ini_file to read the contents of a file however it is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.