• Welcome to Vampyre Imaging Library Forum. Please login or sign up.
 

Post reply

Other options

Shortcuts: ALT+S save/post or ALT+P preview

Topic summary

Posted by salvok5
 - 22 December 2012, 15:50:26
On delphi XE3 the "ImagingFmx.pas" by 4 error.
Posted by Galfar
 - 22 December 2012, 04:07:28
Have you checked ImagingFmx.pas unit?
It has a functions like:
Code (pascal) Select
{ Converts image from TBaseImage instance to FMX bitmap. Bitmap must be already instantiated.}
procedure ConvertImageToFmxBitmap(Image: TBaseImage; Bitmap: TBitmap);

that can directly convert from Imaging image to FMX bitmap (for FMX1 in XE2 only though).

Resaving image as GIF and loading it to FMX bitmap is a bad idea, you lose the alpha channel.
And it seems to me that you will only have the last frame in FMX image after this code is run.

Try something like this first:
Code (pascal) Select
FImage.LoadMultiFromFile('E:\espulso.gif');
FmxImage.BeginUpdate;
try
  ImagingFmx.ConvertImageToFmxBitmap(FImage, FmxImage.Bitmap);
finally
  FmxImage.EndUpdate;
end;

 
Posted by salvok5
 - 20 December 2012, 17:25:05
I'm trying to convert a frame of animated gif file to "FMX TImage".
The problem with this code is that there is no transparency in the alpha channel does not work.
Sorry for my bad inghlese.

Code (pascal) Select
procedure TForm5.Button1Click(Sender: TObject);
var
  I,y,x: LongInt;
  T: Int64;
  io:Tmemorystream;
  Dest, Src: PByte;
  Alpha: Byte;
begin
    try
      FImage := TMultiImage.Create;
      FImage2 := TMultiImage.Create;

      // Load all subimages in file
      T := ImagingUtility.GetTimeMicroseconds;
      FImage.LoadMultiFromFile('E:\espulso.gif');
      FImage2.LoadMultiFromFile('E:\espulso.gif');

      for I := 0 to FImage.ImageCount - 1 do
      begin
        FImage.ActiveImage := I;
        if not (FImage.Format in TImagingCanvas.GetSupportedFormats) then
          FImage.Format := ifA8R8G8B8;
        for Y := 0 to Height - 1 do
        begin
          Src := FImage.Scanline[y];
          Dest := FImage2.ScanLine[y];
          for X := 0 to Width - 1 do
          begin
            Alpha := Src[X * 4 + 3];
            Dest[X * 4 + 0] := Src[x * 4 + 0] * Alpha div 255;
            Dest[X * 4 + 1] := Src[x * 4 + 1] * Alpha div 255;
            Dest[X * 4 + 2] := Src[x * 4 + 2] * Alpha div 255;
            Dest[X * 4 + 3] := Alpha;
          end;
        end;
        io:=Tmemorystream.Create;
        FImage2.SaveToStream('gif',io);
        image1.Bitmap.LoadFromStream(io);
        ............
        break;

      end;
      // Activate first image and update UI
      FImage.ActiveImage := 0;
    except
      raise;
    end;

end;


SMF spam blocked by CleanTalk