图像镜像
  3LtouLW8lEKV 2023年11月02日 26 0


三个函数,垂直镜像、水平镜像、自定义镜像。


void CDIGTLSView::OnMirrorVertical()    //垂直镜像
//程序编制:李立宗
// 2012-8-6
{
if(myImage1.IsNull())
OnOpenResourceFile();
if(myImage2.IsNull()){
//myImage2.Destroy();
myImage2.Create(myImage1.GetWidth(),myImage1.GetHeight(),24,0);
}
COLORREF pixel;
int maxY = myImage1.GetHeight();
int maxX=myImage1.GetWidth();
int r,g,b,avg;
double c;
byte* pRealData;
byte* pRealData2;
pRealData=(byte*)myImage1.GetBits();
pRealData2=(byte*)myImage2.GetBits();
int pit=myImage1.GetPitch();
int pit2=myImage2.GetPitch();
//需要注意,pit和pit2的值并不一样,所以如果使用一个值,会导致不同的结果出现
//CString str;
//str.Format(TEXT("%d"),pit2);
//MessageBox(str);
//str.Format(TEXT("%d"),pit2);
//MessageBox(str);
int bitCount=myImage1.GetBPP()/8;
int bitCount2=myImage2.GetBPP()/8;
//CString str;
//str.Format(TEXT("%d"),bitCount);
//MessageBox(str);
//str.Format(TEXT("%d"),bitCount2);
//MessageBox(str);
int newValue;
int tempR,tempG,tempB;
int key1,key2; //用来控制方向
//srand((unsigned)time(NULL));
//key1=rand()%100;
//key2=rand()%100;
//if(key1>50)
// key1=-1;
//else
// key1=1;
//if(key2<50)
// key2=1;
//else
// key2=-1;
//int xTrans=key1*rand()%(int)(maxX/1.5)+1;
//int yTrans=key2*rand()%(int)(maxY/1.5)+1;
//说明:将生产的图像作为24位图处理。
for (int y=0; y<maxY; y++) {
for (int x=0; x<maxX; x++) {
if((maxY-1-y>=0)&&(maxY-1-y<=maxY))
{ tempR=(int)(int)(*(pRealData+pit*(maxY-1-y)+x*bitCount));
if(bitCount==1)
{tempG=tempR;
tempB=tempR;}
else
{

tempG=(int)(int)(*(pRealData+pit*(maxY-1-y)+x*bitCount+1));
tempB=(int)(int)(*(pRealData+pit*(maxY-1-y)+x*bitCount+2));
}
}
else
{
tempR=255;
tempG=0;
tempB=0;
}

*(pRealData2+pit2*y+x*bitCount2)=tempR;
*(pRealData2+pit2*y+x*bitCount2+1)=tempG;
*(pRealData2+pit2*y+x*bitCount2+2)=tempB;
}

}
Invalidate();
}


void CDIGTLSView::OnMirrorHorizental() //水平镜像
{
if(myImage1.IsNull())
OnOpenResourceFile();
if(myImage2.IsNull()){
//myImage2.Destroy();
myImage2.Create(myImage1.GetWidth(),myImage1.GetHeight(),24,0);
}
COLORREF pixel;
int maxY = myImage1.GetHeight();
int maxX=myImage1.GetWidth();
int r,g,b,avg;
double c;
byte* pRealData;
byte* pRealData2;
pRealData=(byte*)myImage1.GetBits();
pRealData2=(byte*)myImage2.GetBits();
int pit=myImage1.GetPitch();
int pit2=myImage2.GetPitch();
//需要注意,pit和pit2的值并不一样,所以如果使用一个值,会导致不同的结果出现
//CString str;
//str.Format(TEXT("%d"),pit2);
//MessageBox(str);
//str.Format(TEXT("%d"),pit2);
//MessageBox(str);
int bitCount=myImage1.GetBPP()/8;
int bitCount2=myImage2.GetBPP()/8;
//CString str;
//str.Format(TEXT("%d"),bitCount);
//MessageBox(str);
//str.Format(TEXT("%d"),bitCount2);
//MessageBox(str);
int newValue;
int tempR,tempG,tempB;
int key1,key2; //用来控制方向
//srand((unsigned)time(NULL));
//key1=rand()%100;
//key2=rand()%100;
//if(key1>50)
// key1=-1;
//else
// key1=1;
//if(key2<50)
// key2=1;
//else
// key2=-1;
//int xTrans=key1*rand()%(int)(maxX/1.5)+1;
//int yTrans=key2*rand()%(int)(maxY/1.5)+1;
//说明:将生产的图像作为24位图处理。
for (int y=0; y<maxY; y++) {
for (int x=0; x<maxX; x++) {
if((maxX-1-x>=0)&&(maxX-1-x<=maxX))
{ tempR=(int)(int)(*(pRealData+pit*y+(maxX-1-x)*bitCount));
if(bitCount==1)
{tempG=tempR;
tempB=tempR;}
else
{

tempG=(int)(int)(*(pRealData+pit*y+(maxX-1-x)*bitCount+1));
tempB=(int)(int)(*(pRealData+pit*y+(maxX-1-x)*bitCount+2));
}
}
else
{
tempR=255;
tempG=0;
tempB=0;
}

*(pRealData2+pit2*y+x*bitCount2)=tempR;
*(pRealData2+pit2*y+x*bitCount2+1)=tempG;
*(pRealData2+pit2*y+x*bitCount2+2)=tempB;
}

}
Invalidate();
}


void CDIGTLSView::OnMirrorCustome() //自定义水平、垂直镜像
{
if(myImage1.IsNull())
OnOpenResourceFile();
CMyMirror myDlg;
int myAngle;
if(myDlg.DoModal () == IDOK)
{
myAngle=myDlg.myMirror;
// CString str;
//str.Format(TEXT("%d"),myAngle);
//MessageBox(str);
if(myAngle==0)
OnMirrorHorizental();
else

OnMirrorVertical();
}
else
{
myImage2.Destroy();
Invalidate();
}
}



【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  3LtouLW8lEKV   2023年11月02日   27   0   0 自定义位图nullbyte
3LtouLW8lEKV
最新推荐 更多