How To Paint A Picture On Canvas
Overview
From the GR32 library, I am using TImgView32 to render a filigree which will be my transparent groundwork like so:
Placed inside the TImgView32 I have a regular TImage, where I volition exist cartoon onto the canvas, something like this:
Task
What I would like to achieve is the ability to set the opacity of the brush, assuasive further possibilities for image editing in my program. Rather than have one flat color been drawn, setting the opacity of the castor allows different levels of color depth etc.
I establish this question earlier whilst searching around: Draw opacity ellipse in Delphi 2010 - Andreas Rejbrand has provided a few examples in his answer for that question.
I take looked at what Andreas did, and came upwards with my own simplified try just I am stuck with a trouble. Take a await at these next two images, the start is with the transparent background and the second with a black background to show the problem more clearer:
Every bit you can encounter, around the brush (circle) is a really annoying square I cannot become rid of. All that should be visible is the brush. This is my code used to produce those results:
procedure DrawOpacityBrush(ACanvasBitmap: TBitmap; X, Y: Integer; AColor: TColor; ASize: Integer; Opacity: Integer); var Bmp: TBitmap; begin Bmp := TBitmap.Create; attempt Bmp.SetSize(ASize, ASize); Bmp.Transparent := Faux; with Bmp.Sheet exercise begin Pen.Color := AColor; Pen.Style := psSolid; Pen.Width := ASize; MoveTo(ASize div 2, ASize div two); LineTo(ASize div 2, ASize div two); finish; ACanvasBitmap.Sheet.Draw(X, Y, Bmp, Opacity); finally Bmp.Free; terminate; finish; procedure TForm1.Image1MouseDown(Sender: TObject; Push: TMouseButton; Shift: TShiftState; X, Y: Integer); begin DrawOpacityBrush(Image1.Picture.Bitmap, X, Y, clRed, 50, 85); finish;
which produces this on a regular bitmap:
The thought I had (based on Andreas manner of creating an ellipse with opacity) was to render a typical brush on the sheet, assign it to a offscreen bitmap then redraw information technology onto the main bitmap with the opacity. Which works, except that annoying square around the edge.
How can I return a brush with opacity as illustrated in the screenshots, just without that foursquare around the brush circle?
If I fix Bmp.Transparent := Truthful
there is still a white box, but no opacity anymore. Just a solid white foursquare and solid filled red circle.
Source: https://stackoverflow.com/questions/10342603/how-to-paint-on-a-canvas-with-transparency-and-opacity
Posted by: barstowfrally1974.blogspot.com
0 Response to "How To Paint A Picture On Canvas"
Post a Comment