在非模式对话框上添加一个Slider控件,当滑动Slider时,图像二值化效果能立即做相应地改变(类似photoshop的有些功能),不知道该怎么实现。我现在的一个问题是当用滑块改变一次,再滑动滑块时是在图像已经改变的基础上所做的改变,大家提供点思路,谢谢了。
我的二值化的处理函数
n_Threshold = m_BinDlg->m_Threshold;//n_Threshold是要改变的二值化的数值,m_Threshold是通过slider改变得到的数值
BYTE *pbIndex; //定义指针,引入图象
BYTE *pbIndex1;
float temp; //求的灰度值
int i,j;
int Blue; //定义蓝绿红
int Green;
int Red;
int BytesPerLine; ///////////////////////////////////
//The basic steps: first convert the color image to gray one, then perform the binarization
pbIndex=pdib;
BytesPerLine=Width*3; if(BytesPerLine%4!=0)
BytesPerLine=(BytesPerLine/4+1)*4;  pdib1=(BYTE *)new char[BytesPerLine*Height]; //申请空间为了显示三个分量结果
pbIndex1=pdib1; for(i=0;i<Height;i++)//对图象进行遍历
for(j=0;j<Width;j++)
{
pbIndex=pdib+i*BytesPerLine+j*3;//注意图象的补齐
pbIndex1=pdib1+i*BytesPerLine+j*3;//用于保留原图像
Blue=*(pbIndex);
Green=*(pbIndex+1);
Red=*(pbIndex+2);
    temp=(float)(114*Blue+587*Green+299*Red)/1000; //Convert the color image to be gray one if(temp>=n_Threshold) //Perform binarization
{
*pbIndex=255;
pbIndex++;
*pbIndex=255;
pbIndex++;
*pbIndex=255;
}
else
{
*pbIndex=0;
pbIndex++;
*pbIndex=0;
pbIndex++;
*pbIndex=0;
} *pbIndex1=(BYTE)Blue; //Let the orignal image display at the same time
       pbIndex1++;
    *pbIndex1=(BYTE)Green;
       pbIndex1++;
    *pbIndex1=(BYTE)Red; } Invalidate();

解决方案 »

  1.   

    能具体说一下实现的方法吗?初学MFC,思路不大清晰
      

  2.   

    不知道你用过CImage没有,
    对话框声明两个图片对象,如:
    CImage m_imgOrg;
    CImage m_imgProcessing;
    把要处理的用m_imgOrg.Load()进去,
    每次处理显示的是m_imgProcessing显示。
    m_imgOrg数据不改变,m_imgProcessing为处理后的图片。
    操作很简单,获得图像数据指针:GetBIts();
    只是图片指针位置要注意,图片指针为指向图片尾,看msdn就清楚了:)
    CBitmap 类似,思想一样,处理手段不同