![]() |
c的讀圖檔
我對c比較不強
1.如何用c把一個jpg讀入,讀到一個陣列裡? 2.把陣列旋轉? 比如有一個圖片為 [ 1 , 2 3 , 4 ] 旋轉+90度後為 [ 2 , 4 1 , 3 ] -90度為 [ 3 , 1 4 , 2 ] |
這裡有一篇
http://209.85.173.104/search?q=cache...&lr=lang_zh-TW 是用 C++ 及 GDI+ 示範的是 讀一個 lena.jpg 存成 newlena.jpg 只要對 newImage->SetPixel 之 x,y 重新排列 就可達到旋轉圖像 的功能 正常是 從左上角 0,0 一直讀寫到 右下角 x,y 要轉90度 只要 先讀 y 而 寫入 x 即可 |
我是用dev-c++的,編繹好像不行
我再從最基礎的來研究一下好了~ |
引用:
需要點 FreeImage (Open Source) 去下載 FreeImage3100Win32.zip |
FreeImage3100Win32.zip 放哪?
FreeImage3100Win32.zip
要放在dev-c++的哪個資料夾下啊 |
用 GDLIB 做圖像旋轉
// 省略不重要部份
.... .... imgtype = JPG; .... File = fopen(Buffer,"rb"); .... .... if(imgtype == JPEG) { img = gdImageCreateFromJpeg(File); } else if(imgtype == GIF) { img = gdImageCreateFromGif(File); } else if(imgtype == PNG) { img = gdImageCreateFromPng(File); } else { img = gdImageCreateFromWBMP(File); } fclose(File); ... ... // rotate angle i = 90; .... aCos = cos (i * .0174532925); aSin = sin (i * .0174532925); size_x = gdImageSX(img); size_y = gdImageSY(img); switch(i) { case 180: if (imgtype == GIF || imgtype == WBMP) new_img = gdImageCreate(size_x,size_y); else new_img = gdImageCreateTrueColor(size_x,size_y); break; case 90: case 270: if (imgtype == GIF || imgtype == WBMP) new_img = gdImageCreate(size_y,size_x); else new_img = gdImageCreateTrueColor(size_y,size_x); break; default: aCos = cos (i * .0174532925); aSin = sin (i * .0174532925); if (imgtype == GIF || imgtype == WBMP) new_img = gdImageCreate(abs((int)(size_x*aCos))+abs((int)(size_y*aSin)), abs((int)(size_y*aCos))+abs((int)(size_x*aSin))); else new_img = gdImageCreateTrueColor(abs((int)(size_x*aCos))+abs((int)(size_y*aSin)), abs((int)(size_y*aCos))+abs((int)(size_x*aSin))); break; } .... .. . 翁 |
用 GDLIB 做圖像旋轉 - 2
// 少貼一段
... .. gdImageCopyRotated(new_img, img, (abs((int)(size_x*aCos))+abs((int)(size_y*aSin)))/2, (abs((int)(size_y*aCos))+abs((int)(size_x*aSin)))/2, //size_x/2, size_y/2, 0,0, size_x, size_y, i); gdImageDestroy(img); img = new_img; ... .. . |
我個人是比較不建議在 Windows 環境下寫 C(當然寫 for windows 的 app 例外)
當然這要看對 C99 標準的支援度要求 至少我看到的 Windows 下的 Compiler,不論是 C++ Builder 還是 MinGW 編出來的東西有的時候會出現 "意想不到" 的結果 還是用 Gnu C 比較實在 用套自己習慣的 Linux 再配上 Eclipse CDT 就很讚了 |
所有時間均為台北時間。現在的時間是 01:49 AM。 |
Powered by vBulletin® 版本 3.6.8
版權所有 ©2000 - 2025, Jelsoft Enterprises Ltd.
『服務條款』
* 有問題不知道該怎麼解決嗎?請聯絡本站的系統管理員 *