诚征 图象 显示特效 资料

microluck 2002-11-23 02:50:15
就是储如 百页窗,扫描,旋转等各种效果的源码,资料之类.
希望各位大虾帮忙!

我可以给很多分,只是一次给不了:(
可以多开几贴给分.
...全文
65 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
Inf 2002-12-03
  • 打赏
  • 举报
回复
灰度级处理
procedure Gray(bmp: TBitmap);
var
p: PByteArray;
w: Integer;
i, j: Integer;
begin
bmp.pixelformat := pf24bit;
for i := 0 to bmp.height - 1 do
begin
p := bmp.scanline[i];
j := 0;
while j < (bmp.width-1) * 3 do
begin
w :=(p[j] * 28 + p[j+1] * 151 + p[j+2]*77);
w := w shr 8;
p[j] := byte(w);
p[j+1] := byte(w);
p[j+2] := byte(w);
inc(j, 3)
end;
end;
end;
HOOK_TTG 2002-12-03
  • 打赏
  • 举报
回复
//这个是图片翻转的
//说了这么多,总的给点分吧!!
Procedure Flip1Click(Sender: TObject);

Var
DummyImage : TImage;
X,Y : Integer;
SrcRect,DstRect : TRect;

Begin
X := Image1.Picture.Width;
Y := Image1.Picture.Height;
SrcRect := Rect(0,0,X,Y);
DstRect := Rect(X,0,0,Y);
DummyImage := TImage.Create(Self);
DummyImage.Width := X;
DummyImage.Height := Y;
//DummyImage.Canvas.CopyMode := cmSrcCopy
DummyImage.Canvas.CopyRect(DstRect,Image1.Canvas,SrcRect);
//Flipping the image
Image1.Picture := DummyImage.Picture;
//Copy the flipped image to Image1
DummyImage.Free;
end.
Inf 2002-12-03
  • 打赏
  • 举报
回复
图象扭曲算法 :
procedure Twist(var Bmp, Dst: TBitmap; Amount: integer);
var
fxmid, fymid : Single;
txmid, tymid : Single;
fx,fy : Single;
tx2, ty2 : Single;
r : Single;
theta : Single;
ifx, ify : integer;
dx, dy : Single;
OFFSET : Single;
ty, tx : Integer;
weight_x, weight_y : array[0..1] of Single;
weight : Single;
new_red, new_green : Integer;
new_blue : Integer;
total_red, total_green : Single;
total_blue : Single;
ix, iy : Integer;
sli, slo : PBytearray;

function ArcTan2(xt,yt : Single): Single;
begin
if xt = 0 then
if yt > 0 then
Result := Pi/2
else
Result := -(Pi/2)
else begin
Result := ArcTan(yt/xt);
if xt < 0 then
Result := Pi + ArcTan(yt/xt);
end;
end;

begin
OFFSET := -(Pi/2);
dx := Bmp.Width - 1;
dy := Bmp.Height - 1;
r := Sqrt(dx * dx + dy * dy);
tx2 := r;
ty2 := r;
txmid := (Bmp.Width-1)/2; //Adjust these to move center of rotation
tymid := (Bmp.Height-1)/2; //Adjust these to move ......
fxmid := (Bmp.Width-1)/2;
fymid := (Bmp.Height-1)/2;
if tx2 >= Bmp.Width then tx2 := Bmp.Width-1;
if ty2 >= Bmp.Height then ty2 := Bmp.Height-1;

for ty := 0 to Round(ty2) do begin
for tx := 0 to Round(tx2) do begin
dx := tx - txmid;
dy := ty - tymid;
r := Sqrt(dx * dx + dy * dy);
if r = 0 then begin
fx := 0;
fy := 0;
end
else begin
theta := ArcTan2(dx,dy) - r/Amount - OFFSET;
fx := r * Cos(theta);
fy := r * Sin(theta);
end;
fx := fx + fxmid;
fy := fy + fymid;

ify := Trunc(fy);
ifx := Trunc(fx);
// Calculate the weights.
if fy >= 0 then begin
weight_y[1] := fy - ify;
weight_y[0] := 1 - weight_y[1];
end else begin
weight_y[0] := -(fy - ify);
weight_y[1] := 1 - weight_y[0];
end;
if fx >= 0 then begin
weight_x[1] := fx - ifx;
weight_x[0] := 1 - weight_x[1];
end else begin
weight_x[0] := -(fx - ifx);
Weight_x[1] := 1 - weight_x[0];
end;

if ifx < 0 then
ifx := Bmp.Width-1-(-ifx mod Bmp.Width)
else if ifx > Bmp.Width-1 then
ifx := ifx mod Bmp.Width;
if ify < 0 then
ify := Bmp.Height-1-(-ify mod Bmp.Height)
else if ify > Bmp.Height-1 then
ify := ify mod Bmp.Height;

total_red := 0.0;
total_green := 0.0;
total_blue := 0.0;
for ix := 0 to 1 do begin
for iy := 0 to 1 do begin
if ify + iy < Bmp.Height then
sli := Bmp.scanline[ify + iy]
else
sli := Bmp.scanline[Bmp.Height - ify - iy];
if ifx + ix < Bmp.Width then begin
new_red := sli[(ifx + ix)*3];
new_green := sli[(ifx + ix)*3+1];
new_blue := sli[(ifx + ix)*3+2];
end
else begin
new_red := sli[(Bmp.Width - ifx - ix)*3];
new_green := sli[(Bmp.Width - ifx - ix)*3+1];
new_blue := sli[(Bmp.Width - ifx - ix)*3+2];
end;
weight := weight_x[ix] * weight_y[iy];
total_red := total_red + new_red * weight;
total_green := total_green + new_green * weight;
total_blue := total_blue + new_blue * weight;
end;
end;
slo := Dst.scanline[ty];
slo[tx*3] := Round(total_red);
slo[tx*3+1] := Round(total_green);
slo[tx*3+2] := Round(total_blue);
end;
end;
end;
procedure Twist(var Bmp, Dst: TBitmap; Amount: integer);
这里的Bmp为源位图,Dst为目标位图,Amount为扭曲常数,你可以定义为任意整数,例如100.
蝈蝈太阳 2002-12-03
  • 打赏
  • 举报
回复
UP
HOOK_TTG 2002-12-03
  • 打赏
  • 举报
回复
让图像旋转



--- Delphi中的Image构件可以显示位图,进一步,我们还可以用它完成位图旋转。


---- 把一个点绕原点旋转α角度后,新的坐标位置与原坐标位置的关系是:


X=xcosα-ysinα

Y= xsinα+ycosα

例如要把位图顺时针旋转90度,坐标变换公式为:X=-y Y=x


---- 把这一公式用到Image构件上,显示位图的主要问题是Image构件显示的位图只有一个象限, 并且x、y坐标也是互相颠倒的,为了解决这个问题,必须在Image构件上建立一个新的坐标原点。下面就举例说明。

---- 1. 新建一工程project1

在form1上添加image1、 image2、 image3、image4,其 Autosize属性设为True

image1用来显示原图,image2、image3、image4分别用来显示旋转90度、180度和270度后的图像。双击image1,选定一幅bmp图。


---- 2. 添加Button1、Button2、Button3和Button4按钮,其caption属性分别为“原图”、 “旋转90度”、“旋转180度”、“旋转270度”。


---- 3. 编写“旋转90度”按钮的On Click事件。


procedure TForm1. Button2Click (Sender: TObject);

var

i

j:integer;

begin

//确定旋转后位图的大小

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];

