有一个24位的位图但只有两种颜色,clred和clblack现在想将其点阵存储下来,由于只有两种颜色,所以一个字节可以存储8个点,用Tbitmap的pixels属性或scanline属性都是太慢了,请大虾发表高见有没有好的办法,保存后还要打开,
2.如何将一个24位的位图转成一个单色的位图。
2.如何将一个24位的位图转成一个单色的位图。
解决方案 »
- 简单问题:怎么给WebBrowser1改名啊?
- 请教如何制作安装包?
- 请斑竹别删--救命的事(我在XP上如何访问2000?)
- 而且在DLL窗体中加了一个DBGridEh,动态实例化窗体至动态生成的tabSheet中,点击后报control 'dbGrid' has no parent
- 当鼠标的中键滚动时,如何是dbgrid中的记录指针也同时移动?
- 可怜可怜我吧,只有最后10分了,求怎样获得系统日期的年份和月份(2002、11),还有个问题就是统计记录的个数
- 请大家说说自己常用的API函数
- 有关VCL组件
- 程序员的下场,程序员的心声
- 哪里可以找到ADO使用的相关资料
- 小弟初学delphi,请问orbpas.pas 和orbpas.dcu这两个文件是干什么用的呀?
- 请教各位,如何设定DbGrid的数据显示格式?
灰度级处理
procedure Gray(bmp: TBitmap);
var
p: PByteArray;
w: Integer;
i, j: Integer;
begin
bmp.pixelformat := pf24bit;
for i := 0 to bmp.height - 1 do
begin
p := bmp.scanline[i];
j := 0;
while j < (bmp.width-1) * 3 do
begin
w :=(p[j] * 28 + p[j+1] * 151 + p[j+2]*77);
w := w shr 8;
p[j] := byte(w);
p[j+1] := byte(w);
p[j+2] := byte(w);
inc(j, 3)
end;
end;
end; **************************
//This function turns a colored Bitmap into Grayshades
uses
Windows, Graphics; function ConvertBitmapToGrayscale1(const Bitmap: TBitmap): TBitmap;
var
i, j: Integer;
Grayshade, Red, Green, Blue: Byte;
PixelColor: Longint;
begin
with Bitmap do
for i := 0 to Width - 1 do
for j := 0 to Height - 1 do
begin
PixelColor := ColorToRGB(Canvas.Pixels[i, j]);
Red := PixelColor;
Green := PixelColor shr 8;
Blue := PixelColor shr 16;
Grayshade := Round(0.3 * Red + 0.6 * Green + 0.1 * Blue);
Canvas.Pixels[i, j] := RGB(Grayshade, Grayshade, Grayshade);
end;
Result := Bitmap;
end; procedure ConvertBitmapToGrayscale2(const Bmp: TBitmap);
{From: Pascal Enz, [email protected] }
type
TRGBArray = array[0..32767] of TRGBTriple;
PRGBArray = ^TRGBArray;
var
x, y, Gray: Integer;
Row: PRGBArray;
begin
Bmp.PixelFormat := pf24Bit;
for y := 0 to Bmp.Height - 1 do
begin
Row := Bmp.ScanLine[y];
for x := 0 to Bmp.Width - 1 do
begin
Gray := (Row[x].rgbtRed + Row[x].rgbtGreen + Row[x].rgbtBlue) div 3;
Row[x].rgbtRed := Gray;
Row[x].rgbtGreen := Gray;
Row[x].rgbtBlue := Gray;
end;
end;
end;
procedure ConvertBitmapToGrayscale3(const Bitmap: TBitmap);
type
PPixelRec = ^TPixelRec;
TPixelRec = packed record
B: Byte;
G: Byte;
R: Byte;
Reserved: Byte;
end;
var
X: Integer;
Y: Integer;
P: PPixelRec;
Gray: Byte;
begin
Assert(Bitmap.PixelFormat = pf32Bit);
for Y := 0 to (Bitmap.Height - 1) do
begin
P := Bitmap.ScanLine[Y];
for X := 0 to (Bitmap.Width - 1) do
begin
Gray := Round(0.30 * P.R + 0.59 * P.G + 0.11 * P.B);
// Gray := (P.R shr 2) + (P.R shr 4) + (P.G shr 1) + (P.G shr 4) + (P.B shr 3);
P.R := Gray;
P.G := Gray;
P.B := Gray;
Inc(P);
end;
end;
end;