FreeImage映像編程入門

來源:互聯網
上載者:User

(來源:http://blog.bioon.net/user1/2484/archives/2009/233212.shtml

過去一直使用OpenGL進行圖形編程,聽說使用FreeImage進行圖形處理非常方便,最近一段時間學習使用FreeImage進行圖形編程。在http://freeimage.sourceforge.net/

載了最新的FreeImage 3.12.0 [WIN32],
解壓縮該FreeImage3120Win32.zip檔案,將子檔案夾Dist下,FreeImage.h、FreeImage.lib和
FreeImage.dll分別放到vc安裝資料夾的Include檔案夾、LIB檔案夾和Bin檔案夾中。此外,http://freeimage.sourceforge.net/
網站上可以下載FreeImage開發組寫的參考手冊( 《a free, open source graphics library》), 該網站上也可以下載到湖南地震局黎品忠先生翻譯成的中文版參考手冊(《一個自由、開源的圖形庫》)。

需要特別注意的是:需要在使用FreeImage庫的xxx.CPP或xxx.C程式中進行如下聲明:
#i nclude"FreeImage.h"
#pragma comment(lib,"FreeImage.lib")
-----------------------------------------------------------------------------------------
一個簡單的程式如下:(轉載於梅園 《FreeImage學習筆記》 http://blog.chinaunix.net/u1/58776/showart_527523.html

#i nclude <iostream>
#i nclude <cassert>
#i nclude"FreeImage.h"
#pragma comment(lib,"FreeImage.lib")

#define show(a) std::cout<< a <<std::endl

int main(int argc,char *argv)
{
   //初始化FreeImage
   FreeImage_Initialise(TRUE);

   //預設分配一塊記憶體儲存影像,其中bpp表示映像深度
   //FIBITMAP *bitmap = FreeImage_AllocateT(FIT_BITMAP,Width,height,bpp,
   //red_mask,green_mask,blue_mask);

   //最後一個參數用來改變函數的行為或啟用位元影像外掛程式的一種特性,每個外掛程式有他自己的參數集
   //FreeImage_LoadU參數都是一樣,不過只在win32下起作用
   FIBITMAP * bmp = FreeImage_Load(FIF_BMP,"cs5.BMP",BMP_DEFAULT);

   //FreeImage_SaveU和上面的一樣
   if( bmp)
   {
  //FreeImage_Save(FIF_BMP, bmp, "whtm.bmp", BMP_DEFAULT);
   }

   //擷取影像的寬高,都以像素為單位
   int Width = FreeImage_GetWidth(bmp);
   int Height = FreeImage_GetHeight(bmp);

   //擷取影像的byte寬度,不對,我上面運行與Width相等
   int ByteWidth = FreeImage_GetLine(bmp);

   //返回每個像素使用灰階值
   show(FreeImage_GetBPP(bmp));
   //返回資料類型
   show(FreeImage_GetImageType(bmp));
   //返回調色盤的大小
   show(FreeImage_GetColorsUsed(bmp));

   show(Width<<" "<<Height<<" "<<ByteWidth);

 //assert(ByteWidth == Width*8 );

   show(FreeImage_GetDIBSize(bmp));

   //有調用load就有unload,否則就會記憶體流失
   FreeImage_Unload(bmp);
   FreeImage_DeInitialise();

   return 0;
}

 

(FreeImage是映像編程四大庫(OpenCV/FreeImage/CImg/CxImage)之一。FreeImage:C語言的體系,大量使用指標運算速度可以保證,內含先進的多種插值演算法。
另外專屬的支援meta exif資訊的讀取。該庫最大的特點就是比較簡練,只把重點放在對各種格式映像的讀取寫入支援上,沒有顯示部分,實際編程的時候還是需要調用API函數進行顯示。

 

其它資料:

http://hi.baidu.com/brianlanbo/blog/item/67c85e11c4c9972fdc540142.html

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.