求救!!!Image的"Canvas is not allow to drawing"错误!!!

christopher_hp 2004-09-18 12:22:01
我的form上有一个panel,panel是用来显示视频图象的(用的VFW),然后有个TIMAGE,是保存图象的,有个BYTE的数组保存image->Canvas->Pixels像素值,用来计算图象中圆的中心。
工作工程如下:接受一个指令,执行GetCaptruePicData函数,先停止视频显示,然后bitblt拷贝图象到image上面,然后取得像素值,然后掉用算法取得圆中心,然后把数据还回IMAGE并且保存图象文件,最后让视频采集。

bool __fastcall TMainForm::GetCaptruePicData()
{
float Cx, Cy, R;
bool result =true;
int i, j, l=0;
TColor RGB;
HDC hdc =NULL;
int width, height;
hdc =GetDC(Panel1->Handle);
//if(Set_GetFramePic())
//{
try
{
BitBlt(image->Canvas->Handle, 0, 0, image->Width, image->Height,
hdc, 0, 0, SRCCOPY);
image->Picture->SaveToFile("c:\\temp1.bmp");
//保存采集原始图象
image->Width =image->Picture->Bitmap->Width;
image->Height =image->Picture->Bitmap->Height;
if(lpBits)
delete lpBits;
lpBits =new BYTE[image->Width*image->Height];
//分配图象数据
}
__finally
{
for(i=0; i<image->Height; i++)
for(j=0; j<image->Width; j++)
{
RGB =image->Canvas->Pixels[j][i];
lpBits[l++] =(GetRValue(RGB) +GetGValue(RGB) +GetBValue(RGB))/3;


}
}
if(GetCirclePara(image->Width, image->Height, lpBits, 0, Cx,Cy,R, 20))
//取得圆心
{
l =0;
for(i=0; i<image->Height; i++)
for(j=0; j<image->Width; j++)
{
image->Canvas->Pixels[j][i] =(TColor)RGB(lpBits[l], lpBits[l], lpBits[l]);
l++;
}
image->Picture->SaveToFile("c:\\temp.bmp");
//保存画出圆心的图象
if(bFirstScale ==true)
ModiForm->newRadio =R;
if(m_bRevise ==true)
{
dx =Cx -gCapWidth/2;
dy =Cy -gCapHeight/2;
m_bRevise =false;
}
params[0] =(Cx -gCapWidth/2 +dx)*m_fModulus*1000/cos(m_fXDipRate*3.1415927/180)/m_fStepLengX;
params[1] =(Cy -gCapHeight/2 +dy)*m_fModulus*1000/cos(m_fYDipRate*3.1415927/180)/m_fStepLengY;
radio =R;
//ShowMessage(FloatToStr(R));
}
else
{
if(bFirstScale)
ModiForm->newRadio =0;
MessageBeep(0);
ShowMessage("error to get circle");
result =false;
}
//}
ReleaseDC(Panel1->Handle, hdc);
//Sleep(1000) //加了好象就不容易出错了
//Set_Preview();
return result;
}
请教为什么出错啊!?
...全文
127 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
大大怪老张 2004-09-18
  • 打赏
  • 举报
回复
没搞过 :(
问题生 2004-09-18
  • 打赏
  • 举报
回复
我不会帮顶
gdyt007 2004-09-18
  • 打赏
  • 举报
回复
研究ing
lbg 2004-09-18
  • 打赏
  • 举报
回复
帮顶
tanlim 2004-09-18
  • 打赏
  • 举报
回复
ReleaseDC(Panel1->Handle, hdc);
对于VCL组件体系中的句柄不能使用这样的方法释放的
要在VCL组件对像本身释放后,由组件析构函数来完成
ahaozi 2004-09-18
  • 打赏
  • 举报
回复
兄弟,我只能帮你顶了!

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