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.
有问题,其他的代码都是一些很普通的,我调试过是没问题的
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.