ERLEDIGT
NEIN
NEIN
ANTWORTEN
2
2
ZUGRIFFE
365
365
EMPFEHLEN
-
13.08.07 10:02 #1
Hallo zusammen,
bastle gerade an einem Projekt, in dem man Bilder zoomen kann. Doch leider nach einer bestimmten Größe - vermute ich - schmiert mir die Anwendung ab. Komisch ist nur, dass das erste zoomen (1. Bild) klappt und das zweite nicht.
Zum besseren Verständnis : ich habe ein Verzeichnis, in dem Bilder liegen, dass in der untenstehenden Methode mit FileList betitelt ist. Nun kann ich durch die Bilder blättern, wie in einem Imageviewer. Das Problem ist halt der Zoom. Habe ich das erste oder auch das 3. Bild auf Maximum gezoomt und gehe damm ein Bild weiter, stellen sich alle Werte wieder zurück auf normal und man kann wieder aus- oder einzoomen. Doch bei 12x zoom ist schluß.
Hier mal zwei Methoden :
Diese beiden Methoden blättern einmal vor und zoomen ein.Code :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 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
int zoomAktuell = -1; double[] zoom = {0.06,0.08,0.12,0.17,0.25,0.33,0.50,0.67,1,2,3,4,5,6,7,8,12,16}; int imageOrgWidth; int imageOrgHeight; void TsBildVorClick(object sender, EventArgs e) { this.pictureBox1.Image = null; GC.Collect(); int internalHeight = this.toolStripContainer1.Height-(this.toolStrip1.Height*2)-this.statusStrip1.Height; if(this.selected_image < this.FileList.Count-1) { this.selected_image +=1; this.pictureBox1.Image = Image.FromFile(FileList[this.selected_image].ToString()); Bitmap bmp = new Bitmap(FileList[this.selected_image].ToString()); this.imageOrgWidth = bmp.Size.Width; this.imageOrgHeight = bmp.Size.Height; this.zoomAktuell = -1; //--- BildInfos start --- string breite = bmp.Size.Width.ToString(); string hoehe = bmp.Size.Height.ToString(); string aufloesung = bmp.HorizontalResolution.ToString(); string farbtiefe = ""; if(Path.GetExtension(this.FileList[this.selected_image].ToString()) == ".gif" || Path.GetExtension(this.FileList[this.selected_image].ToString()) == ".GIF") { if(bmp.PixelFormat.ToString().Substring(6,2) == "32") farbtiefe = "8"; else if(bmp.PixelFormat.ToString().Substring(7,1) == "b") farbtiefe = bmp.PixelFormat.ToString().Substring(6,1); } else if(bmp.PixelFormat.ToString().Substring(7,1) == "b") farbtiefe = bmp.PixelFormat.ToString().Substring(6,1); else if(Path.GetExtension(this.FileList[this.selected_image].ToString()) != ".gif" || Path.GetExtension(this.FileList[this.selected_image].ToString()) != ".GIF") farbtiefe = bmp.PixelFormat.ToString().Substring(6,2); this.statusLabel2.Text = breite+" x "+hoehe+" x "+farbtiefe+" Bit | "+aufloesung+" dpi"; //-- BildInfos ende --- if(bmp.Size.Height > Screen.PrimaryScreen.WorkingArea.Height || bmp.Size.Width > Screen.PrimaryScreen.WorkingArea.Width) { if(bmp.Size.Height > bmp.Size.Width) { this.pictureBox1.Height = internalHeight; //this.pictureBox1.Height = Screen.PrimaryScreen.WorkingArea.Height-100; this.pictureBox1.Width = this.pictureBox1.Height * bmp.Size.Width / bmp.Size.Height; } else if(bmp.Size.Width > bmp.Size.Height) { this.pictureBox1.Width = Screen.PrimaryScreen.WorkingArea.Width; this.pictureBox1.Height = this.pictureBox1.Width * bmp.Size.Height / bmp.Size.Width; if(this.pictureBox1.Height > internalHeight) { this.pictureBox1.Height = internalHeight; this.pictureBox1.Width = this.pictureBox1.Height * bmp.Size.Width / bmp.Size.Height; } } } else { this.pictureBox1.Width = bmp.Size.Width; this.pictureBox1.Height = bmp.Size.Height; } int x = (this.toolStripContainer1.Width/2)-(this.pictureBox1.Width/2); int y = ((this.toolStripContainer1.Height-this.toolStrip1.Height-this.statusStrip1.Height)/2)-(this.pictureBox1.Height/2); this.pictureBox1.Location = new System.Drawing.Point(x,y); this.Text = Path.GetFileName(FileList[this.selected_image].ToString()); this.statusLabel1.Text = "Bild "+(this.selected_image+1).ToString()+" / "+this.FileList.Count.ToString()+" | "; if(this.selected_image > 0) { this.tsBildZurueck.Enabled = true; } if(this.selected_image == this.FileList.Count-1) this.tsBildVor.Enabled = false; bmp = null; GC.Collect(); } else { this.tsBildVor.Enabled = false; Application.DoEvents(); } this.ziehFlag = false; if(this.lvFiles.Items[this.selected_image].Checked == true) this.tsBildAusgewaehlt.Checked = true; else this.tsBildAusgewaehlt.Checked = false; this.tsZoomGroesser.Enabled = true; this.tsZoomKleiner.Enabled = true; } void TsZoomGroesserClick(object sender, EventArgs e) { int i; if(this.zoomAktuell == -1) { i=0; double prozent = (double)this.pictureBox1.Width / (double)this.imageOrgWidth; for(; i<zoom.Length-1;i++) { if(zoom[i] < prozent) { continue; } else { i+=1; break; } } this.zoomAktuell = i; } else { if(zoomAktuell >= zoom.Length-2) return; i=this.zoomAktuell+1; this.zoomAktuell = i; } if(this.imageOrgHeight > this.imageOrgWidth) { this.pictureBox1.Height = (int)Math.Round(this.imageOrgHeight * zoom[i]); this.pictureBox1.Width = this.pictureBox1.Height * this.imageOrgWidth / this.imageOrgHeight; } else if(this.imageOrgWidth > this.imageOrgHeight) { this.pictureBox1.Width = (int)Math.Round(this.imageOrgWidth * zoom[i]); this.pictureBox1.Height = this.pictureBox1.Width * this.imageOrgHeight / this.imageOrgWidth; } int x = (this.toolStripContainer1.Width/2)-(this.pictureBox1.Width/2); int y = ((this.toolStripContainer1.Height-this.statusStrip1.Height)/2)-(this.pictureBox1.Height/2); this.pictureBox1.Location = new System.Drawing.Point(x,y); if(i >= zoom.Length-2) { this.tsZoomGroesser.Enabled = false; } this.tsZoomKleiner.Enabled = true; }
Vielleicht hat ja jemand eine Idee, was ich falsch mache.
AsterixGeändert von Asterix-Ac (13.08.07 um 10:08 Uhr)
-
Probier ein bmp.Dispose() anstatt des bmp = null;. Damit werden die gebundenen Ressourcen freigegeben. Ein GC.Collect() sollte dann auch nicht mehr notwendig sein, da der Speicher ohnehin automatisch freigegeben wird.
-
14.08.07 18:46 #3
Hallo Norbert,
danke für Deine Antwort.
Leider hat das nichts gebracht. Die Applikation verabschiedet sich nach wie vor mit folgendem Fehlertext :
Was mich dabei irritiert, ist die Tatsache, dass immerwieder von UnsaveNativeMethods gesprochen wird. Doch ich nutze keine unsave-Methoden, oder unterbewusst doch?Code :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
Ausnahme System.ComponentModel.Win32Exception wurde im ausgeführten Programm ausgelöst: Der Vorgang wurde erfolgreich beendet CreateCompatibleDIB() CreateBuffer() AllocBuffer() AllocBufferInTempManager() Allocate() WmPaint() WndProc() OnMessage() WndProc() DebuggableCallback() System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop() RunMessageLoopInner() RunMessageLoop() ShowDialog() ShowDialog() TsAnsichtGrossesBildClick() - g:\Projekte-dotnet-20\Bilder-Assistent\MainForm.cs:398,5 RaiseEvent() OnClick() HandleClick() HandleMouseUp() FireEventInteractive() FireEvent() OnMouseUp() WmMouseUp() WndProc() WndProc() WndProc() OnMessage() WndProc() DebuggableCallback() System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop() RunMessageLoopInner() RunMessageLoop() Run() Main() - g:\Projekte-dotnet-20\Bilder-Assistent\MainForm.cs:40,4
Also ich habe ein MainForm und rufe ein zweites Form mit ShowDialog auf, dass als Viewer dienen soll.
Schaue ich mir die Bilder ohne zoom an, geht alles gut. Auch der 1. zoom geht gut. Aber der 2. löst diese Fehlermeldung aus. Aber erst bei Maximum zoom. Zugleich erscheint die Meldung, dass die Auslagerungsdatei zu klein ist und dass sie nun vergrößert wird.
Asterix
Ähnliche Themen
-
showConfirmDialog mit x schließen, Anwendung weiterlaufen lassen
Von Duckemai im Forum Swing, Java2D/3D, SWT, JFaceAntworten: 3Letzter Beitrag: 11.02.10, 13:29 -
[ANSI-C] anwendung unter win im hintergrund laufen lassen
Von matt im Forum C/C++Antworten: 3Letzter Beitrag: 04.09.09, 16:53 -
Zeit einer Anwendung anzeigen lassen
Von KleinesNadine im Forum JavaAntworten: 4Letzter Beitrag: 06.09.07, 19:53 -
Anwendung auf Thread warten lassen
Von The_Maegges im Forum .NET Windows FormsAntworten: 4Letzter Beitrag: 24.07.07, 19:02 -
eine anwendung auf jeden pc gleich schnell laufen lassen
Von coolerouny im Forum JavaAntworten: 4Letzter Beitrag: 10.05.05, 19:17





Zitieren
Login