end;



---- 4. 编写“旋转180度”按钮的On Click事件。

procedure TForm1.Button3Click(Sender: TObject);

var

i

j:integer;

begin

//确定旋转后位图的大小

image3.Picture.Bitmap.Height:=image1.picture.Height;

image3.Picture.Bitmap.Width:=image1.picture.Width;

for i:=0 to image1.Height do

for j:=0 to image1.Width do

image3.canvas.Pixels[(image1.Width

-j)

(image1.Height-i)]:=image1.canvas.Pixels[j

i];

end;


---- 5. 编写“旋转270度” 按钮的On Click事件。代码和步骤3相似,只需要用image4 替换image2,然后用以下的语句替换步骤3 for循环中的原有的语句。

image4.canvas.Pixels[i

(image1.Width-j)]:=image1.canvas.Pixels[j

i];
HOOK_TTG 2002-12-03
  • 打赏
  • 举报
回复
//这是我编的演示程序,希望对你有帮助
//好的话,就给加点分吧……
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls;

type
TForm1 = class(TForm)
Image1: TImage;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
newbmp: TBitmap;
i,bmpheight,bmpwidth:integer;
begin
newbmp:= TBitmap.Create;
newbmp.Width:=image1.Width;
newbmp.Height:=image1.Height;
bmpheight:=image1.Height;
bmpwidth:=image1.Width;
for i:=0 to bmpheight do
begin
newbmp.Canvas.CopyRect(Rect
(0,bmpheight-i,bmpwidth,bmpheight),
image1.Canvas,
Rect(0,0,bmpwidth,i));
form1.Canvas.Draw(120,100,newbmp);
end;
newbmp.free;

