2013-10-07 14 views
5

Sto provando a generare una bitmap da un controllo TLayout. Per fare questo uso la funzione TControl.Makescreenshot. Durante il test l'applicazione su Windows, tutto funziona come previsto:FireMonkey TControl.MakeScreenshot genera un bitmap sottodimensionato su piattaforme mobili

Windows

Tuttavia, quando si esegue l'applicazione su iOS, Android (sia emulatori e dispositivi reali), il risultato si presenta così (il bordo rosso intorno al immagine viene disegnata solo all'interno del bordo della bitmap):

iOS Screenshot

Nella versione mobile immagine è metà dimensione e il bordo viene ritagliata.

Ecco il codice che ho usato:

(.pas)

unit Unit15; 

interface 

uses 
    System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 
    FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls, 
    FMX.Objects, FMX.Layouts, FMX.Edit; 

type 
    TForm15 = class(TForm) 
    Layout1: TLayout; 
    Image1: TImage; 
    Button1: TButton; 
    CheckBox1: TCheckBox; 
    Label1: TLabel; 
    Switch1: TSwitch; 
    ArcDial1: TArcDial; 
    Edit1: TEdit; 
    Edit2: TEdit; 
    procedure Button1Click(Sender: TObject); 
    procedure FormResize(Sender: TObject); 
    private 
    { Private declarations } 
    public 
    { Public declarations } 
    end; 

var 
    Form15: TForm15; 

implementation 

{$R *.fmx} 

procedure TForm15.Button1Click(Sender: TObject); 
begin 
    Image1.Bitmap := Layout1.MakeScreenshot; 
    Image1.Bitmap.Canvas.BeginScene; 
    try 
    Image1.Bitmap.Canvas.Stroke.Color := TAlphaColorRec.Red; 
    Image1.Bitmap.Canvas.DrawRect(RectF(1, 1, Image1.Bitmap.Width - 1, Image1.Bitmap.Height - 2), 0, 0, [], 1); 
    finally 
    Image1.Bitmap.Canvas.EndScene; 
    end; 

    Edit1.Text := format('Image = Width: %d - Height: %d', [Image1.Bitmap.Width, Image1.Bitmap.Height]); 
    Edit2.Text := format('Original = Width: %d - Height: %d', [Round(Layout1.Width), Round(Layout1.Height)]); 
end; 

procedure TForm15.FormResize(Sender: TObject); 
begin 
    Layout1.Height := ClientHeight div 2; 
end; 

end. 

(.fmx)

object Form15: TForm15 
    Left = 0 
    Top = 0 
    Caption = 'Form15' 
    ClientHeight = 460 
    ClientWidth = 320 
    FormFactor.Width = 320 
    FormFactor.Height = 480 
    FormFactor.Devices = [dkDesktop] 
    OnResize = FormResize 
    DesignerMobile = True 
    DesignerWidth = 320 
    DesignerHeight = 480 
    DesignerDeviceName = 'iPhone' 
    DesignerOrientation = 0 
    DesignerOSVersion = '6' 
    object Layout1: TLayout 
    Align = alTop 
    ClipChildren = True 
    Height = 233.000000000000000000 
    Width = 320.000000000000000000 
    object Button1: TButton 
     Height = 44.000000000000000000 
     Position.X = 8.000000000000000000 
     Position.Y = 8.000000000000000000 
     TabOrder = 0 
     Text = 'Click to create Bitmap' 
     Trimming = ttCharacter 
     Width = 201.000000000000000000 
     OnClick = Button1Click 
    end 
    object CheckBox1: TCheckBox 
     Height = 23.000000000000000000 
     Position.X = 24.000000000000000000 
     Position.Y = 56.000000000000000000 
     TabOrder = 1 
     Text = 'CheckBox1' 
     Width = 120.000000000000000000 
    end 
    object Label1: TLabel 
     Height = 23.000000000000000000 
     Position.X = 24.000000000000000000 
     Position.Y = 88.000000000000000000 
     Text = 'Label1' 
     Width = 82.000000000000000000 
     Trimming = ttCharacter 
    end 
    object Switch1: TSwitch 
     Height = 27.000000000000000000 
     IsChecked = False 
     Position.X = 24.000000000000000000 
     Position.Y = 120.000000000000000000 
     TabOrder = 3 
     Width = 78.000000000000000000 
    end 
    object ArcDial1: TArcDial 
     Height = 81.000000000000000000 
     Position.X = 216.000000000000000000 
     Position.Y = 16.000000000000000000 
     TabOrder = 4 
     Width = 97.000000000000000000 
    end 
    object Edit1: TEdit 
     Touch.InteractiveGestures = [igLongTap, igDoubleTap] 
     TabOrder = 5 
     Position.X = 8.000000000000000000 
     Position.Y = 192.000000000000000000 
     Width = 305.000000000000000000 
     Height = 31.000000000000000000 
     KillFocusByReturn = False 
    end 
    object Edit2: TEdit 
     Touch.InteractiveGestures = [igLongTap, igDoubleTap] 
     TabOrder = 6 
     Position.X = 8.000000000000000000 
     Position.Y = 152.000000000000000000 
     Width = 305.000000000000000000 
     Height = 31.000000000000000000 
     KillFocusByReturn = False 
    end 
    end 
    object Image1: TImage 
    MultiResBitmap = < 
     item 
     end> 
    Align = alClient 
    Height = 227.000000000000000000 
    MarginWrapMode = iwOriginal 
    Width = 320.000000000000000000 
    WrapMode = iwOriginal 
    end 
