博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
刚刚写的一个将图像的某个区域之外的区域变暗的函数
阅读量:4149 次
发布时间:2019-05-25

本文共 2588 字,大约阅读时间需要 8 分钟。

DelphiCode:
{-------------------------------------------------------------------------------  过程名:    DarkBmp  作者:      不得闲  日期:      2009.02.04  参数:      bmp: TBitmap;var DarkRect: TRect;const DarkValue: Integer;const HighValue: Integer = 0             DarkRect指定不变暗的区域             DarkValue: 指定暗化的数量值             HighValue: 指定矩形区域增亮化的数量值  功能:     将图像的某个区域之外的区域变暗的函数  返回值:    无-------------------------------------------------------------------------------}procedure DarkBmp(bmp: TBitmap;var DarkRect: TRect;const DarkValue: Integer;const HighValue: Integer = 0);var  i,j : integer;  pB : PByteArray;  BmpFormatXs: Integer;  w,h:Integer;begin  i := Integer(bmp.PixelFormat);  if i < 4 then    i := 4  else if i = 4 then    inc(i)  else if i > 7 then    i := 7;    BmpFormatXs := i - 3;  w:= DarkRect.Right - DarkRect.Left;  h:= DarkRect.Bottom - DarkRect.Top;   if DarkRect.Right > bmp.Width then  begin    DarkRect.Left:=bmp.Width - w;    DarkRect.Right:=bmp.Width;  end;  if (DarkRect.Bottom > bmp.Height) then  begin    DarkRect.Top:= bmp.Height - h;    DarkRect.Bottom:=bmp.Height;  end;  if DarkRect.Left <0 then  begin    DarkRect.Left:=0;    DarkRect.Right:=w;  end;  if DarkRect.Top <0 then  begin    DarkRect.Top:=0;    DarkRect.Bottom:=h;  end;  for i := 0 to DarkRect.Top - 1 do  begin    pb:=bmp.ScanLine[i];    for j:=0 to BmpFormatXs*bmp.Width - 1 do      if pb[j]then        pb[j]:=0      else dec(pb[j],DarkValue);  end;  for i := DarkRect.Top to bmp.Height - 1 do  begin    pb:=bmp.ScanLine[i];    for j:=0 to BmpFormatXs*DarkRect.Left - 1 do      if pb[j]then        pb[j]:=0      else dec(pb[j],DarkValue);  end;  for i := DarkRect.Bottom to bmp.Height - 1 do  begin    pb:=bmp.ScanLine[i];    for j:= BmpFormatXs*DarkRect.Left to BmpFormatXs*bmp.Width - 1 do      if pb[j]then        pb[j]:=0      else dec(pb[j],DarkValue);  end;  for i := DarkRect.Top to DarkRect.Bottom - 1 do  begin    pb:=bmp.ScanLine[i];    for j:= BmpFormatXs*DarkRect.Right to BmpFormatXs*bmp.Width - 1 do      if pb[j]then        pb[j]:=0      else dec(pb[j],DarkValue)  end;  if HighValue <> 0 then    for i := DarkRect.Top to DarkRect.Bottom - 1 do    begin      pb:=bmp.ScanLine[i];      for j:= BmpFormatXs*DarkRect.Left to BmpFormatXs*DarkRect.Right - 1 do        if pb[j]>(255-DarkValue) then          pb[j]:=255        else inc(pb[j],HighValue);    end;end;使用方法:procedure TForm1.Button1Click(Sender: TObject);var  bmp: TBitmap;  r: TRect;begin  bmp := TBitmap.Create;  bmp.Assign(Image1.Picture.Bitmap);  r := Rect(0,0,50,50);  DarkBmp(bmp,r,40,10);  Image2.Picture.Bitmap := bmp;end;

转载地址:http://srsti.baihongyu.com/

你可能感兴趣的文章
checkio-moore neighbourhood
查看>>
checkio-the most wanted letter
查看>>
Redis可视化工具
查看>>
1033. To Fill or Not to Fill (25)
查看>>
1034. Head of a Gang (30)
查看>>
1035. Password (20)
查看>>
1036. Boys vs Girls (25)
查看>>
1037. Magic Coupon (25)
查看>>
1038. Recover the Smallest Number (30)
查看>>
1011. World Cup Betting (20)
查看>>
PAT解题报告索引
查看>>
1039. Course List for Student (25)
查看>>
1010. Radix (25)
查看>>
Pattern Searching
查看>>
[LeetCode]3Sum
查看>>
[LeetCode]Add Two Numbers
查看>>
[LeetCode]Anagrams
查看>>
[LeetCode]Balanced Binary Tree
查看>>
[LeetCode]Best Time to Buy and Sell Stock
查看>>
[LeetCode]Best Time to Buy and Sell Stock II
查看>>