Autor Beitrag
initrc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 20

Debian 3.1 sarge, FreeBSD, Windows 2000

BeitragVerfasst: Fr 25.03.05 23:06 
Hallo,

ich habe schon das Forum durchsucht, bin aber leider nicht so richtig fündig geworden.

Ich habe vor ein Bild (nur JPG), über einen OpenPictureDialog einzulesen und dann in ein Variable vom Typ TImage einzulesen (sorry 2x aber mir fällt kein anderes Wort dazu ein).

Mein kurze Frage ich jetzt wie kann ich das OpenPictureDialog.Filename in Bild:TImage einlesen?

Danke schomal für eure Antworten.

Borland Delphi 7.0 Personal
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Fr 25.03.05 23:17 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm1.Button1Click(Sender: TObject);
var
  Bild: TPicture;
begin
  Bild := TPicture.Create;
  OpenPictureDialog1.Execute;
  Bild.LoadFromFile(OpenPictureDialog1.FileName);
  Image1.Picture := Bild;
end;

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
initrc Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 20

Debian 3.1 sarge, FreeBSD, Windows 2000

BeitragVerfasst: Fr 25.03.05 23:34 
Okay, das leuchtet mir ein, danke für den Tipp.

Funktioniert auch soweit ganz gut, aber leider nicht mir JPG, BMP funzt.

Diesen Fehler bekomme ich, sobald ich ein JPG Bild auswähle:

"ProjectXYZ foobar.exe raised exception class EInvalidGraphic with message "Unknown picture file extension (.jpg)' Process stopped. Use .... *blubb*"

Gibt es evtl. noch was Anderes außer TPicture?

Gruß und danke
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Fr 25.03.05 23:41 
Lass alles so und schreib in die Uses "JPEG". Schon geht's.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
initrc Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 20

Debian 3.1 sarge, FreeBSD, Windows 2000

BeitragVerfasst: Fr 25.03.05 23:53 
Okay, das klappt alles, danke!

Nochmal eine Frage, hat TPicture irgendwelche Funktionen um die Größe der Bilder zu verändern?

Ich habe schon etwas über TJPGImage gelesen, der hat ja sogar Komprimierungsmöglichkeiten, aber wie sieht es da bei TPicture aus? Und wie könnte ich meine Variable "Bild" jetzt verkleinern?

Gruß
initrc Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 20

Debian 3.1 sarge, FreeBSD, Windows 2000

BeitragVerfasst: Sa 26.03.05 00:37 
Wenn ich das mit
Bild.Width := 300
probiere bekomme ich folgenden Fehler

Zitat:
cannot assign to a read-only property


wie kann ich den "read-only"- "Modus" entfernen?

Danke im Voraus!

Gruß
wdbee
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 628
Erhaltene Danke: 1



BeitragVerfasst: Sa 26.03.05 09:38 
Wenn du dir in der Delphi-Hilfe den Text zu TJPEGImage anschaust, siehst du, dass das so nicht vorgesehen ist. Wenn du dein Bild verändern willst, musst du es in ein Bitmap umwandeln:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
var
  oPicture: TJPEGImage;
  oBitmap: TBitmap;
...
  if OpenPictureDialog.Execute then
  begin
    if oPicture <> nil then           // Falls schon mal benutzt
      oPicture.Free;                  //   alte Instanz freigeben
    oPicture := TJPEGImage.Create;
    oPicture.LoadFromFile(OpenPictureDialog.Filename);
    Image.Picture.Assign(oPicture);   // JPeg direkt anzeigen: Read only   ...  aber  ...
    if oBitmap <> nil then            // Falls schon mal benutzt
      ooBitmap.Free;                  //   alte Instanz freigeben
    oBitmap := TBitmap.Create;      
    oBitmap.Assign(oPicture);
    Image.Picture.Assign(oBitmap);    // Via Bitmap anzeigen: Bild kann bearbeitet werden
  end;


Wenn du das veränderte Bild wieder als JPEG speichern willst, musst du dann das ganze wieder umgekehrt machen:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
  if SavePictureDialog.Execute then
  begin
    if (oPicture = nilor (oBitmap = nilthen       
      Exit;

    oPicture.Assign(oBitmap);                     // JPEG-Org. durch bearbeitetes Bitmap ersetzen
    oPicture.CompressionQuality := 100;           // Qualität 0 bis 100% 
    ...                                           // und ggf. andere Einstellungen
    oPicture.SaveToFile(SavePictureDialog.Filename);
  end;
initrc Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 20

Debian 3.1 sarge, FreeBSD, Windows 2000

BeitragVerfasst: Sa 26.03.05 10:16 
Okay, ich danke dir für deine Antwort. Ich werde das mal ausprobieren...

Grusz
initrc Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 20

Debian 3.1 sarge, FreeBSD, Windows 2000

BeitragVerfasst: Sa 26.03.05 10:41 
Das hat so alles Super geklappt, hab auch verstanden, was ich dort mache, aber jetzt tauchen zwei neue Fragen auf:

1.) was genau macht nil
2.) Ich habe jetzt das bmp mit bmp.Height und bmp.Width verkleinert, leider verkleinert er nicht das Bild an sich, sondern er schneidet das Bild auf die größe aus. Wie kann ich das so machen, das er es nur "zusammenzieht"?


