This method sets the RGB value and the palette number of a specified pixel in the Device Independent Bitmap (DIB)
Parameters
Name | Explanation |
---|---|
DibNo | The identification number of the DIB as retrieved from the StartDibAccess method. |
x, y | The x,y coordinates of the specified pixel |
PalNo | The palette number of the specified pixel |
Red | The red component of the RGB value of the specified pixel |
Green | The green component of the RGB value of the specified pixel |
Blue | The blue component of the RGB value of the specified pixel |
Return Value
Returns True if successful, otherwise returns False.
Explanation
The SetDibPixel method sets the RGB values and palette number of the specified pixel in the Device Independent Bitmap (DIB). The DibNo parameter value must be the same as that retrieved from the StartDibAccess method. For 1, 4, and 8 bit images, the applicable values are set in the PalNo parameter. For 16, 24, and 32 bit images, the applicable values are set in the Red, Green, and Blue parameters
To access the DIB and manipulate pixel data, you must use the
following methods as a group:
StartDibAccess
|
GetDibPixel, SetDibPixel
|
EndDibAccess
Note: If you want to access the DIB it is highly recommended
that you use the ImageKit DLL functions which are faster.
Sample Code
The following code starts access to the DIB, then loops through
each pixel in the image, using the GetDibPixel method to retrieve the
pixels' rgb values. Then those values are reversed and set using
the SetDibPixel method. (For 1,
16, 24, or 32 bit images)
In C++Builder
bool Ret;
short DibNo;
int i, j;
Byte PalNo, Red, Green, Blue;
VImageKit1->LayerNo = -1;
Ret = VImageKit1->GetImageType();
if (Ret == false) return;
Ret =
VImageKit1->Effect->StartDibAccess(VImageKit1->ImageHandle,
DibNo);
if (Ret == false) return;
for (i = 0; i < VImageKit1->ImageHeight;
i++)
{
for (j = 0; j <
VImageKit1->ImageWidth; j++)
{
Ret =
VImageKit1->Effect->GetDibPixel(DibNo, j, i, PalNo, Red,
Green, Blue);
if
(VImageKit1->BitCount == 1)
{
if (PalNo != 0)
PalNo = 0;
else
PalNo = 1;
} else if
(VImageKit1->BitCount > 8) {
Blue = 255 - Blue;
Green = 255 - Green;
Red = 255 - Red;
}
Ret =
VImageKit1->Effect->SetDibPixel(DibNo, j, i, PalNo, Red,
Green, Blue);
}
}
Ret =
VImageKit1->Effect->EndDibAccess(DibNo);
VImageKit1->Refresh();
In Delphi
Ret: Boolean;
DibNo: Smallint;
i, j: Longint;
PalNo, Red, Green, Blue: Byte;
VImageKit1.LayerNo := -1;
Ret := VImageKit1.GetImageType();
if Ret = False then Exit;
Ret :=
VImageKit1.Effect.StartDibAccess(ImageKit1.ImageHandle, DibNo);
if Ret = False then Exit;
for i := 0 to VImageKit1.ImageHeight - 1 do
begin
for j := 0 to VImageKit1.ImageWidth
- 1 do
begin
Ret :=
VImageKit1.Effect.GetDibPixel(DibNo, j, i, PalNo, Red, Green,
Blue);
if
VImageKit1.BitCount = 1 then
begin
if PalNo <> 0 then
PalNo := 0
else
PalNo := 1;
end
else if
VImageKit1.BitCount > 8 then
begin
Blue := 255 - Blue;
Green := 255 - Green;
Red := 255 - Red;
end;
Ret :=
VImageKit1.Effect.SetDibPixel(DibNo, j, i, PalNo, Red, Green,
Blue);
end;
end;
Ret := VImageKit1.Effect.EndDibAccess(DibNo);
VImageKit1.Refresh;
Differences from the ImageKit 7/8/9 ActiveX
The parameters PalNo, Red, Green, and Blue have been changed to type Byte.