我是新来的,我需要一些项目的帮助: 我的项目是合并两张图片,每个线程都有合并其部分的任务。
这是我的代码:
class Partie_Gauche {
public:
IMAGE & pict1;
IMAGE & pict2;
double beta;
double omega;
Partie_Gauche(IMAGE & image_1, IMAGE & image_2, double ruine, double b)
:pict1(image_1), pict2(image_2), beta(ruine), omega(b) {};
};
DWORD WINAPI Second_thread(LPVOID lpParam)
{
Partie_Gauche *m_thread = (Partie_Gauche*)lpParam;
DWORD idThread = GetCurrentThreadId(); //recupere l'identifiant du thread
int zeta = m_thread->omega;
for (int x = ((zeta * 1.0) / nbreThreads)*m_thread->pict1.width(); x < ((1.0 + zeta)*m_thread->pict1.width()) / nbreThreads; x++)
{
for (int y = 0; y < m_thread->pict1.height(); y++)
{
for (int c = 0; c < m_thread->pict1.spectrum(); c++) // les plans de couleur(R, G, B)
{
// détermination du ceof de pondération en fonction de la coordonnée y du pixel
double coef = m_thread->beta*(1 - double(y) / m_thread->pict1.height());
// somme pondérée des pixels
m_thread->pict1(x, y, 0, c) = (unsigned char)((1 - m_thread->beta)*m_thread->pict1(x, y, 0, c) + coef*m_thread->pict2(x, y, 0, c));
}
}
}
return 0;
}
最后我创建了我的主题:
'HANDLE tabThread[nbreThreads];
Partie_Gauche* m_Thd[nbreThreads];
for (int y(0); y > nbreThreads;y++)
m_Thd[y] = new Partie_Gauche(imageA, imageB, 0.5, (double)y);
for (int i = 0; i < nbreThreads; i++)
tabThread[i] = CreateThread(NULL, 0, Second_thread, &m_Thd[i], NULL, NULL);
WaitForMultipleObjects(nbreThreads, tabThread, true, INFINITE); '
然后编译器指示我违反内存访问的例外。 我不明白为什么。感谢