scan line index out of range?是什么错误 ( 积分: 100 )

  • 主题发起人 主题发起人 freeloader
  • 开始时间 开始时间
F

freeloader

Unregistered / Unconfirmed
GUEST, unregistred user!
我在对两个bmp图片进行透明处理时出现的错误.
我的代码如下:
procedure TfrmMain.BlendBmp(BmpFrom, BmpTo: TBitmap; var Bmp: TBitmap;
BlendValue: Byte);
var
I, J:Integer;
P, PFrom, PTo:PByteArray;
Value:Byte;
begin
BmpFrom.PixelFormat:=pf24bit;
BmpTo.PixelFormat:=pf24bit;
Bmp.PixelFormat:=pf24Bit;
for J:=0 to Bmp.Height - 1 do
begin
P:=Bmp.ScanLine[J];
PFrom:=BmpFrom.ScanLine[J];
PTo:=BmpTo.ScanLine[J];
for I:=0 to Bmp.Width * 3 - 1 do
P:=PFrom * (255 - BlendValue) div 255 + PTo * BlendValue div 255;
end;
end;
那位大哥请指导以下
 
我在对两个bmp图片进行透明处理时出现的错误.
我的代码如下:
procedure TfrmMain.BlendBmp(BmpFrom, BmpTo: TBitmap; var Bmp: TBitmap;
BlendValue: Byte);
var
I, J:Integer;
P, PFrom, PTo:PByteArray;
Value:Byte;
begin
BmpFrom.PixelFormat:=pf24bit;
BmpTo.PixelFormat:=pf24bit;
Bmp.PixelFormat:=pf24Bit;
for J:=0 to Bmp.Height - 1 do
begin
P:=Bmp.ScanLine[J];
PFrom:=BmpFrom.ScanLine[J];
PTo:=BmpTo.ScanLine[J];
for I:=0 to Bmp.Width * 3 - 1 do
P:=PFrom * (255 - BlendValue) div 255 + PTo * BlendValue div 255;
end;
end;
那位大哥请指导以下
 
超出范围了,这几个图的大小不同
 
,[j]越界了
 
怎么解决????
 
为什么在用jpg时没错,在bmp是报错
 
加以下几句,就可以了
BmpFrom.PixelFormat:=pf24bit;
BmpTo.PixelFormat:=pf24bit;
Bmp.PixelFormat:=pf24Bit;
<----------------------------
bmpfrom.width:=?你图片的宽度;bmpfrom.height:=?你图片的高度;
bmpto 同上
bmp 同上
<----------------------------
for J:=0 to Bmp.Height - 1 do
 
还有你的jpg图有没有转换成BMP?
 
转了,我现在试试
 
to 3333w:不行呀!我的代码如下帮看看
unit MainFrm;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, ExtCtrls, CommCtrl, StdCtrls, jpeg;

type
TfrmMain = class(TForm)
Image: TImage;
ImgMM: TImage;
TrackBar: TTrackBar;
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure TrackBarChange(Sender: TObject);
private
BmpImage:TBitmap;
BmpMM:TBitmap;
procedure BlendBmp(BmpFrom, BmpTo:TBitmap; var Bmp:TBitmap;
BlendValue:Byte = 255);
public
{ Public declarations }
end;

var
frmMain: TfrmMain;

implementation

{$R *.dfm}

{ TfrmMain }

procedure TfrmMain.BlendBmp(BmpFrom, BmpTo: TBitmap; var Bmp: TBitmap;
BlendValue: Byte);
var
I, J:Integer;
P, PFrom, PTo:PByteArray;
Value:Byte;
begin
BmpFrom.PixelFormat:=pf24bit;
BmpTo.PixelFormat:=pf24bit;
Bmp.PixelFormat:=pf24Bit;
bmp.Width:=image.Width;
bmp.Height:=image.Height;
bmpto.Height:=imgmm.Height;
bmpto.Width:=imgmm.Width;
bmpfrom.width:=image.Width;
BmpFrom.Height:=image.Height;

for J:=0 to Bmp.Height - 1 do
begin
P:=Bmp.ScanLine[J];
PFrom:=BmpFrom.ScanLine[J];
PTo:=BmpTo.ScanLine[J];
for I:=0 to Bmp.Width * 3 - 1 do
P:=PFrom * (255 - BlendValue) div 255 + PTo * BlendValue div 255;
end;
end;


procedure TfrmMain.FormCreate(Sender: TObject);
begin
BmpImage:=TBitmap.Create;
BmpImage.Assign(Image.Picture.Graphic);
BmpMM:=TBitmap.Create;
BmpMM.Assign(ImgMM.Picture.Graphic);
ImgMM.Picture.Assign(nil);
Image.Picture.Assign(BmpImage);
end;

procedure TfrmMain.FormDestroy(Sender: TObject);
begin
BmpImage.Free;
BmpMM.Free;
end;

procedure TfrmMain.TrackBarChange(Sender: TObject);
var
Bmp:TBitmap;
begin
Bmp:=Image.Picture.Bitmap;
BlendBmp(BmpImage,BmpMM,Bmp,TrackBar.Position);
Image.Refresh;
end;

end.
 
三个图片高宽必须一致
 
to 3333w:是图片一至,还是image一致
 
bitmap一致
bmpto.Height:=imgmm.Height;
bmpto.Width:=imgmm.Width;
改成
bmpto.Height:=image.Height;
bmpto.Width:=image.Width;
 
to :
图片放大了
 
接受答案了.
 
后退
顶部