alex1496
Messages postés10Date d'inscriptionlundi 9 février 2004StatutMembreDernière intervention 1 mars 2007
-
27 févr. 2007 à 23:43
Lucyberad
Messages postés414Date d'inscriptionmercredi 16 juin 2004StatutMembreDernière intervention26 juillet 2007
-
1 mars 2007 à 23:31
Mon programme calcule le ferraillage d'un poteau béton. L'utilisateur
entre les données, et lance le calcul qui aboutit sur le dessin du
poteau et une note de calcul que je genère en HTML.
L'image est enregistrée sur mon disque et est affichée dans une picturebox et dans la note de calcul en HTML.
Tout cela marche mais si je relance le calcul ça plante avec mon erreur de GDI+.
Je n'arrive pas à comprendre si c'est parce que l'image est utilisé que je n'arrive pas à l'afficcher de nouveau.
MON CODE
Private
Sub menu_Calculer(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles barre_calculer.Click, mnu_calculer.Click
...blablablabla....
'--- Affichage dessin ---
'Image de support
'pic.Dispose()
Dim img As Bitmap = New Bitmap(pic.Width, pic.Height)
'Dim img As New Bitmap(file_img_p)
'frm_note.Close()
'pic.Image = Nothing
'Paramètres de transformation
Dim ajust As ajustage = Ajuste_section(section, pic)
'Trace
Call Trace_section(section, img, ajust)
Call Trace_section(section_Br, img, ajust)
'Affichage sur la picturebox
Try
Image.FromFile(file_img_p).Dispose()
img.Save(file_img_p, ImageFormat.Gif)
pic.Image = Image.FromFile(file_img_p)
Catch ex As Exception
Console.WriteLine(">>>" & ex.Message)
End Try
Public Sub Trace_section(ByRef tableau() As PointF, ByVal img As Bitmap, ByVal ajust As ajustage)
'Trace une image à partir d'un tableau
Dim tableau_trace() As PointF
tableau_trace = tableau.Clone
'Tableau affichage
For i As Integer = 0 To tableau_trace.GetUpperBound(0)
tableau_trace(i).X = tableau(i).X * ajust.echelle.dx + ajust.vecteur.dx
tableau_trace(i).Y = tableau(i).Y * ajust.echelle.dy + ajust.vecteur.dy
Next i
'Créer une image en fonction de la picturebox
Dim graph As Graphics = Graphics.FromImage(img)
'graph.FromImage(img)
'Dessin
graph.FillRectangle(Brushes.White, New Rectangle(0, 0, img.Width, img.Height))
graph.DrawPolygon(Pens.Red, tableau_trace)
'Dim img1 As Image = New Bitmap(img.Width, img.Height, graph)
'img1.Save("c:\essai.bmp") ', ImageFormat.Bmp)
'Affichage sur la picturebox
img.Save(file_img_p, ImageFormat.Bmp)
pic.Image = img
graph.Dispose()
end sub
Public Sub Trace_section(ByRef tableau() As PointF, ByVal img As Bitmap, ByVal graph As Graphics, ByVal ajust As ajustage)
'Trace une image à partir d'un tableau
Dim tableau_trace() As PointF
tableau_trace = tableau.Clone
'Tableau affichage
For i As Integer = 0 To tableau_trace.GetUpperBound(0)
tableau_trace(i).X = tableau(i).X * ajust.echelle.dx + ajust.vecteur.dx
tableau_trace(i).Y = tableau(i).Y * ajust.echelle.dy + ajust.vecteur.dy
Next i
alex1496
Messages postés10Date d'inscriptionlundi 9 février 2004StatutMembreDernière intervention 1 mars 2007 27 févr. 2007 à 23:45
C'est ce que j'ai reussi à recupérer de l'erreur :
L'exception System.Runtime.InteropServices.ExternalException n'a pas été gérée
ErrorCode=-2147467259
Message="Une erreur générique s'est produite dans GDI+."
Source="System.Drawing"
StackTrace:
à System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams)
à System.Drawing.Image.Save(String filename, ImageFormat format)
à WindowsApplication1.frm_poteau.menu_Calculer(Object sender, EventArgs e) dans N:\PROG_VB2005\CABA\frm_poteau.vb:ligne 235
à System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
à System.Windows.Forms.ToolStripButton.OnClick(EventArgs e)
à System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
à System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
à System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
à System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
à System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
à System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
à System.Windows.Forms.Control.WndProc(Message& m)
à System.Windows.Forms.ScrollableControl.WndProc(Message& m)
à System.Windows.Forms.ToolStrip.WndProc(Message& m)
à System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
à System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
à System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
à System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
à System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
à System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
à System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
à System.Windows.Forms.Application.Run(ApplicationContext context)
à Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
à Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
à Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
à WindowsApplication1.My.MyApplication.Main(String[] Args) dans 17d14f5c-a337-4978-8281-53493378c1071.vb:ligne 81
à System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
à System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
à Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
à System.Threading.ThreadHelper.ThreadStart_Context(Object state)
à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
à System.Threading.ThreadHelper.ThreadStart()
Moi j'y comprends rien
Lucyberad
Messages postés414Date d'inscriptionmercredi 16 juin 2004StatutMembreDernière intervention26 juillet 20073 1 mars 2007 à 23:31
la tu utilise le BMP, c'est vachement lourd comme fichier.
si la taille ne t'importe pas et que tu a plutot besoin de vitesse de traitement, ok pour le BMP, sinon pour alleger les images: utilise le Jpeg.
comme je te l'ai repondu a ton MP, la premiere ligne:
Image.FromFile(file_img_p).Dispose()
ne sert a rien.
ensuite je crois savoir pourquoi: probablement que la methode Save fait un travail asynchrone, et que la deuxieme essaye de charger un fichier en cours d'edition... peut-être, en tout cas à essayer !
img.Save(file_img_p, ImageFormat.Bmp)
pic.Image = Image.FromFile(file_img_p)