Einzelnen Beitrag anzeigen

TUX_der_Pinguin

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

Bitmap mit bestimmter DPI erstellen

  Alt 15. Mai 2009, 07:52
Hi DPler,

ich bastel mal wieder an einem Rave Projekt rum, ich habe einen Report mit einer Bitmap Komponente desen größe ist 180mm x 125 mm
jetzt möchte ich ein Bild an diese Komponente übergeben, dazu erstelle ich ein Bitmap und fange an darauf "rum zu malen". Alles
wunderbar jetzt geht es nur um die größe des Bitmaps. Erstell ich ein Bitmap so hat dieses Bitmap 96 DPI aber das ist zu
wenig, das Bild sieht nachher total pixelig aus, darum dachte ich ich erstelle das Bild mit 600 DPI.

Will ich also ein Bild mit der größe 18 x 12,5 cm bei 600 Dpi haben so muß dieses 4252 x 2953 pixel groß sein.
Die Formel dazu lautet pixel = mm * (dpi / 25,4), Beispiel: 4252 = 180 * (600 / 25,4).

Alles kein Problem nur hat mein erstelltes Bild immer noch eine Dpi von 96 und nicht 600. Ich brauche ein Bitmap oder
irgendeine Zeichenfläche die ich mit 600 Dpi erstellen kann, anschließend auf 1/10 mm Einteilung einstellen kann.
Um darauf in mm Angaben zu zeichnen. Damit ich direkt erblicken kann wie groß wird das was ich zeichne auf dem Report.


Mein bisheriger Versuch:
Delphi-Quellcode:
 Bitmap := TBitmap.Create;
  try
    try
      //Farbtiefe
      Bitmap.PixelFormat := pf4bit;

      //Größe des Bitmaps
      Bitmap.SetSize(Round(180 * (600 / 25.4)), Round(125 * (600 / 25.4)));

      //Bitmap in 1/10 mm Einteilung
      OutDC := Bitmap.Canvas.Handle;
      SetMapMode(OutDC,MM_LOMETRIC);
      GetWindowExtEx(OutDC,w);
      GetViewportExtEx(OutDC,v);
      SetMapMode(OutDC,MM_ANISOTROPIC);
      SetWindowExtEx(OutDC,w.cx,w.cy,nil);
      SetViewPortExtEx(OutDC,v.cx,-v.cy,nil);

      //Ränder-Einstellungen
      L_Margin := 0;
      T_Margin := 0;

      //Der Teil wird nicht benötigt, da es keinen Mindestrand gibt wie bei einem Drucker
      //OffSetX := GetDevicecaps(OutDC,PHYSICALOFFSETX) / GetDevicecaps(OutDC,LOGPIXELSX) * 25.4;
      //OffSetY := GetDevicecaps(OutDC,PHYSICALOFFSETY) / GetDevicecaps(OutDC,LOGPIXELSY) * 25.4;
      //L_Margin := LeftMargin - Round((OffSetX*10));
      //T_Margin := TopMargin - Round((OffSetY*10));

      //Bild 1
      With Graph1.Draw Do Begin
        Pos.Left := L_Margin+50;
        Pos.Top := T_Margin;
        Pos.Width := 850;
        Pos.Height := 550;

        Margin.Top := 50; {Abstand zum oberen Rand}
        Margin.Left := 120; {Abstand zum linken Rand}
        Margin.Right := 90; {Abstand zum rechten Rand}
        Margin.Bottom := 50; {Abstand zum unteren Rand}

        Font := TFont.Create;
        Font.Name := 'Arial';
        Font.Height := 32;
        Font.Style := [];

        LabelDist.X := 10;
        LabelDist.Y := 10;

        DPI.Horz := GetDeviceCaps(OutDC, LOGPIXELSX);
        DPI.Vert := GetDeviceCaps(OutDC, LOGPIXELSY);
      End;{with Graph1.Draw}

      //Bild 2
      With Graph2.Draw Do Begin
        Pos.Left := L_Margin+50+870;
        Pos.Top := T_Margin;
        Pos.Width := 850;
        Pos.Height := 550;

        Margin.Top := 50; {Abstand zum oberen Rand}
        Margin.Left := 120; {Abstand zum linken Rand}
        Margin.Right := 90; {Abstand zum rechten Rand}
        Margin.Bottom := 50; {Abstand zum unteren Rand}

        Font := TFont.Create;
        Font.Name := 'Arial';
        Font.Height := 32;
        Font.Style := [];

        LabelDist.X := 10;
        LabelDist.Y := 10;

        DPI.Horz := GetDeviceCaps(OutDC, LOGPIXELSX);
        DPI.Vert := GetDeviceCaps(OutDC, LOGPIXELSY);
      End;{with}

      //Bild 3
      With Graph3.Draw Do Begin
        Pos.Left := L_Margin+50;
        Pos.Top := T_Margin+570;
        Pos.Width := 1720;
        Pos.Height := 550;

        Margin.Top := 50; {Abstand zum oberen Rand}
        Margin.Left := 120; {Abstand zum linken Rand}
        Margin.Right := 90; {Abstand zum rechten Rand}
        Margin.Bottom := 50; {Abstand zum unteren Rand}

        Font := TFont.Create;
        Font.Name := 'Arial';
        Font.Height := 32;
        Font.Style := [];

        LabelDist.X := 10;
        LabelDist.Y := 10;

        DPI.Horz := GetDeviceCaps(OutDC, LOGPIXELSX);
        DPI.Vert := GetDeviceCaps(OutDC, LOGPIXELSY);
      End;{with}

      //Grafik zeichnen...
      pGraph_Draw(Bitmap.Canvas, True);

      //Speichern...
      Bitmap.SaveToFile(glLocalAppDir+'bla.bmp');

      //Bild in Report laden...
      MemStream := TMemoryStream.Create;
      try
        Bitmap.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
    Bitmap.Free;
  end;{try..finally}
  Mit Zitat antworten Zitat