急!图片合并问题!!请你帮忙了! ( 积分: 100 )

  • 主题发起人 主题发起人 handll
  • 开始时间 开始时间
H

handll

Unregistered / Unconfirmed
GUEST, unregistred user!
我需要一个图片合并过程,这是我的实现过程,但提示“Bitmap image is not valid”的错误提示,是怎么回事呢?你有解决方法么?
注: 过程功能 是把picpath1 和 picPath2路径的图片纵向合并为新的图片路径picPath
必须(或最好)在一个过程内完成此功能
procedure Bind(picPath1 : string; picPath2 : string; picPath: string);
var
myrect1 : TRect;
myrect2 : TRect;
bmps,bmp1,bmp2 : TBitmap;

begin
bmps := TBitmap.Create;
bmp1 := TBitmap.Create;
bmp2 := TBitmap.Create;
bmp1.LoadFromFile(picPath1);
bmp2.LoadFromFile(picPath2);

bmps.Height := bmp1.Height + bmp2.Height;
myrect1 := Rect(0,0,bmp1.Width,bmp1.Height);
myrect2 := Rect(0,bmp1.Height,bmp2.Width,bmp1.Height + bmp2.Height);
bmps.Canvas.StretchDraw(myrect1,bmp1);
bmps.Canvas.StretchDraw(myrect2,bmp2);
bmps.SaveToFile(picPath);
end;

谢谢你的过目!!
 
我需要一个图片合并过程,这是我的实现过程,但提示“Bitmap image is not valid”的错误提示,是怎么回事呢?你有解决方法么?
注: 过程功能 是把picpath1 和 picPath2路径的图片纵向合并为新的图片路径picPath
必须(或最好)在一个过程内完成此功能
procedure Bind(picPath1 : string; picPath2 : string; picPath: string);
var
myrect1 : TRect;
myrect2 : TRect;
bmps,bmp1,bmp2 : TBitmap;

begin
bmps := TBitmap.Create;
bmp1 := TBitmap.Create;
bmp2 := TBitmap.Create;
bmp1.LoadFromFile(picPath1);
bmp2.LoadFromFile(picPath2);

bmps.Height := bmp1.Height + bmp2.Height;
myrect1 := Rect(0,0,bmp1.Width,bmp1.Height);
myrect2 := Rect(0,bmp1.Height,bmp2.Width,bmp1.Height + bmp2.Height);
bmps.Canvas.StretchDraw(myrect1,bmp1);
bmps.Canvas.StretchDraw(myrect2,bmp2);
bmps.SaveToFile(picPath);
end;

谢谢你的过目!!
 
1。bmps.Width你没定义大小,导致bmps是空的,保存成的文件大小为0
2。bmps.Free ;资源没有释放
bmp1.Free ;
bmp2.Free;
 
这样的合并你最好还是用直接文件操作的方式
查一查BMP文件的结构很好做的
文件头
位图头
调色板
位图数据
好象是这样的结构,我记不太清了。
 
var
myrect1 : TRect;
myrect2 : TRect;
bmps,bmp1,bmp2 : TBitmap;

begin
bmps := TBitmap.Create;
bmp1 := TBitmap.Create;
bmp2 := TBitmap.Create;
self.DoubleBuffered := True;

bmp1.LoadFromFile('F:/picture/MM1/01.jpg');
bmp2.LoadFromFile('F:/picture/MM1/02.jpg');

bmps.Height := bmp1.Height + bmp2.Height;
bmps.Width := bmp1.Width;
myrect1 := Rect(0,0,bmp1.Width,bmp1.Height);
myrect2 := Rect(0,bmp1.Height,bmp2.Width,bmp1.Height + bmp2.Height);
bmps.Canvas.StretchDraw(myrect1,bmp1);
bmps.Canvas.StretchDraw(myrect2,bmp2);
bmps.SaveToFile('c:/aa.jpg');
bmp1.Free;
bmp2.Free;
bmps.Free;
这是我程序中的一个片段,按“啊啊啊啊啊”朋友的提示改过后问题依然。看来不是那的问题,诸位还有解数么?
 
晕。你这是jpeg文件不是bmp文件
Jpeg文件你用TBitmap类来操作当然会出问题了。。
 
将代码改成如下
var
myrect1 : TRect;
myrect2 : TRect;
bmp1,bmp2 : TJPEGImage;
bmps : TBitmap;
ResultJpg : TJPEGImage;
begin
bmps := TBitmap.Create;
bmp1 := TJPEGImage.Create;
bmp2 := TJPEGImage.Create;
ResultJpg := TJPEGImage.Create ;
self.DoubleBuffered := True;

bmp1.LoadFromFile('d:/9.jpg');
bmp2.LoadFromFile('d:/22.jpg');

bmps.Height := bmp1.Height + bmp2.Height;
bmps.Width := bmp1.Width;
myrect1 := Rect(0,0,bmp1.Width,bmp1.Height);
myrect2 := Rect(0,bmp1.Height,bmp2.Width,bmp1.Height + bmp2.Height);

bmps.Canvas.StretchDraw(myrect1,bmp1);
bmps.Canvas.StretchDraw(myrect2,bmp2);
{以下是重点,不能用bmps.SaveToFile('c:/aa.jpg')
那样文件还是bmp格式的,大小与jpg不一样}
ResultJpg.Assign(bmps);
ResultJpg.SaveToFile('c:/aa.jpg');
ResultJpg.Free ;
bmp1.Free;
bmp2.Free;
bmps.Free;
 
后退
顶部