图片保存到数组中

C++语言 码拜 8年前 (2016-04-15) 965次浏览
c++新手:int *a=new a[100];
怎么实现将视频中的图片存到a[]中?
解决方案

10

仅供参考:

#include <iostream>
#include <fstream>
#include <string>
#include <windows.h>
#include <gdiplus.h>
#pragma comment(lib, "gdiplus.lib")
using namespace std;
using namespace Gdiplus;
int main() {
    GdiplusStartupInput gdiplusstartupinput;
    ULONG_PTR gdiplustoken;
    GdiplusStartup(&gdiplustoken, &gdiplusstartupinput, NULL);
    wstring infilename(L"1.jpg");
    string outfilename("color.txt");
    Bitmap* bmp = new Bitmap(infilename.c_str());
    UINT height = bmp->GetHeight();
    UINT width  = bmp->GetWidth();
    cout << "width " << width << ", height " << height << endl;
    Color color;
    ofstream fout(outfilename.c_str());
    for (UINT y = 0; y < height; y++)
    for (UINT x = 0; x < width ; x++) {
            bmp->GetPixel(x, y, &color);
            fout << x << "," << y << ";"
                 << (int)color.GetRed()   << ","
                 << (int)color.GetGreen() << ","
                 << (int)color.GetBlue()  << endl;
    }
    fout.close();
    delete bmp;
    GdiplusShutdown(gdiplustoken);
    return 0;
}

10

引用:

c++新手:int *a=new a[100];
怎么实现将视频中的图片存到a[]中?

new a[100]…… 这是啥意思?new int[100]?100这个数字哪里来的?
首先你需要一个视频解码器,能获取视频中的图像数据(分辨率、像素类型等),能把每一帧视频抽取出来。存储的话,可以考虑容器,而不是动态分配的赤裸裸的指针。


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明图片保存到数组中
喜欢 (0)
[1034331897@qq.com]
分享 (0)