Gruß
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Sa 26.03.05 10:46 
Zitat:
The Nil constant is a pointer value that is defined as undetermined.

Use of a Nil pointer will result in an exception.

Nil is mostly used as a substitute for a Pointer parameter - it tells the routine that no Pointer value is available for this parameter.

Pointer variables are not set to Nil except in special circumstances, such as when creating a new object that contains pointers. This is because Delphi initialises the storage taken by a new object to 0's. A Nil pointer is one that has the value 0.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
initrc Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 20

Debian 3.1 sarge, FreeBSD, Windows 2000

BeitragVerfasst: Sa 26.03.05 11:41 
Okay das ist schonmal interessant.

Habe noch ein paar Sachen im Forum gefunden zum Thema Bilder verkleinern, aber so richtig verstanden habe ich das (noch) nicht.

Grusz
wdbee
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 628
Erhaltene Danke: 1



BeitragVerfasst: Sa 26.03.05 11:58 
TImage hat eine Eigenschaft Stretch. Wenn Stretch true ist, wir das Bild (TBitmap) so skaliert, dass es die Zeichenfläche des TImage in Höhe und Breite genau ausfüllt. Dabei wird nicht das Bild verkleiner oder vergößert, sondern nur die Abbildung.
initrc Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 20

Debian 3.1 sarge, FreeBSD, Windows 2000

BeitragVerfasst: Sa 26.03.05 12:08 
Nein, dass ist eigentlich nicht das Problem.

Ich lese das Bild über OpenPictureDialog ein, wende den Algorytmus an (jpg -> bmp -> bearbeiten -> jpg)

Wenn ich nun das bearbeitete Jpg (bearbeitet durch Width und height) wieder abspeichern will, (per SavePictureDialog) ist die Ausgabe, also das bild was er abspeichert auf die eingegebene Größe beschnitten und nicht verkleinert.

Kann es sein, dass es etwas mit der Eigenschaft "Proportional" zu tun hat? So funktioniert es jedenfalls bei der Ausgabe in eine "Image.Picture".

Danke schonmal!

Grusz
wdbee
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 628
Erhaltene Danke: 1



BeitragVerfasst: Sa 26.03.05 12:36 
Wenn du das Bild und nicht die Anzeige ändern willst, wird es immer Qualitätsverluste geben, da die Bilder Rasterbilder sind. Möglich ist es, das ursprüngliche Bitmap mit StretchDraw in einen Bitmap.Canvas einer zweiten Bitmap zu zeichnen und dann die zweite Bitmap zu speichern
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
var
  Bitmap1: TBitmap;
  Bitmap2: TBitmap;
begin
  Bitmap1 := TBitmap.Create;
  Bitmap1.LoadFromFile('Test100x100.bmp');
  Bitmap2 := TBitmap.Create;
  Bitmap2.Width := Bitmap1.Width div 2;
  Bitmap2.Height := Bitmap1.Height div 2;
  Bitmap2.Canvas.StretchDraw(Rect(0,0,Bitmap2.Width-1,Bitmap2.Height-1),Bitmap1);
  Bitmap2.SaveToFile('Test50x50.bmp');
  Bitmap1.Free;
  Bitmap2.Free;
end;
initrc Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 20

Debian 3.1 sarge, FreeBSD, Windows 2000

BeitragVerfasst: Sa 26.03.05 13:07 
Sehr gut! Hat funktioniert! Danke...

Jetzt kann ich mich ranmachen!

Danke euch allen für die Hilfe, super Community!
MSC
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 63

Win XP Home, Win Vista Buisiness
Delphi 7 Enterprise
BeitragVerfasst: Fr 08.09.06 22:36 
Hi! Bin neu hier.

Ich habe ein ähnliches Problem:
Wenn ich nen Butten1 klicke soll in einem Image ein bmp 1 erscheinen.
Und wenn ich Button2 klicke soll bmp 2 erscheinen ect.

Ich will es umgehen, das ich z.B. 20 Images hab, und die dann einzeln Visible True/False machen muss.

edit: Bzw. möchte ich über einen Timer eine art Animation erreichen, der dann verschidene Bilder nacheinander in einem Image Element anzeigt.
Oder ist da Image nicht das richtige, und ich sollte etwas anderes nehmen, was auch BMP anzeigen kann und mit transparenter Fabe arbeiten kann?

Könnte mir da jemand helfen? :)
jakobwenzel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1889
Erhaltene Danke: 1

XP home, ubuntu
BDS 2006 Prof
BeitragVerfasst: Sa 16.09.06 17:33 
Neue Frage --> neuer Thread.

_________________
I thought what I'd do was, I'd pretend I was one of those deaf-mutes.
MSC
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 63

Win XP Home, Win Vista Buisiness
Delphi 7 Enterprise
BeitragVerfasst: Sa 16.09.06 23:57 
Titel: OK
Vielen Dank, wusste nicht wie das hier ist :)