Author |
Topic  |
|
nwscomps
  
185 Posts |
Posted - Jan 11 2016 : 09:58:14
|
I tried to attach the zip file for the project but it did not work, so I copied the code of the main form. Please add a TImageenview component to the form and set the zoomfilter to FastLinear (or anything other than none). Then add the button1, the opendialog and the spinedit to change the zoom
When viewed at 100% the layer will display the alpha channel, but when viewed with other zoom the alpha channel is not taken into consideration when displaying the layer. I used a older version of Imageen 5.0.5, maybe this is already solved in newer versions? Thanks, Francesco
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, ieopensavedlg, Vcl.StdCtrls,
imageenview, ieview, Vcl.Samples.Spin;
type
TForm1 = class(TForm)
ImageEnView1: TImageEnView;
Button1: TButton;
OpenImageEnDialog1: TOpenImageEnDialog;
SpinEdit1: TSpinEdit;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure SpinEdit1Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses hyiedefs, hyieutils;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
alayer: TIELayer;
iebmp: Tiebitmap;
alphach: tbitmap;
begin
if OpenImageEnDialog1.execute then
begin
imageenview1.LayersAdd;
alayer := imageenview1.layers[imageenview1.Layerscurrent];
alayer.Locked := false;
imageenview1.IO.LoadFromFile(openimageendialog1.filename);
//alayer.
if (not alayer.bitmap.HasAlphaChannel) or (not assigned(alayer.bitmap.AlphaChannel)) then
begin
iebmp := TIEBitmap.Create();
try
iebmp.AssignImage(alayer.Bitmap);
alphach := tBitmap.create;
alphach.PixelFormat := pf24bit;
alphach.Canvas.brush.color := rgb(0, 0, 0); //rgb(255, 255, 255);
alphach.width := alayer.Width;
alphach.height := alayer.height;
alphach.Canvas.brush.color := rgb(255, 255, 255); // rgb(0, 0, 0);
alphach.Canvas.brush.Style := bsSolid;
alphach.Canvas.Ellipse(0,0,alphach.width, alphach.height);
alphach.PixelFormat := pf8bit;
try
// iebmp.AlphaChannel.Assign(bmp);
alayer.Bitmap.AssignImage(iebmp);
alayer.Bitmap.AlphaChannel := TIEBitmap.Create();
alayer.Bitmap.AlphaChannel.CopyFromTBitmap(alphach);
ShowMessage(BoolToStr(alayer.Bitmap.HasAlphaChannel));
finally
alphach.free;
end;
finally
iebmp.Free;
end;
end;
imageenview1.update;
end;
end;
procedure TForm1.SpinEdit1Change(Sender: TObject);
begin
ImageEnView1.Zoom := SpinEdit1.Value ;
end;
end.
Francesco Savastano Nwscomps.com Add-ons for the ImageEn Library |
|
xequte
    
39053 Posts |
Posted - Jan 11 2016 : 17:31:34
|
Hi Francesco
It seems to work fine in my tests. Perhaps attach a screenshot of what you are seeing and an example image.
Nigel Xequte Software www.xequte.com nigel@xequte.com
|
 |
|
nwscomps
  
185 Posts |
Posted - Jan 12 2016 : 10:03:07
|
Hi Nigel, here are the steps: - load a jpeg from file (step 1) - the elliptic alpha channel will be created and assigned to the layer, the layer is displayed correctly when zoom is 100% (step 2) - When I change the zoom to 50% or any value < 100 (step 3) the alpha channel is not accounted while displaying (although it is still there)
Please make sure the zoomfilter property of imageenview is set to some value other than rfnone to reproduce the issue, and also consider I am using v. 5.0.5



Thanks for looking into it, Francesco
Francesco Savastano Nwscomps.com Add-ons for the ImageEn Library |
 |
|
xequte
    
39053 Posts |
Posted - Jan 13 2016 : 16:21:49
|
Thanks Francesco,
I can reproduce and am investigating.
FYI, you should not create TIEBitmap.AlphaChannel. It is created automatically when accessed,
i.e. just call: alayer.Bitmap.AlphaChannel.CopyFromTBitmap(alphach);
Nigel Xequte Software www.xequte.com nigel@xequte.com
|
 |
|
xequte
    
39053 Posts |
Posted - Jan 14 2016 : 20:52:49
|
Hi
Oh, I see that the alpha channel is not 8bit after the copy (we need to improve that).
This code works:
procedure TForm1.Button1Click(Sender: TObject);
var
alayer: TIELayer;
alphach: tbitmap;
begin
if OpenImageEnDialog1.execute then
begin
imageenview1.LayersAdd;
alayer := imageenview1.layers[imageenview1.Layerscurrent];
alayer.Locked := false;
imageenview1.IO.LoadFromFile( openimageendialog1.filename);
if (not alayer.bitmap.HasAlphaChannel) or (not assigned(alayer.bitmap.AlphaChannel)) then
begin
alphach := tBitmap.create;
alphach.PixelFormat := pf24bit;
alphach.Canvas.brush.color := rgb(0, 0, 0);
alphach.width := alayer.Width;
alphach.height := alayer.height;
alphach.Canvas.brush.color := rgb(255, 255, 255);
alphach.Canvas.brush.Style := bsSolid;
alphach.Canvas.Ellipse(0,0,alphach.width, alphach.height);
alphach.PixelFormat := pf8bit;
try
alayer.Bitmap.AlphaChannel.CopyFromTBitmap(alphach);
alayer.Bitmap.AlphaChannel.PixelFormat := ie8g;
finally
alphach.free;
end;
end;
imageenview1.update;
end;
end;
Nigel Xequte Software www.xequte.com nigel@xequte.com
|
 |
|
xequte
    
39053 Posts |
Posted - Jan 17 2016 : 21:27:24
|
Also, here is a better way to create the transparency:
alayer.Bitmap.AlphaChannel.Fill(0);
with alayer.Bitmap.AlphaChannel.CreateROICanvas(Rect(0, 0, alayer.Bitmap.Width - 1, alayer.Bitmap.Height - 1)) do
begin
brush.Style := bsSolid;
brush.color := rgb(255, 255, 255);
Ellipse(0, 0, alayer.Bitmap.Width, alayer.Bitmap.Height);
Free();
end;
Nigel Xequte Software www.xequte.com nigel@xequte.com
|
 |
|
|
Topic  |
|
|
|