IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

fichier image bitmap verrouillé [Débutant]


Sujet :

VB.NET

  1. #1
    Membre averti
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Mars 2012
    Messages
    640
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Bâtiment

    Informations forums :
    Inscription : Mars 2012
    Messages : 640
    Points : 372
    Points
    372
    Par défaut fichier image bitmap verrouillé
    Bonsoir à tous,
    j'ai un fichier "preview.jpg" verrouillé, alors que il me semble avoir fait ce qu'il fallait dans mon code.
    Auriez vous une idée s'il vous plait, car je sèche complètement.
    Le code est un tantinet compliqué mais ça permet d'afficher un logo en Overlay.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
      Private Sub AfficheSkinAndLogo(Folder As String, SkinName As String)
            Dim PathBackImage As String = Folder & "\skins\" & SkinName & "\preview.jpg"
            Dim PathOverlayImage As String = Folder & "\ui\" & "badge.png"
     
            'Dim g As Graphics = Graphics.FromHwnd(pbCar2.Handle)
            'g.DrawImage(img, pbCar2.ClientRectangle)
            Dim BackImage As Bitmap = Nothing
            Dim OverLayImage As Bitmap = Nothing
     
            Try
                BackImage = New Bitmap(PathBackImage, True)
            Catch ex As Exception
     
            End Try
            Try
                OverLayImage = New Bitmap(PathOverlayImage, True)
            Catch ex As Exception
     
            End Try
            Dim BadgeSize As Single = 0.25
            Dim BadgePosX As Single = 0.05
            Dim BadgePosY As Single = 0.1
            If OverLayImage IsNot Nothing AndAlso BackImage IsNot Nothing Then
                Dim RatioImg As Single = CSng(OverLayImage.Width / OverLayImage.Height)
                Dim g As Graphics = Graphics.FromImage(BackImage)
                Dim Larg As Integer = BackImage.Width
                Dim Haut As Integer = CInt(Larg / RatioImg)
                If Haut > BackImage.Height Then
                    Haut = CInt(BackImage.Height * BadgeSize)
                    Larg = CInt(Haut * RatioImg)
                Else
                    Larg = CInt(BackImage.Width * BadgeSize)
                    Haut = CInt(Larg / RatioImg)
                End If
                Dim PosX As Integer = CInt((BackImage.Width - Larg) * BadgePosX)
                Dim PosY As Integer = CInt((BackImage.Height - Haut) * BadgePosY)
                g.DrawImage(OverLayImage, PosX, PosY, Larg, Haut)
            End If
     
            If BackImage IsNot Nothing Then
                Dim BackImageCache As New Bitmap(BackImage)
                BackImage.Dispose()
                BackImage = Nothing
                pbCar.Image = BackImageCache
            Else
                pbCar.Image = My.Resources.splash
            End If
            If OverLayImage IsNot Nothing Then
                OverLayImage.Dispose()
                OverLayImage = Nothing
            End If
        End Sub

  2. #2
    Membre averti
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Mars 2012
    Messages
    640
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Bâtiment

    Informations forums :
    Inscription : Mars 2012
    Messages : 640
    Points : 372
    Points
    372
    Par défaut
    Zut alors, j'ai oublié l'objet graphics, désolé c'est la grosse fatigue....
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    g.Dispose()
    g = Nothing

  3. #3
    Expert éminent sénior Avatar de Pol63
    Homme Profil pro
    .NET / SQL SERVER
    Inscrit en
    Avril 2007
    Messages
    14 154
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : .NET / SQL SERVER

    Informations forums :
    Inscription : Avril 2007
    Messages : 14 154
    Points : 25 072
    Points
    25 072
    Par défaut
    quelques remarques tout de même

    ton try catch me semble un peu court, tant qu'à faire autant qu'il englobe tout le code
    un catch vide c'est pas super utile en général ^^
    pour éviter d'avoir à y penser et surtout pour être sur que Dispose soit appelé tu peux utiliser un bloc using (équivalent try finally)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    using disposablevar = ...
       ' code
    end using
    et les variables sont mises à Nothing en sortie de bloc (de sub par exemple) automatiquement (ca apporte rarement quelque chose de le faire explicitement)
    Cours complets, tutos et autres FAQ ici : C# - VB.NET

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. envoyer image bitmap dans fichier PDF
    Par colorid dans le forum Langage
    Réponses: 8
    Dernier message: 24/04/2012, 10h13
  2. intégrer un fichier image dans une base de donnée?
    Par Lody dans le forum Requêtes
    Réponses: 9
    Dernier message: 16/03/2006, 19h08
  3. Afficher et comparer 2 images bitmap
    Par leplusnul dans le forum MFC
    Réponses: 2
    Dernier message: 12/01/2004, 16h54
  4. generer une image bitmap a partir d'une scene OGL
    Par FreshLog dans le forum OpenGL
    Réponses: 4
    Dernier message: 01/07/2003, 11h29
  5. Lecture d'une image bitmap
    Par Geronimo dans le forum x86 32-bits / 64-bits
    Réponses: 18
    Dernier message: 28/06/2002, 12h01

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo