load tiff using FreeImage

情到浓时终转凉″ 提交于 2019-12-24 09:36:55

问题


I tried this code with FreeImage to load my tif, and i get no error, but also no output. It works just fine if the input is a jpg. My tiff input is 16-bit greyscale.

public void OpenRotateSave()
    {
        // load image,  16-bit tif 
       FIBITMAP dib = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_TIFF, "Mytif.tif",FREE_IMAGE_LOAD_FLAGS.DEFAULT);         
        // save image
        FreeImage.SaveEx(dib, "MyTifOut.jpg");
        // unload bitmap
        FreeImage.UnloadEx(ref dib);
    }

I tried to Load without the modifiers, using just the filename, the same result. Also tried LoadEx.

Much Thanks, Dan


回答1:


According to http://downloads.sourceforge.net/freeimage/FreeImage3170.pdf Page 117, Appendix, Supported file formats => FreeImage does not support 16bit PNG.

The specification https://en.wikipedia.org/wiki/Portable_Network_Graphics#Pixel_format allows 16bit greyscale without alpha. I have never seen one...




回答2:


I made a lot of progress by using the examples for Load and Save in the Wraper folder with the newest distribution:

FreeImage\Wrapper\FreeImage.NET\cs\Samples\Sample 01 - Loading and saving

It turns out the load worked fine, but it does not seem so easy to save the 16-bit image. I tried converting to 8 bits or greyscale, and then save as jpeg, but i got no output and no error message. What i found works is saving to PNG as follows:

public void OpenSave()
  {
  string InFileName = "MyTiff.tif";
  string OutFileName = "MyOutputFile";
  // load image,  16-bit tif 
  FIBITMAP dib = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_TIFF, InFileName,FREE_IMAGE_LOAD_FLAGS.DEFAULT);         
  // save image
  FreeImage.SaveEx(
       ref dib,
       OutFileName, // FreeImage will add a file extension. NB: SaveEx will strip the file extension from OutFileName, and replace it with png, so even if OutFileName = "MyOutFile.jpg", SaveEx will save it here as MyOutFile.png"
       FREE_IMAGE_FORMAT.FIF_PNG,                               
       FREE_IMAGE_SAVE_FLAGS.DEFAULT,                      
       FREE_IMAGE_COLOR_DEPTH.FICD_04_BPP,                 
       true);
   FreeImage.UnloadEx(ref dib);
   }

I don't need any particular output format, since what i am interested in for this application is openning a tiff and manipulating the bits, so I am complete for this question.

Thanks for reading, Dan



来源:https://stackoverflow.com/questions/16290459/load-tiff-using-freeimage

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!