end;

procedure TForm1.Button2Click(Sender: TObject);
var
newbmp:TBitmap;
i,j,bmpheight,bmpwidth:integer;
begin
newbmp:= TBitmap.Create;
newbmp.Width:=image1.Width;
newbmp.Height:=image1.Height;
bmpheight:=image1.Height;
bmpwidth:=image1.Width;
i:=0;
while i<=bmpheight do
begin
j:=i;
while j >0 do
begin
newbmp.Canvas.CopyRect(Rect(0,j-1,bmpwidth,j),
image1.Canvas,
Rect(0,bmpheight-i+j-1,bmpwidth,bmpheight-i+j));
newbmp.Canvas.CopyRect(Rect
(0,bmpheight-j,bmpwidth,bmpheight-j+1),
image1.Canvas,
Rect(0,i-j,bmpwidth,i-j+1));
j:=j-2;
end;
form1.Canvas.Draw(120,100,newbmp);
i:=i+2;
end;
newbmp.free;
end;

procedure TForm1.Button3Click(Sender: TObject);
var
newbmp:TBitmap;
i,j,bmpheight,bmpwidth:integer;
begin
newbmp:= TBitmap.Create;
newbmp.Width:=image1.Width;
newbmp.Height:=image1.Height;
bmpheight:=image1.Height;
bmpwidth:=image1.Width;
i:=0;
while i<=bmpwidth do
begin
j:=i;
while j >0 do
begin
newbmp.Canvas.CopyRect(Rect(j-1,0,j,bmpheight),
image1.Canvas,
Rect(bmpwidth-i+j-1,0,bmpwidth-i+j,bmpheight));
newbmp.Canvas.CopyRect(Rect
(bmpwidth-j,0,bmpwidth-j+1,bmpheight),
image1.Canvas,
Rect(i-j,0,i-j+1,bmpheight));
j:=j-2;
end;
form1.Canvas.Draw(120,100,newbmp);
i:=i+2;
end;
newbmp.free;


end;

procedure TForm1.Button4Click(Sender: TObject);
var
newbmp:TBitmap;
i,j,bmpheight,bmpwidth:integer;
begin
newbmp:= TBitmap.Create;
newbmp.Width:=image1.Width;
newbmp.Height:=image1.Height;
bmpheight:=image1.Height;
bmpwidth:=image1.Width;
for i:=bmpheight downto 1 do
for j:=1 to i do
begin
newbmp.Canvas.CopyRect(Rect(0,j-1,bmpwidth,j),
image1.Canvas,
Rect(0,i-1,bmpwidth,i));
form1.Canvas.Draw(120,100,newbmp);
end;
newbmp.free;

end;

