Autor Beitrag
huuuuuh
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 665
Erhaltene Danke: 19

win xp, (win vista), win 7
VS 2008 Express Edition, VS 2010 Express Edition, VS 2010 Professionell
BeitragVerfasst: Sa 27.11.10 23:08 
hab zurzeit ein Problem und weiss absolut nicht, wie ich es beheben soll...
und zwar soll ein Bild geladen, woanders abgespeichert und im Programm angezeigt werden. wenn ich das Bild jedoch speichern will, kommt der Fehler: "Allgemeiner Fehler in GDI+."
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
 OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "PNG-Datei | *.png";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                texture_path.Text = ofd.FileName;
            }
            FileInfo finfo=new FileInfo(ofd.FileName);
            planetImage = Image.FromFile(ofd.FileName);
            
            plBox.Image = planetImage;
            planetImage.Save(@"Content\images\" + finfo.Name, ImageFormat.Png);//hier kommt der Fehler

ps. hab keine ahnung von GDI+ oder so. arbeite mit Windows Forms...
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4764
Erhaltene Danke: 1052

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: So 28.11.10 13:29 
Du solltest beim Abspeichern absolute Pfadnamen verwenden, denn durch die Verwendung des Open- bzw. SaveFileDialogs wird das aktuelle Verzeichnis geändert, so daß dann "Content\images\" nicht mehr gefunden werden kann.

Mit "absolute Pfadnamen" meine ich natürlich nicht hardcodierte Pfadangaben im Quelltext, sondern mittels Path.Combine zusammengesetzte Pfade, z.B.:
ausblenden C#-Quelltext
1:
Path.Combine(Application.StartupPath, @"Content\images\")					


Alternativ könntest du auch noch "Open/SaveFileDialog.RestoreDirectory = true" setzen...

Edit:
Du solltest jedoch mittels Directory.Exists und evtl. Directory.CreateDirectory sicherstellen, daß der Pfad auch wirklich existiert.

Für diesen Beitrag haben gedankt: huuuuuh
huuuuuh Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 665
Erhaltene Danke: 19

win xp, (win vista), win 7
VS 2008 Express Edition, VS 2010 Express Edition, VS 2010 Professionell
BeitragVerfasst: So 28.11.10 13:59 
vielen dank, das fehlende Directory.CreateDirectory wars. :autsch: