none
image saving method in mspaint

    Question

  • I'm currently looking for a solution regarding an image print issue.  I attempted to use the vb.net function that allows you to load an image and save it as another format. 

    This didn't work as the image was the same when output, the strange thing is, when you save with mspaint it'll save the image as we want it (print full page) while if we did the same thing with microsoft office document imaging it would inherit the same issue.  In this instance i'm trying to save TIF to TIF, with the function available in vb.net (System.Drawing.Imaging.ImageFormat) i tried to save it as a bitmap first then back to TIF.

    My main question is what does mspaint do that is different from everything else?

    Thursday, January 28, 2010 1:35 PM

Answers

  • Allright. Then your problem is not about image conversion, but about fixing something that's wrong within the image file. Since you said that you can get them displaying fine after resaving them from paint, my educated guess is that the problem is within the files' header information (if the image data had been reduced, there wouldn't be any way to actually recover the data).

    There are many approaches that can be taken to solve this problem. Here are some examples:

    1. The most theoretically correct method would be to find a good specification of the TIFF file format, then look at the bad files with some hex or binary editor to figure out what's wrong, and finally write a program that reads each image as a raw stream of bytes, recovers the good data (such as the image data itself) and rewrites it correctly.
    2. The most theoretically incorrect method is to do it by hand: take each image, open it on mspaint, and save it. Depending on the ammount of images to process, this may easily be an insane task.
    3. Another approach would be to exploit the known fact that mspaint is capable of fixing the files' issue: it'd be enough to pass the right arguments or DDE options to paint for it to do the job. The bad thing is that there is no documentation about what does mspaint accept through either the command-line or DDE. Some trial and error (for which you might find inspiration by looking at the non-default actions of different file types, such as "print", "play", and so on) may allow you to find the right way to do it, assuming that the program allows for this degree of control through at least one of these methods.
    4. Reverse-engineering the fix: this may be tricky, but if you get lucky you may get results without too much effort. Process by hand a reduced sample of files (a dozen or so may be enough, but it's hard to tell in advance); then compare the contents of the original and the fixed file. As soon as you find a pattern that describes the changes between each pair of files you just need to write the code to apply the same changes to any given file.
    These are the methods I can think from the top of my head. If you dare to engage with method #1, the links here may be of help: http://en.wikipedia.org/wiki/Tagged_Image_File_Format#External_links . For the other methods, I'm afraid there is much more help to be found: you'll be stepping into the unknown and only reverse-engineering and/or trial&error can guide you.

    Hope this helps.

    Regards,
    Herenvardo
    • Marked as answer by Jing0Moderator Monday, February 08, 2010 2:52 AM
    Thursday, January 28, 2010 7:35 PM
  • Check the DPI.  MSPaint may change it to 96 dpi.  You can change it in code to get the size you wish in Document Imaging Viewer. 

    Verified that MSPaint changes the dpi to the screen resolution.  
    • Edited by JohnWein Thursday, January 28, 2010 8:26 PM verified change in resolution.
    • Marked as answer by Jing0Moderator Monday, February 08, 2010 2:52 AM
    Thursday, January 28, 2010 8:14 PM

All replies

  • If you want your app to operate the same as mspaint,  you have to write code to do it.  .NET and paint save to the same formats.
    Thursday, January 28, 2010 3:08 PM
  • The reason I ask is that, due to the way Microsoft office document imaging viewer saves differently (or rather, the same way as the system.drawing.imaging.imageformat method in .net).
    Thursday, January 28, 2010 3:21 PM
  • It would if useful if, rather than describing what your code do (or what do you think it does), you posted the relevant snippets: if there were any mistakes your code could be doing something different to what you expected it to do.

    In any case, I think something like this should do the job:
    Dim img As Image
    img = New Bitmap("source filename")
    img.Save("destination filename", System.Drawing.Imaging.ImageFormat.Tiff)
    
    Of course, you need to change the strings on that snippet with the actual name of the files you want to load and save. I just tried it to do some conversions between formats and it worked fine.

    Regards,
    Herenvardo
    Thursday, January 28, 2010 4:21 PM
  • I know what you're saying, It's quite difficult to get across what i mean, because while I was trying to find a coding solution i'm confused as to how MSPaint manipulates the saved data (for the good, I might add!).

    The problem I'm having here is that we have source images that are wrong (they got converted by some third party badly and now we have to resolve the issue).  The images themselves (TIF) print out really small, best described as thumbnail.  The printing for the environment has to be done using Document Imaging viewer.  If i resave them in Document Imaging Viewer they stay the same, however if i load the image up in MSPaint and save it as TIF, and then print out via Document Imaging viewer then it works.

    I stumbled on code alike to yours and gave it a try.  When saving the TIF to TIF i got the same output as Document Imaging viewer.  I even tried saving it as Bitmap then saving again as TIF and got the same result.

    Granted there might be a more complicated way to code a solution, but I'm curious as to why MSPaint works.

    I've tried some other third party software (as I'd need to bulk convert the images) and they behave the same way as Document Imaging viewer.
    Thursday, January 28, 2010 5:29 PM
  • Allright. Then your problem is not about image conversion, but about fixing something that's wrong within the image file. Since you said that you can get them displaying fine after resaving them from paint, my educated guess is that the problem is within the files' header information (if the image data had been reduced, there wouldn't be any way to actually recover the data).

    There are many approaches that can be taken to solve this problem. Here are some examples:

    1. The most theoretically correct method would be to find a good specification of the TIFF file format, then look at the bad files with some hex or binary editor to figure out what's wrong, and finally write a program that reads each image as a raw stream of bytes, recovers the good data (such as the image data itself) and rewrites it correctly.
    2. The most theoretically incorrect method is to do it by hand: take each image, open it on mspaint, and save it. Depending on the ammount of images to process, this may easily be an insane task.
    3. Another approach would be to exploit the known fact that mspaint is capable of fixing the files' issue: it'd be enough to pass the right arguments or DDE options to paint for it to do the job. The bad thing is that there is no documentation about what does mspaint accept through either the command-line or DDE. Some trial and error (for which you might find inspiration by looking at the non-default actions of different file types, such as "print", "play", and so on) may allow you to find the right way to do it, assuming that the program allows for this degree of control through at least one of these methods.
    4. Reverse-engineering the fix: this may be tricky, but if you get lucky you may get results without too much effort. Process by hand a reduced sample of files (a dozen or so may be enough, but it's hard to tell in advance); then compare the contents of the original and the fixed file. As soon as you find a pattern that describes the changes between each pair of files you just need to write the code to apply the same changes to any given file.
    These are the methods I can think from the top of my head. If you dare to engage with method #1, the links here may be of help: http://en.wikipedia.org/wiki/Tagged_Image_File_Format#External_links . For the other methods, I'm afraid there is much more help to be found: you'll be stepping into the unknown and only reverse-engineering and/or trial&error can guide you.

    Hope this helps.

    Regards,
    Herenvardo
    • Marked as answer by Jing0Moderator Monday, February 08, 2010 2:52 AM
    Thursday, January 28, 2010 7:35 PM
  • Check the DPI.  MSPaint may change it to 96 dpi.  You can change it in code to get the size you wish in Document Imaging Viewer. 

    Verified that MSPaint changes the dpi to the screen resolution.  
    • Edited by JohnWein Thursday, January 28, 2010 8:26 PM verified change in resolution.
    • Marked as answer by Jing0Moderator Monday, February 08, 2010 2:52 AM
    Thursday, January 28, 2010 8:14 PM
  • I'll have a look at this, thanks all for your help.
    Friday, January 29, 2010 1:37 PM
  • Hi,

     

    How is this problem now?

     

    If there is anything unclear, please feel free to tell us.

     

    Please remember to click “Mark as Answer” on the post that helps you.This can be beneficial to other community members reading the thread.

     

    Best regards,

    Ling Wang


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    Thursday, February 04, 2010 12:05 PM
    Moderator