使用FreeImage加载tiff [英] load tiff using FreeImage

查看:341
本文介绍了使用FreeImage加载tiff的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试用FreeImage这段代码来加载我的tif,但没有错误,但是也没有输出.如果输入为jpg,则效果很好.我的tiff输入是16位灰度.

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);
    }

我尝试仅使用文件名而不使用修饰符进行加载,结果相同.还尝试了LoadEx.

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

非常感谢, 丹

推荐答案

在Wraper文件夹中,使用最新发行版的Load and Save示例,我取得了很大进步:

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-加载和保存

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

事实证明,负载工作正常,但是保存16位图像似乎并不容易.我尝试转换为8位或灰度,然后另存为jpeg,但没有输出,也没有错误消息.我发现可以将以下内容保存为PNG:

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);
   }

我不需要任何特定的输出格式,因为我对此应用程序感兴趣的是打开一个tiff并操纵这些位,所以我对这个问题很了解.

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.

感谢您的阅读, 丹

这篇关于使用FreeImage加载tiff的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