procedure TForm1.Button5Click(Sender: TObject);
var
newbmp:TBitmap;
i,j,bmpheight,bmpwidth:integer;
xgroup,xcount:integer;
begin
newbmp:= TBitmap.Create;
newbmp.Width:=image1.Width;
newbmp.Height:=image1.Height;
bmpheight:=image1.Height;
bmpwidth:=image1.Width;
xgroup:=16;
xcount:=bmpheight div xgroup;
for i:=0 to xcount do
for j:=0 to xgroup do
begin
newbmp.Canvas.CopyRect(Rect
(0,xcount*j+i-1,bmpwidth,xcount*j+i),
image1.Canvas,
Rect(0,xcount*j+i-1,bmpwidth,xcount*j+i));
form1.Canvas.Draw(120,100,newbmp);
end;
newbmp.Free;


end;

procedure TForm1.Button6Click(Sender: TObject);
var
newbmp:TBitmap;
i,j,bmpheight,bmpwidth:integer;
begin
newbmp:= TBitmap.Create;
newbmp.Width:=image1.Width;
newbmp.Height:=image1.Height;
bmpheight:=image1.Height;
bmpwidth:=image1.Width;
i:=bmpheight;
while i>0 do
begin
for j:=10 to i do
begin
newbmp.Canvas.CopyRect(Rect(0,j-10,bmpwidth,j),
image1.Canvas,
Rect(0,i-10,bmpwidth,i));
form1.Canvas.Draw(120,100,newbmp);
end;
i:=i-10;
end;
newbmp.free;

end;

end.
baby19820917 2002-11-24
  • 打赏
  • 举报
回复
你的信箱.我发给你 ,我的信箱是baby19820917@163.com
发信给我也可以.
weibz0525 2002-11-24
  • 打赏
  • 举报
回复
给我信箱,我这里有一些delphi源代码,
我先粘点bcb的,看一下思路自己改成Delphi的吧。
分再多,我都不在乎,呵呵。



标题: 用C++ Builder对图像进行特殊效果处理


关键字:对图像进行特殊效果处理,柔化,锐化,浮雕效果,TCanvas类


在Windows编程中图像处理相对比较复杂,好在C++ Builder提供了一些图形类,它们通过对Windows中的图形对象进行包装,从而大大简化了图像操作的难度。下面就通过对图像进行柔化、锐化、浮雕效果等几个特殊效果处理来具体说明一下。

一、准备工作 位图图形实际上是像素的二维数组,它记录了每个像素的颜色信息,而TCanvas类提供了Pixels属性,用它可以存取指定像素的颜色值,通过这个属性将位图图形的部分或全部像素的颜色值进行相应的变换处理,就可以实现图像的特殊效果处理。在Windows中颜色是根据红、绿、蓝三种颜色的饱和度来定义的,在这里我们要将像素颜色值的红、绿、蓝分量从像素值中分离出来,分别加以保存,所以需要定义一个结构来存放颜色分量:

struct rgb_str
{
unsigned char r_color;
unsigned char g_color;
unsigned char b_color;
};
rgb_str rgb[2000][2000];

建立全局变量:Graphics::TBitmap *bitmap;

//用来存放变换后的位图

int i,j,width,height;

在窗体上放置一个TImage组件和OpenPictureDialog组件,将TImage的AutoSize属性设为true,将OpenPictureDialog的Filter设为*.bmp。当用户选择Open命令后,打开相应的对话框,让用户选择要处理的图像文件,然后程序将图像的所有像素的颜色分量保存到rgb数组中:

void __fastcall TForm1::mnuFileOpenClick(TObject *Sender)
{
TColor color;
if(OpenPictureDialog1- >Execute())
{
Image1- >Picture->LoadFromFile(OpenPictureDialog1- >FileName);
width=Image1- >Picture- >Width; height=Image1->Picture->Height;
for(i=0;i< width-1;i++)
for(j=0;j< height-1;j++)
{
color=Image1- >Canvas->Pixels[i][j];
rgb[i][j].r_color=GetRValue(color);
rgb[i][j].g_color=GetGValue(color);
rgb[i][j].b_color=GetBValue(color);
}
bitmap=new Graphics::TBitmap;
bitmap->Width=width;
bitmap->Height=height;
}
}

二、图像的柔化处理

柔化就是对图像进行平滑处理,减少相邻像素间的颜色差别,一般选用3*3像素块,将中间的像素值改成这9个像素的平均像素值,从而达到柔化效果。其代码如下:

