我的24位图像宽320,高240(象素)。
现在我只想取出这个图像的最右边的图片,宽度20个象素。也就是说,我要新生成的图片是20个宽,240个高,是原图像最右边的部分。
以下是我编写的代码:
procedure TForm1.Button4Click(Sender: TObject);
var
BitMap,bmCentre : TBitMap;
p1,p2 : PByteArray;
x,y,nXB: integer;
begin
BitMap := TBitmap.Create;
bmCentre := TBitmap.Create;
try
begin
BitMap.LoadFromFile('E:\BiowayUrine\image\sss.bmp');
//
bmCentre.Width := StrToInt(Edit1.Text);
bmCentre.Height := BitMap.Height;
bmCentre.PixelFormat := pf24bit; nXB := Bitmap.Width - bmCentre.Width;
//CopyMemory(DataPoint,VideoStr^.lpData,Diblen);
for y := 0 to bmCentre.Height - 1 do
begin
p1 := BitMap.ScanLine[y];
p2 := bmCentre.ScanLine[y]; for x := 0 to bmCentre.Width * 3 - 1 do
begin
p2[x] := p1[x];
end;
end;
bmCentre.SaveToFile('E:\BiowayUrine\image\bottom.bmp');
end
finally
BitMap.Free;
bmCentre.Free;
end;
end;其中edit1是输入的新图像的宽度,也就是说可以是20,也可能是320,看输入。
执行这段代码后,保存的图片不对!!!!特来向大家请教。
第一次做和图片有关的程序,比较迷茫!
现在我只想取出这个图像的最右边的图片,宽度20个象素。也就是说,我要新生成的图片是20个宽,240个高,是原图像最右边的部分。
以下是我编写的代码:
procedure TForm1.Button4Click(Sender: TObject);
var
BitMap,bmCentre : TBitMap;
p1,p2 : PByteArray;
x,y,nXB: integer;
begin
BitMap := TBitmap.Create;
bmCentre := TBitmap.Create;
try
begin
BitMap.LoadFromFile('E:\BiowayUrine\image\sss.bmp');
//
bmCentre.Width := StrToInt(Edit1.Text);
bmCentre.Height := BitMap.Height;
bmCentre.PixelFormat := pf24bit; nXB := Bitmap.Width - bmCentre.Width;
//CopyMemory(DataPoint,VideoStr^.lpData,Diblen);
for y := 0 to bmCentre.Height - 1 do
begin
p1 := BitMap.ScanLine[y];
p2 := bmCentre.ScanLine[y]; for x := 0 to bmCentre.Width * 3 - 1 do
begin
p2[x] := p1[x];
end;
end;
bmCentre.SaveToFile('E:\BiowayUrine\image\bottom.bmp');
end
finally
BitMap.Free;
bmCentre.Free;
end;
end;其中edit1是输入的新图像的宽度,也就是说可以是20,也可能是320,看输入。
执行这段代码后,保存的图片不对!!!!特来向大家请教。
第一次做和图片有关的程序,比较迷茫!
解决方案 »
- dbgrideh表中表RowDetailPanel如何设置对应的字段关联呀
- 使用Adodataset的疑问
- form大小
- 这种功能怎样做,晚上9点准时结所有的贴子。
- ADO的臭虫、问题太多,只好用BDE了
- 我做了个chm的帮助文件,怎样把他加到程序中去呢?
- 在DELPHI中要使用API函数如OPENPRINTER,WRITEPINTER如何用?我一用就说未说明。。。
- 问个难以启齿的简单问题!Dbgrideh的打印问题
- 请大家一定帮帮我,谢谢……我只有82分,关于剪贴板和Memo的问题!!!!!!
- 在应用程序中怎么样设置应用程序所使用的字体(字库)路径.在delphi里可以设置memo的字体.但是用的是font目录下的字体.我要让memo控件用当前目录下的某个ttf文件来输文本,分数没问题
- [关于菜单的问题]今天在写程序的时候,偶然看到菜单可以从MNU导入
- delphi txt 操作问题。
Graphics::TBitmap *Bitmap = new Graphics::TBitmap;
Bitmap->LoadFromFile("earth.bmp"); byte *Pixels = new byte[Bitmap->Width * Bitmap->Height *3 ]; long temp;
for (long i=0; i<Bitmap->Height; i++) //读像素数据
{
for (long j=0; j<Bitmap->Width; j++)
{
temp=i* Bitmap->Width * 3+ j * 3;
Pixels[temp+0] =
GetRValue(Bitmap->Canvas->Pixels[j][Bitmap->Height-i-1]);
Pixels[temp+1] =
GetGValue(Bitmap->Canvas->Pixels[j][Bitmap->Height-i-1]);
Pixels[temp+2] =
GetBValue(Bitmap->Canvas->Pixels[j][Bitmap->Height-i-1]);
}
}你把循环区域改成你需要的区域。
不过我会试一下,谢谢!