Nasıl yapılır: GDI+ ile Resim İşleme

Uygulamalarınızda dosya olarak bulunan görüntüleri işlemek için GDI+ kullanabilirsiniz. Bunu yapmak için sınıfın Image yeni bir nesnesini (örneğin Bitmap), kullanmak istediğiniz çizim yüzeyine başvuran bir Graphics nesne oluşturup nesnesinin DrawImageGraphics yöntemini çağırın. Görüntü, grafik sınıfı tarafından temsil edilen çizim yüzeyine boyanacaktır. Görüntü Düzenleyicisi'ni kullanarak tasarım zamanında görüntü dosyaları oluşturabilir ve düzenleyebilir ve bunları çalışma zamanında GDI+ ile işleyebilirsiniz. Daha fazla bilgi için bkz . Simgeler için Görüntü Düzenleyicisi.

GDI+ ile görüntü işlemek için

  1. Görüntülemek istediğiniz görüntüyü temsil eden bir nesne oluşturun. Bu nesne, veya Metafilegibi Bitmap öğesinden Imagedevralan bir sınıfın üyesi olmalıdır. Bir örnek gösterilmiştir:

    ' Uses the System.Environment.GetFolderPath to get the path to the
    ' current user's MyPictures folder.  
    Dim myBitmap as New Bitmap _  
       (System.Environment.GetFolderPath _  
          (System.Environment.SpecialFolder.MyPictures))  
    
    // Uses the System.Environment.GetFolderPath to get the path to the
    // current user's MyPictures folder.  
    Bitmap myBitmap = new Bitmap  
       (System.Environment.GetFolderPath  
          (System.Environment.SpecialFolder.MyPictures));  
    
    // Uses the System.Environment.GetFolderPath to get the path to the
    // current user's MyPictures folder.  
    Bitmap^ myBitmap = gcnew Bitmap  
       (System::Environment::GetFolderPath  
          (System::Environment::SpecialFolder::MyPictures));  
    
  2. Kullanmak istediğiniz çizim yüzeyini temsil eden bir Graphics nesne oluşturun. Daha fazla bilgi için bkz . Nasıl yapılır: Çizim için Grafik Nesneleri Oluşturma.

    ' Creates a Graphics object that represents the drawing surface of
    ' Button1.  
    Dim g as Graphics = Button1.CreateGraphics  
    
    // Creates a Graphics object that represents the drawing surface of
    // Button1.  
    Graphics g = Button1.CreateGraphics();  
    
    // Creates a Graphics object that represents the drawing surface of
    // Button1.  
    Graphics^ g = button1->CreateGraphics();  
    
  3. DrawImage Görüntüyü işlemek için grafik nesnenizin öğesini çağırın. Hem çizilecek görüntüyü hem de çizilecek koordinatları belirtmeniz gerekir.

    g.DrawImage(myBitmap, 1, 1)  
    
    g.DrawImage(myBitmap, 1, 1);  
    
    g->DrawImage(myBitmap, 1, 1);  
    

Ayrıca bkz.