无所事事,就写了很简单且无聊的程序,就是bmp图片和jpg图片的相互转换,下面是程序: jpg图片转换为bmp图片: 下载地址:http://sites.google.com/site/pengsky9/xia-zai/jpg2bmp.7z?attredirects=0 说明:将jpg图片转化为bmp图片 1、将需要转换的jpg图片放到jpg目录下 2、运行jpg2bmp.exe即可 -------------------------------------------------------------------------------- #include <cstdlib> #include <iostream> #include <vector> #include <string> #include <fstream> using namespace std; #include <cv.h> #include <cxcore.h> #include <highgui.h> int main(int argc, char *argv[]) { system("dir /b jpg > jpglist.txt"); ifstream jpglist("jpglist.txt"); vector<string> jpgName; string buf; while(jpglist) { if(getline(jpglist,buf)) { jpgName.push_back(buf); } } jpglist.close(); for(string::size_type i=0;i<jpgName.size();i++) { string save_dir="bmp/"; string open_dir="jpg/"; string filename=jpgName[i]; string file_no_ext=""; for(int j=0;j<jpgName[i].length()-4;j++) { file_no_ext+=filename[j]; } file_no_ext.append(".bmp"); IplImage *src=cvLoadImage(open_dir.append(jpgName[i]).c_str()); if(!src) { cout<<"can not load the image : "<<jpgName[i]<<endl; break; } cout<<"processing "<<jpgName[i]<<endl; cvSaveImage(save_dir.append(file_no_ext).c_str(),src); cvReleaseImage(&src); src=NULL; } system("PAUSE"); return EXIT_SUCCESS; } bmp图片转换为jpg图片: 下载地址:http://sites.google.com/site/pengsky9/xia-zai/bmp2jpg.7z?attredirects=0 说明:将后缀名为bmp的图片转化为jpg图片 1、将需要转换的bmp图片放到bmp目录下 2、运行bmp2jpg.exe即可 -------------------------------------------------------------------------------- #include <cstdlib> #include <iostream> #include <vector> #include <string> #include <fstream> using namespace std; #include <cv.h> #include <cxcore.h> #include <highgui.h> int main(int argc, char *argv[]) { system("dir /b bmp > bmplist.txt"); ifstream bmplist("bmplist.txt"); vector<string> bmpName; string buf; while(bmplist) { if(getline(bmplist,buf)) { bmpName.push_back(buf); } } bmplist.close(); for(string::size_type i=0;i<bmpName.size();i++) { string save_dir="jpg/"; string open_dir="bmp/"; string filename=bmpName[i]; string file_no_ext=""; for(int j=0;j<bmpName[i].length()-4;j++) { file_no_ext+=filename[j]; } file_no_ext.append(".jpg"); IplImage *src=cvLoadImage(open_dir.append(bmpName[i]).c_str()); if(!src) { cout<<"can not load the image : "<<bmpName[i]<<endl; break; } cout<<"processing "<<bmpName[i]<<endl; cvSaveImage(save_dir.append(file_no_ext).c_str(),src); cvReleaseImage(&src); src=NULL; } system("PAUSE"); return EXIT_SUCCESS; } |