Einzelnen Beitrag anzeigen

TUX_der_Pinguin

Registriert seit: 1. Jun 2005
Ort: Anholt (NRW)
608 Beiträge
 
Delphi 11 Alexandria
 
#16

Re: Bitmap mit bestimmter DPI erstellen

  Alt 19. Mai 2009, 11:07
Ein Versuch die Grafikqualität zu erhöhen. Ich habe einen Versuch gestartet das ganze mit MetaFile umzusetzen, die Qualität
ist da durch auch enorm gestiegen. Jedoch ist das MetaFile auch irgendwie pixelig und nachher im Report/PDF auch.

Die Dateigröße des PDF ist auch viel zu viel, ein Ausdruck mit einem PDF drucker brachte eine Dateigröße von ca. 40 KB
und der Weg über den Rave Report bringt eine Datei mit einer größe von > 400 KB.

Delphi-Quellcode:
procedure TfrmGraph.RvCustConTAGraphGetRow(Connection: TRvCustomConnection);
var
  MemStream : TMemoryStream;
  DotsPerInch : Word;
  Wmf : TMetaFile;
  WmfCanvas : TMetaFileCanvas;

begin
  //init
  DotsPerInch := RvRenderPDF.MetafileDPI;

  Wmf := TMetaFile.Create;
  try
    try
      //Größe
      Wmf.SetSize(fMmToPx(1800, DotsPerInch), fMmToPx(1220, DotsPerInch));
      
      //Zeichenfläche erstellen
      WmfCanvas := TMetaFileCanvas.Create(Wmf, 0);
      try

        //Bild 1
        with Graph1.Draw do begin
          Pos.Left := fMmToPx(40, DotsPerInch);
          Pos.Top := fMmToPx(50, DotsPerInch);
          Pos.Width := fMmToPx(850, DotsPerInch);
          Pos.Height := fMmToPx(550, DotsPerInch);

          Margin.Top := fMmToPx(50, DotsPerInch); //Abstand zum oberen Rand
          Margin.Left := fMmToPx(120, DotsPerInch); //Abstand zum linken Rand
          Margin.Right := fMmToPx(90, DotsPerInch); //Abstand zum rechten Rand
          Margin.Bottom := fMmToPx(50, DotsPerInch); //Abstand zum unteren Rand

          Font := TFont.Create;
          Font.Name := 'Arial';
          Font.Height := fMmToPx(32, DotsPerInch);
          Font.Style := [];

          LabelDist.X := fMmToPx(10, DotsPerInch);
          LabelDist.Y := fMmToPx(10, DotsPerInch);

          DPI.Horz := DotsPerInch;
          DPI.Vert := DotsPerInch;
        end;{with Graph1.Draw}

        //Bild 2
        with Graph2.Draw do begin
          Pos.Left := fMmToPx(870+40, DotsPerInch);
          Pos.Top := fMmToPx(50, DotsPerInch);
          Pos.Width := fMmToPx(850, DotsPerInch);
          Pos.Height := fMmToPx(550, DotsPerInch);

          Margin.Top := fMmToPx(50, DotsPerInch); //Abstand zum oberen Rand
          Margin.Left := fMmToPx(120, DotsPerInch); //Abstand zum linken Rand
          Margin.Right := fMmToPx(90, DotsPerInch); //Abstand zum rechten Rand
          Margin.Bottom := fMmToPx(50, DotsPerInch); //Abstand zum unteren Rand

          Font := TFont.Create;
          Font.Name := 'Arial';
          Font.Height := fMmToPx(32, DotsPerInch);
          Font.Style := [];

          LabelDist.X := fMmToPx(10, DotsPerInch);
          LabelDist.Y := fMmToPx(10, DotsPerInch);

          DPI.Horz := DotsPerInch;
          DPI.Vert := DotsPerInch;
        end;{with}

        //Bild 3
        with Graph3.Draw do begin
          Pos.Left := fMmToPx(40, DotsPerInch);
          Pos.Top := fMmToPx(570+50, DotsPerInch);
          Pos.Width := fMmToPx(1720, DotsPerInch);
          Pos.Height := fMmToPx(550, DotsPerInch);

          Margin.Top := fMmToPx(50, DotsPerInch); //Abstand zum oberen Rand
          Margin.Left := fMmToPx(120, DotsPerInch); //Abstand zum linken Rand
          Margin.Right := fMmToPx(90, DotsPerInch); //Abstand zum rechten Rand
          Margin.Bottom := fMmToPx(50, DotsPerInch); //Abstand zum unteren Rand

          Font := TFont.Create;
          Font.Name := 'Arial';
          Font.Height := fMmToPx(32, DotsPerInch);
          Font.Style := [];

          LabelDist.X := fMmToPx(10, DotsPerInch);
          LabelDist.Y := fMmToPx(10, DotsPerInch);

          DPI.Horz := DotsPerInch;
          DPI.Vert := DotsPerInch;
        end;{with}

        //Grafik zeichnen...
        pGraph_Draw(WmfCanvas, False, True);

      finally
        WmfCanvas.Free;
      end;

      Wmf.SaveToFile(glLocalAppDir+'bla.wmf'); //Die Datei ist ca. 507 KB groß

      //Bild in Report laden...
      MemStream := TMemoryStream.Create;
      try
        Wmf.SaveToStream(MemStream);
        Connection.WriteBlobData(MemStream.Memory^, MemStream.Size);
      finally
        MemStream.Free;
      end;

    except
      on EOutOfResources do begin
        Application.MessageBox(PAnsiChar(fGetText(10212)), PAnsiChar(fGetText(MSG_ERROR)), 48);
        //Close;
      end;
    end;{try..except}

  finally
    Wmf.Free;
  end;{try..finally}

end;
  Mit Zitat antworten Zitat