title: Combination of Canvas.TransparentColor and Canvas.Draw with Opacity
body: <p>i want to draw a bitmap on a canvas with opacity where the bitmap has a transparent color.</p>
  
  <ul>
  <li>i could create a bitmap with transparent color and draw it to a</li>
  <li>canvas i could create a bitmap and draw it to a canvas with opacity</li>
  </ul>
  
  <p>but i couldn't combine it. if i combine it the opacity is ignored.</p>
  
  <p>here is the code i wrote:</p>
  
  <pre><code>procedure TForm1.FormPaint(Sender: TObject);
  var b1,b2:TBitmap;
  begin
    // Example how it opacity works:
    b1 := TBitmap.Create;
    b1.SetSize(20,20);
    b1.Canvas.Brush.Color := clBlue;
    b1.Canvas.Rectangle(0,0,20,20);
    Canvas.Draw(10,10,b1,$ff);  // Works
    Canvas.Draw(40,10,b1,$66);  // Works
  
    // I need it in combination with TransparentColor:
    b2 := TBitmap.Create;
    // next 3 lines are different from above
    b2.Transparent := true;
    b2.TransparentColor := clFuchsia;
    b2.Canvas.Brush.Color := clFuchsia;
    b2.SetSize(20,20);
    b2.Canvas.Brush.Color := clBlue;
    b2.Canvas.Ellipse(0,0,20,20);
    Canvas.Draw(10,40,b2,$ff);  // Works (full opacity)
    Canvas.Draw(40,40,b2,$66);  // Ignores the $66 Opacity
  
    b1.Free;
    b2.Free;
  end;
  </code></pre>
  
  <p>produces:<br>
  <img src="https://i.stack.imgur.com/godpG.png" alt="enter image description here"></p>
  
  <p>how could i draw (f.e. a blue circle) with transparent background and just 40% opacity?</p>
  
  <p>i would prefere a solution without direct winapi (like bitblt, ...) if possible.</p>
  
  <p>i tried a few hacks like bitshifting a alpha channel to a TColor value but it didn't work.</p>
  
  <p>here i what i tried:</p>
  
  <pre><code>procedure TForm1.FormPaint(Sender: TObject);
  var b:TBitmap;
  begin
    b := TBitmap.Create;
    b.PixelFormat := pf32bit;
    b.AlphaFormat := afDefined;
  
    b.Canvas.Brush.Color := 0 and ($ff shl 32);  // Background Transperency
    b.SetSize(20,20);
    b.Canvas.Brush.Color := clBlue + (($ff-$66) shl 32);
    b.Canvas.Ellipse(0,0,20,20);
    Canvas.Draw(10,10,b);
  
    b.Free;
  end;
  </code></pre>
  
  <p>produces:<br>
  <img src="https://i.stack.imgur.com/Y4Y8q.png" alt="enter image description here"></p>
  
  <p>thanks in advance!</p>
  
  <p><strong>EDIT:</strong> my system: delphi xe 5 on windows 7 64bit (but using the 32bit compiler)    </p>