Autor Beitrag
Bayo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 39



BeitragVerfasst: Fr 28.06.02 13:00 
Hi zusammen....

Ich möchte gerne entweder mit einem TBitmap oder einem TJPEGImage ein Bild laden, die Grösse des Bildes verändern und es wieder als JPG bzw. BMP speichern. Hat evtl. schon mal jemand von euch etwas in der Art gemacht?? Bin dankbar für jede Anregung!!

Grüsse Dominic
DeCodeGuru
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1333
Erhaltene Danke: 1

Arch Linux
Eclipse
BeitragVerfasst: Fr 28.06.02 13:05 
Also, ich habe das mal so gelöst:

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TForm1.ResizeImage(newWidth,newHeight: Integer); 
begin 
  SetStretchBltMode(Image2.Canvas.Handle, Halftone); 
  StretchBlt(Image2.Canvas.Handle, 0,0,newwidth,newheight,Image1.Canvas.Handle,0,0,Image1.Width,Image1.Height,SRCCOPY); 
end; 

procedure TForm1.Button1Click(Sender: TObject); 
begin 
  ResizeImage(100,50); 
end;



In Image1 wird das Bild geladen und in Image2 wird es vergrößert oder verkleinert dargestellt.

_________________
Viele Grüße
Jakob
Bayo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 39



BeitragVerfasst: Fr 28.06.02 13:39 
Hi...

Erstamls bedanke ich mich für deine Antwort!!

Ich habe das mal probiert, leider erstellt er bei mir immer nur ein 0kb grosses Bild, auf dem nichts zu sehen ist :-(

Mein Code sieht folgendermassen aus:

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
procedure TForm1.Button1Click(Sender: TObject);
var
  bmp1, bmp2: TBitmap;

begin
  bmp1 := TBitmap.Create;
  bmp2 := TBitmap.Create;
  try
    if OpenDialog1.Execute then begin
      bmp1.LoadFromFile(OpenDialog1.FileName);
      SetStretchBltMode(bmp2.Canvas.Handle, Halftone);
      StretchBlt(bmp2.Canvas.Handle, 0, 0, 50, 50, bmp1.Canvas.Handle, 0, 0, bmp1.Width, bmp1.Height, SRCCOPY);
      bmp2.SaveToFile('Dominic.bmp');
    end;
  finally
    FreeAndNil(bmp1);
    FreeAndNil(bmp2);
  end;
end;


Ich habe in diesem Beispiel ein TBitmap genommen, könnte das evtl. der Fehler sein, muss ich evtl. eine andere Klasse nehmen??

Grüsse dominic
OregonGhost
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 215



BeitragVerfasst: Fr 28.06.02 18:58 
Der Fehler liegt vielleicht hier:
ausblenden Quelltext
1:
SetStretchBltMode(bmp2.Canvas.Handle, Halftone);					

Zitat:

HALFTONE:
Maps pixels from the source rectangle into blocks of pixels in the destination rectangle. The average color over the destination block of pixels approximates the color of the source pixels.
After setting the HALFTONE stretching mode, an application must call the SetBrushOrgEx function to set the brush origin. If it fails to do so, brush misalignment occurs.
This option is not supported on Windows 95/98/Me.

Mit anderen Worten: HALFTONE produziert zwar die besten Ergebnisse, aber wird nur unter Windows NT unterstützt. Also hast du wahrscheinlich ein Windows 9x. Oder es liegt am fehlenden Aufruf von SetBrushOrgEx().
Also: Wenn du 9x hast, verwende statt HALFTONE einfach BLACKONWHITE oder COLORONCOLOR, wenn du NT hast, füge einen Aufruf von SetBrushOrgEx() ein.

_________________
Oregon Ghost
---
Wenn NULL besonders groß ist, ist es fast schon wie ein bisschen eins.