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

Windows Forms Discussion :

c# comment utilise loadBItmap


Sujet :

Windows Forms

  1. #1
    Candidat au Club
    Profil pro
    Inscrit en
    Août 2008
    Messages
    3
    Détails du profil
    Informations personnelles :
    Localisation : Maroc

    Informations forums :
    Inscription : Août 2008
    Messages : 3
    Points : 3
    Points
    3
    Par défaut c# comment utilise loadBItmap
    Bonjour a tous.
    Je suis débutant en c# et je voudrais savoir comment charger une bitmap à partir d'un native dll . Le problème est erreur de la source et null .
    Merci d'avance.
    voila mon code :

    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
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Reflection;
    using System.IO;
    using System.Runtime.InteropServices;
    using System.Threading;
    namespace Plug_Load
    {
        public partial class Form1 : Form
        {
            #region P/Invoke
            [DllImport("kernel32.dll")]
            static extern IntPtr LoadLibrary(string lpFileName);
            [DllImport("kernel32.dll")]
    		public static extern bool FreeLibrary(IntPtr hModule);
            [DllImport("kernel32.dll", SetLastError = true)]
            static extern IntPtr LoadLibraryEx(string lpFileName, IntPtr hFile, uint dwFlags);
            [DllImport("user32.dll")]
            public static extern IntPtr LoadBitmap(IntPtr hInstance, int uID);        
            [DllImport("kernel32.dll")]
            static extern IntPtr FindResource(IntPtr hModule, int lpID, string lpType);
            [DllImport("kernel32.dll", SetLastError = true)]
            static extern IntPtr LoadResource(IntPtr hModule, IntPtr hResInfo);
            [DllImport("kernel32.dll", SetLastError = true)]
            static extern uint SizeofResource(IntPtr hModule, IntPtr hResInfo);
            [DllImport("user32.dll")]
            public static extern int MessageBox(int h, string m, string c, int type);
     
            public const uint LOAD_LIBRARY_AS_DATAFILE = 0x00000002;
     
            #endregion
     
            public Form1()
            {
                InitializeComponent();
            }
     
            private void button1_Click(object sender, EventArgs e)
            {
                //windows exit
                Close();
            }
     
            private void Form1_Load(object sender, EventArgs e)
            {
                string pathe = "Plugins";
                string[] files = Directory.GetFiles(pathe, "*.dll");
                foreach (string file in files)
                {
                    FileInfo fr = new FileInfo(file);
                    string id = Encoding.Default.GetString(BitConverter.GetBytes(2017));
                    IntPtr hMod = LoadLibraryEx(fr.FullName, IntPtr.Zero, LOAD_LIBRARY_AS_DATAFILE);
                    IntPtr hRes = FindResource(hMod, 2017, "Bitmap");
                    uint size = SizeofResource(hMod, hRes);
                    IntPtr pt = LoadResource(hMod, hRes);
                    Bitmap bmp;
                    byte[] bPtr = new byte[size];
                    Marshal.Copy(pt, bPtr, 0, (int)size);
                    using (MemoryStream m = new MemoryStream(bPtr))                
                        bmp = (Bitmap)Bitmap.FromStream(m);
     
                    pictureBox1.Image = bmp;
                    menuStrip1.Items.Add(hMod.ToString());
                }
            }

  2. #2
    Membre émérite
    Profil pro
    Mangeur de gauffre
    Inscrit en
    Octobre 2007
    Messages
    4 413
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations professionnelles :
    Activité : Mangeur de gauffre

    Informations forums :
    Inscription : Octobre 2007
    Messages : 4 413
    Points : 2 498
    Points
    2 498
    Par défaut
    Sais tu qu'il y a des methodes toutes faite en C# pour faire ce que tu essaye de faire ?
    « Ils ne savaient pas que c'était impossible, alors ils l'ont fait ». (Twain)

  3. #3
    Membre confirmé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2008
    Messages
    337
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Septembre 2008
    Messages : 337
    Points : 456
    Points
    456
    Par défaut
    Salut il suffit d'utiliser la méthode FromFile de la classe image.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    Image newImage = Image.FromFile(path);
    pictureBox1.Image = bmp;

  4. #4
    Candidat au Club
    Profil pro
    Inscrit en
    Août 2008
    Messages
    3
    Détails du profil
    Informations personnelles :
    Localisation : Maroc

    Informations forums :
    Inscription : Août 2008
    Messages : 3
    Points : 3
    Points
    3
    Par défaut
    Salut.
    Merci pour la réponse, mais le problème est l'image dans 'une dll native j'ai utilise la méthode loadResource et FindResource .

  5. #5
    Candidat au Club
    Profil pro
    Inscrit en
    Août 2008
    Messages
    3
    Détails du profil
    Informations personnelles :
    Localisation : Maroc

    Informations forums :
    Inscription : Août 2008
    Messages : 3
    Points : 3
    Points
    3
    Par défaut
    salut.
    je trouve le problème est findresource(hMOd,"#2017","RT_BITMAP") est tout jour égal à zéro quel qu'un ma dit comment fait pour passer se problème et merci.

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

Discussions similaires

  1. Réponses: 4
    Dernier message: 24/02/2009, 12h06
  2. Comment utiliser un cache ?
    Par TOM-Z dans le forum XMLRAD
    Réponses: 4
    Dernier message: 14/03/2003, 09h55
  3. comment utiliser actionscript ?
    Par webs dans le forum Flash
    Réponses: 3
    Dernier message: 09/02/2003, 23h11
  4. Comment utiliser OUT ?
    Par Bouziane Abderraouf dans le forum CORBA
    Réponses: 3
    Dernier message: 20/07/2002, 09h35
  5. Réponses: 5
    Dernier message: 11/06/2002, 15h21

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