一些图象处理的功能,我编了第一个,怎么实现不了?代码也有,在下面 (100分)

  • 主题发起人 主题发起人 lemon3
  • 开始时间 开始时间
L

lemon3

Unregistered / Unconfirmed
GUEST, unregistred user!
主要是那个获取颜色的getrgbp和那个颜色重新设置的过程

有问题,其他的代码都是一些很普通的,我调试过是没问题的

unit round;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, ExtDlgs, Menus;
type
rgbp=record
r:integer;
g:integer;
b:integer;
end;
type
Tform2 = class(TForm)
Image1: TImage;
Image2: TImage;
Image3: TImage;
Image4: TImage;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
MainMenu1: TMainMenu;
N1: TMenuItem;
N2: TMenuItem;
OpenDialog1: TOpenDialog;
N3: TMenuItem;
N4: TMenuItem;
SavePictureDialog1: TSavePictureDialog;
N5: TMenuItem;
N6: TMenuItem;
Image5: TImage;
Image6: TImage;
N121: TMenuItem;
procedure getrgbp(sender:tobject);
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure OpenDialog1IncludeItem(const OFN: TOFNotifyEx;
var Include: Boolean);
procedure N2Click(Sender: TObject);
procedure OpenDialog1Show(Sender: TObject);
procedure N3Click(Sender: TObject);
procedure N4Click(Sender: TObject);
procedure N6Click(Sender: TObject);
procedure N121Click(Sender: TObject);
procedure FormCreate(Sender: TObject);


private
{ Private declarations }
public
{ Public declarations }
end;
var
form2 : Tform2;
x:integer;
xx:integer;
y:integer;
yy:integer;
i:integer;
j:integer;
mybitmap:tbitmap;
rgbpoint:array[0..1000,0..1000] of rgbp;

implementation

{$R *.dfm}

//原图放在image1里面
//显示得图片放在image5里面
//2,3,4用来做转换,里面实际有图形,但是不显示
procedure Tform2.Button2Click(Sender: TObject);
var
i,j:integer;
begin
//image1.Visible:=true;
//image3.Visible:=false;
//image4.Visible:=false;
image2.Picture.Bitmap.Height:=image1.Picture.Width;
image2.Picture.Bitmap.Width:=image1.Picture.Height;
for i:=0 to image1.Height do
for j:=0 to image1.Width do
image2.Canvas.Pixels[(-i+image1.Height),j]:=image1.Canvas.Pixels[j,i];
//image2.Visible:=true;
image5.Picture:=image2.Picture;

end;

procedure Tform2.Button1Click(Sender: TObject);
begin
//image2.Visible:=false;
//image3.Visible:=false;
//image4.Visible:=false;
image5.Picture:=image1.Picture;

end;

procedure Tform2.Button3Click(Sender: TObject);
var
i,j:integer;
begin
//image1.Visible:=false;
//image2.Visible:=false;
//image4.Visible:=false;
//image3.Picture.Bitmap.Height:=image1.Picture.Height;
image2.Picture.Bitmap.Width:=image1.Picture.Width;
for i:=0 to image1.Height do
for j:=0 to image1.Width do
image2.Canvas.Pixels[(image1.Width-j),(image1.Height-i)]:=image1.Canvas.Pixels[j,i];
image5.Picture:=image2.Picture;
end;


procedure Tform2.Button4Click(Sender: TObject);
var
i,j:integer;
begin
//image1.Visible:=false;
//image2.Visible:=false;
//image3.Visible:=false;
image2.Picture.Bitmap.Height:=image1.Picture.Height;
image2.Picture.Bitmap.Width:=image1.Picture.Width;
for i:=0 to image1.Height do
for j:=0 to image1.Width do
image2.Canvas.Pixels[i,(image1.Width-j)]:=image1.Canvas.Pixels[j,i];
image5.Picture:=image2.Picture;
end;


procedure Tform2.OpenDialog1IncludeItem(const OFN: TOFNotifyEx;
var Include: Boolean);
begin
image1.Picture.LoadFromFile(opendialog1.FileName);
end;

procedure Tform2.N2Click(Sender: TObject);
var
filename:ansistring;
color:tcolor;
begin
if(opendialog1.Execute)then
begin
filename:=opendialog1.FileName;
image1.Picture.LoadFromFile(filename);
image6.Picture.LoadFromFile(filename);
x:=image1.Picture.Width;
y:=image1.Picture.Height;
xx:=x-1;
yy:=y-1;
for i:=0 to xx do
begin
for j:=0 to yy do
begin
color:=image1.Canvas.Pixels[i,j];
rgbpoint[i,j].r:=getrvalue(color);
rgbpoint[i,j].g:=getgvalue(color);
rgbpoint[i,j].b:=getbvalue(color);
end;
//
mybitmap:=tbitmap.Create();
mybitmap.Width:=image1.Picture.Width;
mybitmap.Height:=image1.Picture.Height;
end;