void __fastcall TForm1::btnSmoothClick(TObject *Sender)
{
int red,green,blue;
for(i=1;i< width-2;i++)
for(j=1;j< height-2;j++)
{
red=rgb[i-1][j-1].r_color+rgb[i][j-1].r_color+rgb[i+1][j-1].r_color+rgb[i-1][j].r_color+rgb[i][j].r_color+rgb[i+1][j].r_color+
rgb[i-1][j+1].r_color+rgb[i][j+1].r_color+rgb[i+1][j+1].r_color;
green=rgb[i-1][j-1].g_color+rgb[i][j-1].g_color+rgb[i+1][j-1].g_color+rgb[i-1][j].g_color+rgb[i][j].g_color+rgb[i+1][j].g_color+
rgb[i-1][j+1].g_color+rgb[i][j+1].g_color+rgb[i+1][j+1].g_color;
blue=rgb[i-1][j-1].b_color+rgb[i][j-1].b_color+rgb[i+1][j-1].b_color+rgb[i-1][j].b_color+rgb[i][j].b_color+rgb[i+1][j].b_color +
rgb[i-1][j+1].b_color+rgb[i][j+1].b_color+rgb[i+1][j+1].b_color;
bitmap->Canvas->Pixels[i][j]=RGB(red/9,green/9,blue/9);
}
Image1- >Picture- >Bitmap- >Assign(bitmap);
}

三、图像的锐化处理

图像的锐化处理正好与柔化处理相反,它的目的是突出图像的变化部分,这里采用的算法是将要处理的像素与它左对角线的像素之间的差值乘上一个锐化度数,然后再加上原先的像素值:new_value=original_value+degree*difference,你可以通过改变degree的值来调节锐化效果。这里需要注意的是得到的像素新值可能会超出颜色值的有效范围(0-255),所以程序要检验结果的有效性,为此需定义两个函数:

int min(int value1,int value2)
{
if(value1 >value2)return value2;
else return value1;
}

int max(int value1,int value2)
{
if(value1 >value2)return value1;
else return value2;
}

锐化处理的代码如下:

void __fastcall TForm1::btnSharpeClick(TObject *Sender)
{
float degree=0.3;
int red,green,blue;
for(i=1;i<width-1;i++)
for(j=1;j<height-1;j++)
{
red=rgb[i][j].r_color+degree*(rgb[i][j].r_color-rgb[i-1][j-1].r_color);
green=rgb[i][j].g_color+degree*(rgb[i][j].g_color-rgb[i-1][j-1].g_color);
blue=rgb[i][j].b_color+degree*(rgb[i][j].b_color-rgb[i-1][j-1].b_color);
red=min(255,max(0,red));
green=min(255,max(0,green));
blue=min(255,max(0,blue));
bitmap->Canvas->Pixels[i][j]=RGB (red,green,blue);
}
Image1- >Picture- >Bitmap- >Assign(bitmap);


四、图像的浮雕效果实现

浮雕效果就是只将图像的变化部分突出出来,而相同颜色部分则被淡化,使图像出现纵深感,从而达到浮雕效果,这里采用的算法是将要处理的像素取值为与处于对角线上的另一个像素间的差值,这样只有颜色变化区才会出现色彩,而颜色平淡区因差值几乎为零则变成黑色,你可以通过加上一个常量来增加一些亮度:new_value=difference+const_value,具体代码如下:

void __fastcall TForm1::btnEmbossClick(TObject *Sender)
{
int red,green,blue;
const int const_value=128;
for(i=0;i< width-2;i++)
for(j=0;j< height-2;j++)
{
red=abs(rgb[i][j].r_color-rgb[i+1][j+1].r_color+const_value);
green=abs(rgb[i][j].g_color-rgb[i+1][j+1].g_color+const_value);
blue=abs(rgb[i][j].b_color-rgb[i+1][j+1].b_color+const_value);
bitmap->Canvas->Pixels[i][j]=RGB(red,green,blue);
}
Image1- >Picture- >Bitmap- >Assign(bitmap);
}



1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi GAME,图形处理/多媒体
社区管理员
  • GAME,图形处理/多媒体社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