Search results for 'TransparentColor'. 1 post(s) found.
- 2007/09/11 Grayscaling a bitmap ?
This example uses an averaging mechanism to obtain GrayScale intensity on a pixel-by-pixel basis. Specifically, it averages the Red, Green and Blue component values of a color and assigns that value back to each RGB component.
Usage:
GrayScale(Image1.Picture.Graphic, image1.Picture.Bitmap, 0) ;
Here's the source code can use above usage code.
type
TRGBColor = record
case Integer of
0 : (Color : TColor) ;
1 : (Red, Green, Blue, Intensity : Byte) ;
2 : (Colors : array[0..3] of Byte) ;
end;
procedure GrayScale(Graphic : TGraphic;
Bitmap : TBitmap;
Contrast : Integer ) ;
var bmp, mask : TBitmap;
x, y , Avg : Integer;
RGBColor : TRGBColor;
begin
if not Assigned(Graphic) then
Exit;
bmp := TBitmap.Create;
mask := TBitmap.Create;
try
bmp.Height := Graphic.Height;
bmp.Width := Graphic.Width;
with bmp.Canvas do begin
if Graphic is TBitmap then
Brush.Color := (Graphic as TBitmap).TransparentColor
else
Brush.Color := clPurple;
FillRect(ClipRect) ;
Draw(0,0,Graphic) ;
end;
mask.assign(bmp) ;
mask.mask(bmp.TransparentColor) ;
with bmp.Canvas do begin
for y := 0 to ClipRect.Bottom do begin
for x := 0 to ClipRect.Right do begin
if mask.Canvas.Pixels[x,y] = clBlack then begin
RGBColor.Color := Pixels[x,y] ;
with RGBColor do begin
Avg := ((Red+Green+Blue) div 3) ;
Inc(Avg, Contrast) ;
if Avg > 255 then
Avg := 255
else if Avg < 0 then
Avg := 0;
Red := Avg;
Green := Avg;
Blue := Avg;
end;
Pixels[x,y] := RGBColor.Color;
end;
end;
end;
end;
if Assigned(Bitmap) then
Bitmap.Assign(bmp)
else if Graphic is TBitmap then
(Graphic as TBitmap).Assign(bmp) ;
finally
bmp.Free;
mask.Free;
end;
end;
TRGBColor = record
case Integer of
0 : (Color : TColor) ;
1 : (Red, Green, Blue, Intensity : Byte) ;
2 : (Colors : array[0..3] of Byte) ;
end;
procedure GrayScale(Graphic : TGraphic;
Bitmap : TBitmap;
Contrast : Integer ) ;
var bmp, mask : TBitmap;
x, y , Avg : Integer;
RGBColor : TRGBColor;
begin
if not Assigned(Graphic) then
Exit;
bmp := TBitmap.Create;
mask := TBitmap.Create;
try
bmp.Height := Graphic.Height;
bmp.Width := Graphic.Width;
with bmp.Canvas do begin
if Graphic is TBitmap then
Brush.Color := (Graphic as TBitmap).TransparentColor
else
Brush.Color := clPurple;
FillRect(ClipRect) ;
Draw(0,0,Graphic) ;
end;
mask.assign(bmp) ;
mask.mask(bmp.TransparentColor) ;
with bmp.Canvas do begin
for y := 0 to ClipRect.Bottom do begin
for x := 0 to ClipRect.Right do begin
if mask.Canvas.Pixels[x,y] = clBlack then begin
RGBColor.Color := Pixels[x,y] ;
with RGBColor do begin
Avg := ((Red+Green+Blue) div 3) ;
Inc(Avg, Contrast) ;
if Avg > 255 then
Avg := 255
else if Avg < 0 then
Avg := 0;
Red := Avg;
Green := Avg;
Blue := Avg;
end;
Pixels[x,y] := RGBColor.Color;
end;
end;
end;
end;
if Assigned(Bitmap) then
Bitmap.Assign(bmp)
else if Graphic is TBitmap then
(Graphic as TBitmap).Assign(bmp) ;
finally
bmp.Free;
mask.Free;
end;
end;
Another posts included in "Delphi"
| Implementing a lasso drawing technique (0) | 2007/09/11 |
| Is Point in Polygon? (0) | 2007/09/11 |
| Paint a Form with a tiled bitmap image (0) | 2007/09/11 |
| Get Cursor Image (draw it on a Canvas) (0) | 2007/09/11 |
| How to convert HIcon to TIcon ? (0) | 2007/09/11 |
| Extract an icon from an Windows application and paint on a Form (0) | 2007/09/11 |
| How to draw transparent text on Windows Desktop (0) | 2007/09/11 |
| How to draw rotated text (0) | 2007/09/11 |
Trackback : Cannot send a trackbact to this post.
-
Subject different money making ideas
2010/01/29 03:02
moneyideas
-
Subject different money making ideas
2010/01/29 11:44
moneyideas
-
Subject different money making ideas
2010/01/31 16:39
moneyideas

Prev

Rss Feed