No answers, but I managed to get it to work. I think the problem was caused by setting pen or brush colors in the ImageEnView1.IEBitmap.AlphaChannel.Canvas.
procedure TForm1.DrawFilledRectangle;
{Draw a filled rectangle}
var
iPenSize: integer;
iPenColor: TColor;
iPenAlpha: integer;
iBrushColor: TColor;
iBrushAlpha: integer;
begin
MyUndo(ImageEnView1);
// Draw on the Non-Alpha Canvas
NewCanvas := TIECanvas.Create(ImageEnView1.IEBitmap.Canvas, AntiAlias1.Checked, UseGDIPlus1.Checked);
iPenSize := StrToInt(BrushSize1.Text);
iPenColor := PENCOLOR1.Selected;
iPenAlpha := StrToInt(PenAlpha1.Text);
iBrushColor := BrushColor1.Selected;
iBrushAlpha := StrToInt(BrushAlpha1.Text);
NewCanvas.Pen.Color := iPenColor;
NewCanvas.Pen.Transparency := iPenAlpha;
NewCanvas.Pen.Style := psSolid;
NewCanvas.Pen.Width := iPenSize;
NewCanvas.Brush.Color := iBrushColor;
NewCanvas.Brush.Style := bsSolid;
NewCanvas.Brush.Transparency := iBrushAlpha;
NewCanvas.Brush.BackTransparency := iBrushAlpha;
NewCanvas.Rectangle(startX, startY, PX + iPenSize, PY + iPenSize);
NewCanvas.Free();
// Draw on the Alpha Canvas
// Note: do not assign color here... it will overwrite the alphachannel
ImageEnView1.IEBitmap.AlphaChannel.CanvasCurrentAlpha := iPenAlpha;
// Note: unless you assign the AlphaChannel.CanvasCurrentAlpha the pen is not visible even though
// NewCanvas.Pen.Transparency is set before drawing
NewCanvas := TIECanvas.Create(ImageEnView1.IEBitmap.AlphaChannel.Canvas, AntiAlias1.Checked, UseGDIPlus1.Checked);
NewCanvas.Pen.Width := iPenSize;
NewCanvas.Pen.Style := psSolid;
NewCanvas.Pen.Transparency := iPenAlpha;
NewCanvas.Brush.Style := bsSolid;
NewCanvas.Brush.Transparency := iBrushAlpha;
NewCanvas.Brush.BackTransparency := iBrushAlpha;
NewCanvas.Rectangle(startX, startY, PX + iPenSize, PY + iPenSize);
NewCanvas.Free();
ImageEnView1.Update;
ImageEnView1.Bitmap.Modified := True;
end;
The strange thing I find now is that after the rectangle is drawn, I get the alpha under the mouse cursor in OnMouseMove, but the value returned is close to what it was set at when drawing not not exactly.
For example if the alpha is 255 when drawing, iAlpha in ImageEnView1MouseMove returns 252 instead of 255. if the alpha is 102 when drawing, iAlpha in ImageEnView1MouseMove returns 100 instead of 102?
I have never seen this before with ImageEn unless running TIECanvas... is there a bug in ImageEn or am I still working with the alphachannel drawing incorrectly?
procedure TForm1.ImageEnView1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
var
BX, BY: Integer;
iAlpha: integer;
begin
BX := ImageEnView1.XScr2Bmp(X);
BY := ImageEnView1.YScr2Bmp(Y);
iAlpha := ImageEnView1.IEBitmap.Alpha[BX, BY];
AlphaUnderCursor1.Caption := 'Alpha: ' + IntToStr(iAlpha);
OpacityUnderCursor1.Caption := 'Opacity: ' + IntToStr
(IEAlphaToOpacity(iAlpha)) + '%';
end;
William Miller