19,468
社区成员
发帖
与我相关
我的任务
分享
if(msg[i]==symbol[j]) //确定了当前消息字符是哪一个
{
if(j==0) //若当前消息字符是第一个信源符号,区间缩减只改变右端点
{
low=Low; //进行区间缩减时保持区间左端点不变
high=Low+chance[j]*wid; //右端点=左端点+信源符号概率*区间长度
High=high;
wid*=chance[j];
}
else //若当前消息字符不是第一个信源符号,左右端点均改变
{
long double chance_l=0.0;
for(int k=0;k<=j-1;k++)
chance_l+=chance[k];
low=Low+wid*chance_l;
high=Low+wid*(chance_l+chance[j]);
Low=low;
High=high;
wid*=chance[j];
}
#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;
}