《2744.图像效果算法设计——静态效果毕业论文 相关代码.doc》由会员分享,可在线阅读,更多相关《2744.图像效果算法设计——静态效果毕业论文 相关代码.doc(22页珍藏版)》请在优知文库上搜索。
1、目录90度旋转2垂直旋转3水平旋转4灰度4添加噪点5彩色噪点6喷溅6马赛克6RGB调整7亮度调整9对比度调整11饱和度调整12曝光14浮雕14雕刻16模糊17锐化18霓虹19/90度旋转procedure TForm1.Rotatepicture(Bitmap: TBitmap);var aStream: TMemorystream; /内存流 header: TBITMAPINFO; dc: hDC; P: THelpRGB; x, y, b, h: Integer; RowOut: pRGBArray;begin /创建内存流 aStream := TMemoryStream.Create
2、; /设置大小,必须是4的倍数 aStream.SetSize(Bitmap.Height * Bitmap.Width * 4); with header.bmiHeader do /操作位图文件 begin biSize := SizeOf(TBITMAPINFOHEADER); /大小 biWidth := Bitmap.Width; /位图宽 biHeight := Bitmap.Height; /位图高 biPlanes := 1; biBitCount := 32; /无压缩 biCompression := 0; biSizeimage := aStream.Size; biXP
3、elsPerMeter := 1; /水平分辨率 biYPelsPerMeter := 1; /竖直分辨率 biClrUsed := 0; biClrImportant := 0; end; dc := GetDC(0); P := aStream.Memory; GetDIBits(dc, Bitmap.Handle, 0, Bitmap.Height, P, header, dib_RGB_Colors); ReleaseDC(0, dc); b := bitmap.Height; /源图高 h := bitmap.Width; /源图宽 /指定要创建的位图的大小尺寸 bitmap.Wid
4、th := b; bitmap.height := h; for y := 0 to (h - 1) do begin rowOut := Bitmap.ScanLiney; /获取新的位图信息 P := aStream.Memory; /设置文件指针 inc(p, y); /指针移位 for x := 0 to (b - 1) do begin rowoutx := p.rgb; /进行数据转移 inc(p, h); end; end; aStream.Free; /释放资源end;/垂直翻转procedure TForm1.bsSkinSpeedButton3Click(Sender: T
5、Object);var bmp1, bmp2: Tbitmap; i, j: integer; p, p1: pbyteArray;begin image1.Stretch:=true; bmp1 := Tbitmap.Create; bmp2 := Tbitmap.Create; bmp1.Assign(Self.Image1.Picture.Bitmap); bmp2.Assign(Self.image1.Picture.Bitmap); bmp1.PixelFormat := pf24bit; bmp2.PixelFormat := pf24bit; for j := 0 to Self
6、.image1.Picture.Graphic.Height - 1 do begin p := bmp1.ScanLinej; p1 := bmp2.ScanLineSelf.IMAGE1.Picture.Graphic.Height - 1 - j; for i := 0 to Self.image1.Picture.Graphic.Width - 1 do begin p3 * i := p13 * i; p3 * i + 1 := p13 * i + 1; p3 * i + 2 := p12 + 3 * i; end; end; bmp1.PixelFormat:=pf24bit; S
7、elf.Image1.Picture.Bitmap.Assign(bmp1); Self.image1.picture.Bitmap.PixelFormat := pf24bit; bmp1.Free; bmp2.Free; IsImageChanged:=true; undouse;end;/水平翻转procedure TForm1.bsSkinSpeedButton4Click(Sender: TObject);var bmp1, bmp2: TBitmap; T, P: pByteArray; X, Y: integer;begin image1.Stretch:=true; bmp1
8、:= TBitmap.Create; bmp2 := TBitmap.Create; bmp2.Assign(image1.Picture.Bitmap); bmp1.Assign(image1.Picture.Bitmap); for Y := 0 to bmp2.Height - 1 do begin T := bmp2.ScanLineY; P := bmp1.ScanLineY; for X := 0 to bmp2.Width - 1 do begin P3 * X + 2 := T3 * (bmp2.Width - 1 - X) + 2; P3 * X + 1 := T3 * (b
9、mp2.Width - 1 - X) + 1; P3 * X := T3 * (bmp2.Width - 1 - X); end; end; image1.Picture.Bitmap.Assign(bmp1); bmp1.Free; bmp2.Free; IsImageChanged:=true; undouse;end;/函数Function IntToByte(i: Integer): Byte;Begin If i 255 Then Result := 255 Else If i 240 then avg := 240; Pixel.rgbtRed := avg; Pixel.rgbt
10、Green := avg; Pixel.rgbtBlue := avg; Inc(Pixel); end; end;end;/添加噪点Procedure AddMonoNoise(srcbmp: tbitmap; Amount: Integer);Var p0: pbytearray; x, y, a, r, g, b: Integer;Begin For y := 0 To srcbmp.Height - 1 Do Begin p0 := srcbmp.scanliney; For x := 0 To srcbmp.Width - 1 Do Begin a := Random(Amount) - (Amount Shr 1); r := p0x * 3 + a; g := p0x * 3 + 1 + a; b := p0x * 3 + 2 + a; p0x * 3 := IntToByte(r); p0x * 3 + 1 := IntToByte(g); p0x * 3 + 2 := IntToByte(b); End; End;End;/添加彩色噪点Procedur