图像反色问题

jackyw 2005-03-09 07:39:37
下面是代码,有时候在反色处理的时候,图像右边有一部分图像不变化,特别是在灰度图像的时候,
而且在处理完浮雕以后都有一部分图像不变化,请帮忙解决一下。
Graphics::TBitmap *pBitmap = new Graphics::TBitmap();

BYTE *ptr;

pBitmap->Assign(CurrentForm->Image1->Picture->Graphic);
pBitmap->Width=CurrentForm->Image1->Width ;
pBitmap->Height=CurrentForm->Image1->Height ;

for (int y = 0; y <pBitmap->Height; y++)
{
ptr =(BYTE *)pBitmap-> ScanLine[y];
for (int x = 0; x < pBitmap->Width*3; x+=3)
{
ptr[x]=BYTE(255-ptr[x]);
ptr[x+1]=BYTE(255-ptr[x+1]);
ptr[x+2]=BYTE(255-ptr[x+2]);
}
}
CurrentForm->Image1->Picture->Graphic=pBitmap;

delete pBitmap;
...全文
233 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
BlueCapricorn 2005-03-10
  • 打赏
  • 举报
回复
针对楼上的意见,可以通过修改图像的格式来确定图片的格式。
jadeluo 2005-03-10
  • 打赏
  • 举报
回复
for (int x = 0; x < pBitmap->Width*3; x+=3)

改成

for (int x = 0; x < pBitmap->Width*4; x+=4)


另外, 建议楼主看看关于TBitmap的PixelFormat属性的说明,你现在的程序只能处理pf32bit的Bitmap。
shally5 2005-03-09
  • 打赏
  • 举报
回复
我的方法:
void __fastcall TChildForm::I1Click(TObject *Sender)
{
//CurrentForm=(TChildForm *)ActiveMDIChild;
DWORD Color;
BYTE *ptr;
Graphics::TBitmap *tmpBitmap=new Graphics::TBitmap();
tmpBitmap->Assign((TPersistent*)Image1->Picture->Graphic);//CurrentForm->Image1->Picture->Graphic);
tmpBitmap->PixelFormat=pf24bit;

for (int y = 0; y < tmpBitmap->Height; y++)
{
ptr =(BYTE *) tmpBitmap->ScanLine[y];
for (int x = 0; x < tmpBitmap->Width*3; x+=3){
Color=DWORD(TColor(RGB(ptr[x+2],ptr[x+1],ptr[x])));
ptr[x+2]=0xFF-BYTE(Color);
ptr[x+1]=0xFF-BYTE(Color>>8);
ptr[x]=0xFF-BYTE(Color>>16);
}
}
Image1->Picture->Graphic=tmpBitmap;
Image1->Refresh();
delete tmpBitmap;
}
  • 打赏
  • 举报
回复
ptr[x] = ptr[x] ^ 0xFF;
试试。

13,825

社区成员

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

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