end 

è il problema a che fare con densità di pixel o è una FireMonkey bug?

+0

L'immagine1 ha un allineamento di "alClient". Se si imposta l'allineamento su "alNone" e si impostano l'altezza e la larghezza da soli, è utile? – Johan

risposta

2

FireMonkey ha proprietà speciale per TBitmap, che permettono detto Canvas, che questo bitmap dovremmo disegnare con diversi sacle. Ad esempio, con Scala = 2. Si prega di utilizzare l'approccio seguente:

  1. Fai bitmap con la dimensione fisica (ad esempio sulla scala = schermo 2, PhysicalWidth = LogicalWidth * Scala)
  2. (Bitmap come IBitmapAccess) .BitmapScale = 2

Dopo che TCanvas disegnerà questa bitmap con una maggiore qualità.

prega, guardare a questo articolo: http://fire-monkey.ru/page/articles/_/articles/graphics/graphics-screenshot

E 'sulla Russia, ma il codice in inglese :-) e usa un codice da questo articolo con il mio suggerimento di cui sopra ((Bitmap come IBitmapAccess) .BitmapScale = 2)

Grazie

3

Sembra che questo sia un bug. Inviato a Quality Central: http://qc.embarcadero.com/wc/qcmain.aspx?d=119609

+0

Si noti che [QualityCentral è stato chiuso] (https://community.embarcadero.com/blogs/entry/quality-keeps-moving-forward), quindi non è più possibile accedere ai collegamenti 'qc.embarcadero.com' . Se è necessario accedere ai vecchi dati QC, consultare [QCScraper] (http://www.uweraabe.de/Blog/2017/06/09/how-to-save-qualitycentral/). –

1

Ho lo stesso problema. Il mio unico rimedio finora è: 1. Creare un nuovo TBitmap (Temp) e lavorare con la bitmap appena creata per fare tutto ciò che la Bitmap dell'immagine avrebbe dovuto fare. 2. Dopo che tutto è stato disegnato su questa Bitmap Temp, assegnare Temp bitmap all'esempio Image: Image1.MultiResBitmap.Items [1] .assign (TempBitmap). 3. Impostare la modalità di avvolgimento dell'immagine su IWStretch.

Questa soluzione ha funzionato per me, tuttavia ha causato un rendering più lento per l'immagine. Spero davvero che il problema si risolva presto.

procedure Form1.Draw; 
var 
TempBmp : FMX.Graphics.TBitmap; 
begin 
    TempBmp := FMX.Graphics.TBitmap.Create; 
    TempBmp.SetSize(round(Image1.Width),round(Image1.Height)); 
    with TempBmp.Canvas do 
    begin 
    //Work with the TempBmp here 
    end; 
    Image1.MultiResBitmap.Bitmaps[1].Assign(TempBmp); 
    Image1.Bitmap := Image1.MultiResBitmap.Bitmaps[1]; 
    TempBmp.Free; 
end; 
+0

Grazie Christo, proverò la soluzione. Spero che questo sarà risolto nella prossima patch XE5. – norgepaul

Problemi correlati