[求助]全彩转灰阶的程式码的问题

Home Home
引用 | 编辑 rei
2006-04-22 20:30
楼主
推文 x0
const int RED = 2;
const int GREEN = 1;
const int BLUE = 0;

void toGray(TImage *image)
{ Byte * ptr;
int r, g, b, gray, index;

image->Picture->Bitmap->PixelFormat = pf24bit; // for full-color image
for (int row=0; row<image->Picture->Height; ..

访客只能看到部份内容,免费 加入会员



献花 x0
引用 | 编辑 cmovies
2006-04-22 23:13
1楼
  
ptr = (Byte*) image->Picture->Bitmap->ScanLine[row];
-> 取得那个 Row 的影像资料内容的位址
影像资料存放的格式由 image->Picture->Bitmap->PixelFormat = pf24bit 来决定
pf24bit 就是影像资料有R G B 三个 Bytes (共24bits)

index+"xxx"跟ScanLine
-> 就是指向这个 Row 中的第 Index 点的哪个颜色 R G B
一般要做影像处理都会直接对影像资料作运算后再存回去
ScanLine 就能提供影像资料内容的位址供程式加以运算处理

const int RED   = 2;
const int GREEN = 1;
const int BLUE = 0;
-> 这就是影像资料的颜色存放的顺序

Copy from Borland online help:
Provides indexed access to each line of pixels.
property ScanLine[Row: Integer]: Pointer;
Description
ScanLine is used only with DIBs (Device Independent Bitmaps) for image editing tools that do low-level pixel work.

献花 x1
引用 | 编辑 rei
2006-04-23 10:10
2楼
  
下面是引用cmovies于2006-04-22 23:13发表的 :
index+"xxx"跟ScanLine
-> 就是指向这个 Row 中的第 Index 点的哪个颜色 R G B
一般要做影像处理都会直接对影像资料作运算后再存回去
ScanLine 就能提供影像资料内容的位址供程式加以运算处理

不好意思~

想再请问一下~

如果不做存回去的动作~在下的程式码应该怎么改?
//////////////////////////////////////////////////////////////
        ptr[index + BLUE ] = (Byte)gray;
        ptr[index + GREEN ] = (Byte)gray;
        ptr[index + RED   ] = (Byte)gray;
        index += 3;

//////////////////////////////////////////////////////////////
ptr = (Byte*) image->Picture->Bitmap->ScanLine[row];
//////////////////////////////////////////////////////////////

献花 x0
引用 | 编辑 cmovies
2006-04-23 12:49
3楼
  
不存回去那不就没改了吗? 那干嘛拿出来运算?
还是你要写到另一个 Bitmap?

下面三行拿掉就没有存回去了
    ptr[index + BLUE ] = (Byte)gray;
    ptr[index + GREEN ] = (Byte)gray;
    ptr[index + RED   ] = (Byte)gray;

献花 x1
引用 | 编辑 rei
2006-04-23 17:50
4楼
  
下面是引用cmovies于2006-04-23 12:49发表的 :
不存回去那不就没改了吗? 那干嘛拿出来运算?
还是你要写到另一个 Bitmap?

下面三行拿掉就没有存回去了
    ptr[index + BLUE ] = (Byte)gray;
.......

呵~

谢谢您捏~我的问题已经搞定啰!

图跟东西都可以很正常的秀出来了~XD

因为昨天我也是把那三行砍掉...可是也出问题>"<...

可是下午在弄一次却正常了= ="...

XD

献花 x0