end;
end;

procedure Tform2.OpenDialog1Show(Sender: TObject);
begin
{image1.Picture.LoadFromFile(opendialog1.FileName); }
end;

{保存}
procedure Tform2.N3Click(Sender: TObject);
var
filename:ansistring;
begin
if savepicturedialog1.Execute() then
begin
filename:=savepicturedialog1.FileName;
savepicturedialog1.DefaultExt:='.bmp';
// if image2.Visible=true then
image5.Picture.SaveToFile(filename);
// if image3.visible=true then
//image3.Picture.SaveToFile(filename);
//if image4.Visible=true then
//image4.Picture.SaveToFile(filename);
//if image1.Visible=true then
//image1.Picture.SaveToFile(filename);
end;
end;

procedure Tform2.N4Click(Sender: TObject);
begin
close();
end;

procedure tform2.getrgbp(sender:tobject);
var
color:tcolor;
begin
x:=image1.Picture.Width;
xx:=x-1;
y:=image1.Picture.Height;
yy:=y-1;
for i:=0 to xx do
begin
for j:=0 to yy do
begin
color:=image1.Canvas.Pixels[i,j];
rgbpoint[i,j].r:=getrvalue(color);
rgbpoint[i,j].g:=getgvalue(color);
rgbpoint[i,j].b:=getbvalue(color);
end;
end;
end;


{procedure Tform2.N6Click(Sender: TObject);
var
red:integer;
green:integer;
blue:integer;
begin
image1.Picture.Bitmap.Assign(image5.Picture.Bitmap);
getrgbp(sender);
for i:=1 to x-2 do
begin
for j:=1 to y-2 do
begin
red:=rgbpoint[i-1,j-1].
end;}

procedure Tform2.N6Click(Sender: TObject);
var
red:integer;
green:integer;
blue:integer;
begin
image6.Picture.Bitmap.Assign(image1.Picture.Bitmap);
getrgbp(sender);
xx:=x-2;
yy:=y-2;
for i:=1 to xx do
begin
for j:=1 to yy do
begin
red:=rgbpoint[i-1,j-1].r+rgbpoint[i-1,j].r+rgbpoint[i-1,j+1].r+
rgbpoint[i,j-1].r+rgbpoint[i,j].r+rgbpoint[i,j+1].r+
rgbpoint[i+1,j-1].r+rgbpoint[i+1,j].r+rgbpoint[i+1,j+1].r;
green:=rgbpoint[i-1,j-1].g+rgbpoint[i-1,j].g+rgbpoint[i-1,j+1].g+
rgbpoint[i,j-1].g+rgbpoint[i,j].g+rgbpoint[i,j+1].g+
rgbpoint[i+1,j-1].g+rgbpoint[i+1,j].g+rgbpoint[i+1,j+1].g;
blue:=rgbpoint[i-1,j-1].b+rgbpoint[i-1,j].b+rgbpoint[i-1,j+1].b+
rgbpoint[i,j-1].b+rgbpoint[i,j].b+rgbpoint[i,j+1].b+
rgbpoint[i+1,j-1].b+rgbpoint[i+1,j].b+rgbpoint[i+1,j+1].b;
mybitmap.Canvas.Pixels[i,j]:=rgb(red div 9,green div 9,blue div 9);
end;
end;
image6.Picture.Bitmap.Assign(mybitmap);
end;

procedure Tform2.N121Click(Sender: TObject);
var
red,green,blue:integer;
begin
image6.Picture.Bitmap.Assign(image1.Picture.Bitmap);
getrgbp(sender);
i:=1;
while(i<x-1) do
begin
j:=1;
while(j<y-1) do
begin
red:=rgbpoint[i,j].r;
green:=rgbpoint[i,j].g;
blue:=rgbpoint[i,j].b;
mybitmap.Canvas.Pixels[i,j]:=rgb(red,green,blue);
mybitmap.Canvas.Pixels[i,j+1]:=rgb(red,green,blue);
mybitmap.Canvas.Pixels[i+1,j]:=rgb(red,green,blue);
mybitmap.Canvas.Pixels[i+1,j+1]:=rgb(red,green,blue);
j:=j+2;
end;
i:=i+2;
end;
image6.Picture.Bitmap.Assign(mybitmap);


end;

