图片格式 jpg到ppm c++代码

来源:互联网 发布:qq三国js带什么宠物 编辑:程序博客网 时间:2024/05/22 11:46
// ipgToppm.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"    #include <stdio.h>    #include <iostream>    #include <cv.h>    #include <highgui.h>    #include <fstream>    using namespace std;      void jpg2ppm(char* input, char* output)   {    IplImage* jpg;    jpg = cvLoadImage(input, -1);    uchar ptrBlue, ptrGreen, ptrRed;        ofstream pppp;    ofstream ppm(output, ios::app | ios::binary);    ppm<<"P6"<<endl<<jpg->width<<" "<<jpg->height<<endl<<255<<endl;       for(int j = 0; j<jpg->height; j++)     for(int i = 0; i<jpg->width ; i++)       {      uchar* temp_ptr = &((uchar*)(jpg->imageData + jpg->widthStep*j))[i*3];      ptrBlue = temp_ptr[0];      ptrGreen = temp_ptr[1];      ptrRed = temp_ptr[2];         ppm << ptrRed << ptrGreen << ptrBlue;     }       ppm.close();   }      int _tmain(int argc, _TCHAR* argv[])   {       jpg2ppm("0.jpg","0.ppm");       return 0;   } 


 

原创粉丝点击