以下代码用于对pf1bit的图像进行翻转,其中有这样2句注释的话:
// Unclear why this must follow width/height to work correctly.
// If PixelFormat precedes width/height, bitmap will always be black.
我不太明白是什么意思,而且运行时当连续翻转图像2次以上时(点击翻转一次没问题,连着点击2次或以上时),出现image里的图像全部变黑的情况,这是为什么呢?如果去掉Palette := ImageBits.Picture.Bitmap.Palette这句,或者在Palette := ImageBits.Picture.Bitmap.Palette句后增加Bitmap.savetofile('\1.bmp')这句,运行就不会出现图像全部变黑的情况,这又是为什么呢? procedure TFormPf1bit.ButtonInvertClick(Sender: TObject);
VAR
Bitmap: TBitmap;
i: INTEGER;
j: INTEGER;
RowIn : pByteArray;
RowOut: pByteArray;
begin
Bitmap := TBitmap.Create;
TRY
WITH Bitmap DO
BEGIN
Width := ImageBits.Picture.Bitmap.Width;
Height := ImageBits.Picture.Bitmap.Height; // Unclear why this must follow width/height to work correctly.
// If PixelFormat precedes width/height, bitmap will always be black.
PixelFormat := pf1bit;
Palette := ImageBits.Picture.Bitmap.Palette
END; FOR j := 0 TO Bitmap.Height-1 DO
BEGIN
RowOut := pByteArray(Bitmap.Scanline[j]);
RowIn := pByteArray(ImageBits.Picture.Bitmap.Scanline[j]);
FOR i := 0 TO (Bitmap.Width DIV BitsPerPixel)-1 DO
BEGIN
RowOut[i] := NOT RowIn[i]
END
END; ImageBits.Picture.Graphic := Bitmap
FINALLY
Bitmap.Free
END;
end;
// Unclear why this must follow width/height to work correctly.
// If PixelFormat precedes width/height, bitmap will always be black.
我不太明白是什么意思,而且运行时当连续翻转图像2次以上时(点击翻转一次没问题,连着点击2次或以上时),出现image里的图像全部变黑的情况,这是为什么呢?如果去掉Palette := ImageBits.Picture.Bitmap.Palette这句,或者在Palette := ImageBits.Picture.Bitmap.Palette句后增加Bitmap.savetofile('\1.bmp')这句,运行就不会出现图像全部变黑的情况,这又是为什么呢? procedure TFormPf1bit.ButtonInvertClick(Sender: TObject);
VAR
Bitmap: TBitmap;
i: INTEGER;
j: INTEGER;
RowIn : pByteArray;
RowOut: pByteArray;
begin
Bitmap := TBitmap.Create;
TRY
WITH Bitmap DO
BEGIN
Width := ImageBits.Picture.Bitmap.Width;
Height := ImageBits.Picture.Bitmap.Height; // Unclear why this must follow width/height to work correctly.
// If PixelFormat precedes width/height, bitmap will always be black.
PixelFormat := pf1bit;
Palette := ImageBits.Picture.Bitmap.Palette
END; FOR j := 0 TO Bitmap.Height-1 DO
BEGIN
RowOut := pByteArray(Bitmap.Scanline[j]);
RowIn := pByteArray(ImageBits.Picture.Bitmap.Scanline[j]);
FOR i := 0 TO (Bitmap.Width DIV BitsPerPixel)-1 DO
BEGIN
RowOut[i] := NOT RowIn[i]
END
END; ImageBits.Picture.Graphic := Bitmap
FINALLY
Bitmap.Free
END;
end;
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货