procedure Tform2.FormCreate(Sender: TObject);
begin

end;

end.
 
把你的关键代码列出来就可以了
哪里的错,什么错误呢
 
我看晕了
 
procedure tform2.getrgbp(sender:tobject);
var
color:tcolor;
begin
x:=image1.Picture.Width;
xx:=x-1;
y:=image1.Picture.Height;
yy:=y-1;
for i:=0 to xx do
begin
for j:=0 to yy do
begin
color:=image1.Canvas.Pixels[i,j];
rgbpoint[i,j].r:=getrvalue(color);
rgbpoint[i,j].g:=getgvalue(color);
rgbpoint[i,j].b:=getbvalue(color);
end;
end;
end;

procedure Tform2.N6Click(Sender: TObject);
var
red:integer;
green:integer;
blue:integer;
begin
image6.Picture.Bitmap.Assign(image1.Picture.Bitmap);
getrgbp(sender);
xx:=x-2;
yy:=y-2;
for i:=1 to xx do
begin
for j:=1 to yy do
begin
red:=rgbpoint[i-1,j-1].r+rgbpoint[i-1,j].r+rgbpoint[i-1,j+1].r+
rgbpoint[i,j-1].r+rgbpoint[i,j].r+rgbpoint[i,j+1].r+
rgbpoint[i+1,j-1].r+rgbpoint[i+1,j].r+rgbpoint[i+1,j+1].r;
green:=rgbpoint[i-1,j-1].g+rgbpoint[i-1,j].g+rgbpoint[i-1,j+1].g+
rgbpoint[i,j-1].g+rgbpoint[i,j].g+rgbpoint[i,j+1].g+
rgbpoint[i+1,j-1].g+rgbpoint[i+1,j].g+rgbpoint[i+1,j+1].g;
blue:=rgbpoint[i-1,j-1].b+rgbpoint[i-1,j].b+rgbpoint[i-1,j+1].b+
rgbpoint[i,j-1].b+rgbpoint[i,j].b+rgbpoint[i,j+1].b+
rgbpoint[i+1,j-1].b+rgbpoint[i+1,j].b+rgbpoint[i+1,j+1].b;
mybitmap.Canvas.Pixels[i,j]:=rgb(red div 9,green div 9,blue div 9);
end;
end;
image6.Picture.Bitmap.Assign(mybitmap);
end;
这两个过程应该是关键

前面定义也可以看看

好像是很严重的错误,就是说关掉delphi才可以重新来,不是普通的那种调试错误

会是前面那数组太大了,说实话,这段程序是我看书上的

但是算法的大概我理解了啊,就是取颜色的平均值嘛

只是有些函数我找参考也麻烦,但执行开始它并没有报错啊
 
关键代码:)

我没想到这个论坛人气这么旺啊,看来以后要多上

今天我第一次上:)

有同济的吗?
 
跟踪一下∶
procedure tform2.getrgbp(sender:tobject);
var
color:tcolor;
begin
x:=image1.Picture.Width;
xx:=x-1;
y:=image1.Picture.Height;
yy:=y-1;
。。。
end;
看xx*yy是否>1000*1000

 
我想不会超过的吧,那个位图图象很小的啊

整个屏幕的分辨率才1024*768,应该不会超过1000*1000啊

不超过就应该没问题吧
 
会是那种图片格式什么的问题吗?

位图是不是都一样的?
 
问题在下面

procedure Tform2.N2Click(Sender: TObject);
var
filename:ansistring;
color:tcolor;
begin
if(opendialog1.Execute)then
begin
filename:=opendialog1.FileName;
image1.Picture.LoadFromFile(filename);
image6.Picture.LoadFromFile(filename);
x:=image1.Picture.Width;
y:=image1.Picture.Height;
xx:=x-1;
yy:=y-1;
for i:=0 to xx do
begin
for j:=0 to yy do
begin
color:=image1.Canvas.Pixels[i,j];
rgbpoint[i,j].r:=getrvalue(color);
rgbpoint[i,j].g:=getgvalue(color);
rgbpoint[i,j].b:=getbvalue(color);
end;
//
mybitmap:=tbitmap.Create(); // mybitmap被创建了XX次
mybitmap.Width:=image1.Picture.Width; // 而且每次都有这么大
mybitmap.Height:=image1.Picture.Height; // 你的机器有多少内存? :)
end;

end;
end;
 
用 Canvas.Pixels 来做图象处理? 太慢了

为什么不用 Scanline?
 
恩,我想也应该是这样的,可惜现在都改过来了:)没有用mybitmap
多谢了:)
 
后退
顶部