小弟请教一图像问题 ( 积分: 50 )

  • 主题发起人 主题发起人 ghostxp007
  • 开始时间 开始时间
G

ghostxp007

Unregistered / Unconfirmed
GUEST, unregistred user!
程序代码如下,希望能得到模糊的效果,望各位帮帮忙看看,为什么会恢复成原来的样子?
谢谢了先!

unit Unit2;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtDlgs, ExtCtrls, StdCtrls,jpeg,math;

type
TForm1 = class(TForm)
Button1: TButton;
Image1: TImage;
Button2: TButton;
OpenPictureDialog1: TOpenPictureDialog;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
openpicturedialog1.Execute;
image1.Picture.LoadFromFile(openpicturedialog1.FileName);
end;

procedure TForm1.Button2Click(Sender: TObject);
var
x,y:integer;
p:pbytearray;
bmp:tbitmap;


begin

bmp:=tbitmap.Create;
bmp.Assign(image1.Picture.Graphic);
for y:=0 to bmp.Height-1 do
begin
p:=bmp.ScanLine[y];
for x:=0 to bmp.Width -1 do
begin
canvas.Pixels[x,y]:=canvas.Pixels[x+random(10),y+random(10)];

end;

end;
image1.Picture.Bitmap.Assign(bmp);
end;
end.
 
canvas.Pixels[x,y]:=canvas.Pixels[x+random(10),y+random(10)];
问题在这句,canvas是image的,所以修改的像素是image的而不是bmp的,你最后image1.Picture.Bitmap.Assign(bmp);造成图像修改了但马上又改回来了。

去掉image1.Picture.Bitmap.Assign(bmp);就行了
 
问题已经解决,谢谢!!
 

Similar threads

I
回复
0
查看
733
import
I
I
回复
0
查看
409
import
I
I
回复
0
查看
588
import
I
I
回复
0
查看
589
import
I
后退
顶部