Autor Beitrag
draco
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 21



BeitragVerfasst: Mo 26.06.06 21:02 
Hallo,
ich will Jpeg Bilder verkleinern und hab auf swissdelphicenter.ch folgenden cod zum resmpeln einer Bitmapdatei gefunden:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
type
  PBitmap = ^TBitmap;
  TLine = array[0..MaxInt div SizeOf(TRGBQUAD) - 1] of TRGBQUAD;
  PLine = ^TLine;


function ResampleSubBitmap(Bitmap: TBitmap; XPos, YPos, Width, Height: Integer): TRGBQuad;
var
  r, g, b: Cardinal;
  Line: PLine;
  x, y, z: Integer;
begin
  z := (Width * Height);
  r := 0;
  g := 0;
  b := 0;

  //Grenzüberschreitungen abfangen
  if (YPos + Height) >= Bitmap.Height then Height := (Bitmap.Height - YPos) - 1;
  if (XPos + Width) >= Bitmap.Width then Width := (Bitmap.Width - XPos) - 1;

  //Für jedes Pixel die Werte lesen und aufaddieren
  for y := YPos to YPos + Height do
  begin
    Line := Bitmap.ScanLine[y];
    for x := XPos to XPos + Width do
    begin
      r := r + Line[x].rgbRed;
      g := g + Line[x].rgbGreen;
      b := b + Line[x].rgbBlue;
      Inc(z);
    end;
  end;

  if (z = 0) then z := 1;
  //Mittelwert bestimmen und kleine Helligkeitskorrektur
  r := Round((r / z) * 1.4);
  if (r > 255) then r := 255;
  g := Round((g / z) * 1.4);
  if (g > 255) then g := 255;
  b := Round((b / z) * 1.4);
  if (b > 255) then b := 255;

  Result.rgbRed   := r;
  Result.rgbGreen := g;
  Result.rgbBlue  := b;
end;

function ResampleBitmap(Bitmap: TBitmap; NewWidth, NewHeight: Integer): Boolean;
var
  Temp: TBitmap;
  Line: PLine;
  x, y: Integer;
  Blockheight, Blockwidth: Cardinal;
  BlockPosX, BlockPosY: Single;
  BlockDiffX, BlockDiffY: Single;
  XPos, YPos: Single;
  DiffX, Diffy: Single;
begin
  Result := True;

  //Arbeitsbitmap erzeugen
  Temp := TBitmap.Create;

  //Alles muß 32 Bit sein
  Bitmap.PixelFormat := pf32Bit;
  Temp.PixelFormat   := pf32Bit;

  //Neue Höhe unseres Bitmap
  Temp.Height := NewHeight;
  Temp.Width  := NewWidth;

  //Altes Bild in Blöcke zerlegen, deren jeweiliger Mittelwert die Farbe
  //eines neuen Pixels bildet
  //Blockschrittweite pro neues Pixel
  BlockDiffY := (Bitmap.Height / NewHeight);
  BlockDiffX := (Bitmap.Width / NewWidth);
  //Größe eines Blockes
  BlockHeight := Trunc(BlockDiffY);
  BlockWidth  := Trunc(BlockDiffY);


  //Schrittweite der Pixel im neuen Bild
  DiffX := 1;
  DiffY := 1;

  //Alle initialisieren
  BlockPosY := 0;
  YPos      := 0;
  //Jede Spalte
  for y := 0 to NewHeight - 1 do
  begin
    BlockPosX := 0;
    XPos      := 0;
    //Jede Zeile
    Line := Temp.ScanLine[Trunc(YPos)];
    for x := 0 to NewWidth - 1 do
    begin
      //Aus einem angegebenen Block des alten Bitmaps den Mittelwert der
      //Farbe bestimmen
      Line[Trunc(XPos)] := ResampleSubBitmap(Bitmap,
        Round(BlockPosX), Round(BlockPosY), Blockwidth, BlockHeight);

      //Einen Block/Pixel weiter
      BlockPosX := BlockPosX + BlockDiffX;
      XPos      := XPos + DiffX;
    end;
    //Einen Block/Pixel weiter
    BlockPosY := BlockPosY + BlockDiffY;
    YPos      := YPos + DiffY;
  end;
  //Alte Bitmap mit der neuen überschreiben
  Bitmap.Assign(Temp);

  //Hilfsbitmap freigeben
  Temp.Free;
end;


// Beispiel:
// Example:
procedure TForm1.Button1Click(Sender: TObject);
begin
  ResampleBitmap(Image1.Picture.Bitmap, 30, 30);
end;

Nun meine Frage:
Was muss ich ändern damit ich jpg Dateien verkleinern und resamplen kann?
Ich hoffe das die Frage hier richtig ist.

MfG
Tom Schneider
Kroko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1284

W98 W2k WXP
Turbo D
BeitragVerfasst: Di 27.06.06 05:48 
user profile icondraco hat folgendes geschrieben:
...
Nun meine Frage:
Was muss ich ändern damit ich jpg Dateien verkleinern und resamplen kann?
Ich hoffe das die Frage hier richtig ist.

MfG
Tom Schneider


Die Bilder in Bitmap umwandeln????

_________________
Die F1-Taste steht nicht unter Naturschutz und darf somit regelmäßig und oft benutzt werden! oder Wer lesen kann, ist klar im Vorteil!
draco Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 21



BeitragVerfasst: Di 27.06.06 14:19 
nein was ich an dem code ändern muss das ich wenn ich in die image Komponente ein Jpg bBild lade ich das dann auch nachher als JPG speichern kann.
Hoffe man versteht was ich meine
Kroko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1284

W98 W2k WXP
Turbo D
BeitragVerfasst: Mi 28.06.06 07:37 
(a) JPG in BMP
(b) bearbeiten
(c) Bmp in Jpg
(d) speichern!

_________________
Die F1-Taste steht nicht unter Naturschutz und darf somit regelmäßig und oft benutzt werden! oder Wer lesen kann, ist klar im Vorteil!
draco Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 21



BeitragVerfasst: Mi 28.06.06 13:35 
OK danke