forked from PriesiaMioShirakana/McEntityplayer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjpeg.h
More file actions
104 lines (66 loc) · 2.46 KB
/
Copy pathjpeg.h
File metadata and controls
104 lines (66 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#ifndef Jpeg_load_S
#define Jpeg_load_S
#define Xlimit 1920//定义像素(X)
#define Ylimit 1080//定义像素(Y)
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <windows.h>
#include <gdiplus.h>
#pragma comment(lib, "gdiplus.lib")
using namespace std;
using namespace Gdiplus;
struct Image_pixel_data { //RGB通道存储(结构体)
int IPDR;
int IPDG;
int IPDB;
};
wstring strToStdWString(const string& str) //将单字节字符串转换为二字节字符串(因为Gdiplus库仅支持二字节字符串文件名)
{
wstring wStr;
int len = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)str.c_str(), str.size(), NULL, 0);
TCHAR* buffer = new TCHAR[len + 1];
MultiByteToWideChar(CP_ACP, 0, (LPCSTR)str.c_str(), str.size(), buffer, len);
buffer[len] = '\0';
wStr.append(buffer);
return wStr;
}
int init = 0; //初始化
vector <vector <Image_pixel_data>> loaded_Image_pixel_data; //本次数据
vector <vector <Image_pixel_data>> L_loaded_Image_pixel_data; //上一个数据
void Get_Image_pixel_RGB(wstring infilename) { //获取每个像素点的RGB值并存入上述容器
GdiplusStartupInput gdiplusstartupinput;
ULONG_PTR gdiplustoken;
GdiplusStartup(&gdiplustoken, &gdiplusstartupinput, NULL);
Bitmap* bmp = new Bitmap(infilename.c_str());
UINT height = bmp->GetHeight();
UINT width = bmp->GetWidth();
cout << "width " << width << ", height " << height << endl;
if (loaded_Image_pixel_data.size() == 0) {
Image_pixel_data Image_pixel_data_i;
vector <Image_pixel_data> loaded_Image_pixel_data_out;
for (int i = 0; i < Xlimit; i++) {
loaded_Image_pixel_data_out.push_back(Image_pixel_data_i);
}
for (int aaa = 0; aaa < Ylimit; aaa++) {
loaded_Image_pixel_data.push_back(loaded_Image_pixel_data_out);
}
}
Color color;
for (UINT y = 0; y < Ylimit; y++) {
for (UINT x = 0; x < Xlimit; x++) {
bmp->GetPixel(x, y, &color);
loaded_Image_pixel_data[y][x].IPDR = (int)color.GetRed();
loaded_Image_pixel_data[y][x].IPDG = (int)color.GetGreen();
loaded_Image_pixel_data[y][x].IPDB = (int)color.GetBlue();
}
}
if (init == 0) {
L_loaded_Image_pixel_data = loaded_Image_pixel_data; //保存上一次的结果用于下一次的比较
init = 1;
}
delete bmp;
GdiplusShutdown(gdiplustoken);
}
#endif