Kullanıcıların profil bilgileri misafirlere kapatılmıştır.
PictureBox'ta PNG Uzantılı Resimleri Gösterme
PictureBox'ta PNG Uzantılı Resimleri Gösterme
Projemize bir picturebox bir tane de command button ekleyelim. İsimleri aynı kalsın.
Gerekli Api, veri yapısı ve sayma verileri:
Alıntı:
Private Declare Function GdiplusStartup Lib "gdiplus" (token As Long inputbuf As GdiplusStartupInput Optional ByVal outputbuf As Long = 0) As Long
Private Declare Function GdipLoadImageFromFile Lib "GdiPlus.dll" (ByVal mFilename As Long ByRef mImage As Long) As Long
Private Declare Function GdipDeleteGraphics Lib "GdiPlus.dll" (ByVal mGraphics As Long) As Long
Private Declare Function GdipCreateFromHDC Lib "gdiplus" (ByVal hDC As Long hGraphics As Long) As Long
Private Declare Function GdipDrawImage Lib "GdiPlus.dll" (ByVal mGraphics As Long ByVal mImage As Long ByVal mX As SingleByVal mY As Single) As Long
Private Declare Function GdipDisposeImage Lib "gdiplus" (ByVal Image As Long) As Long
Private Declare Sub GdiplusShutdown Lib "gdiplus" (ByVal token As Long)
Private Enum GpStatus
ok = &H0
GenericError = &H1
InvalidParameter = &H2
OutOfMemory = &H3
ObjectBusy = &H4
InsufficientBuffer = &H5
NotImplemented = &H6
Win32Error = &H7
WrongState = &H8
Aborted = &H9
FileNotFound = &HA
ValueOverflow = &HB
AccessDenied = &HC
UnknownImageFormat = &HD
FontFamilyNotFound = &HE
FontStyleNotFound = &HF
NotTrueTypeFont = &H10
UnsupportedGDIPlusVersion = &H11
GDIPlusNotInitialized = &H12
PropertyNotFound = &H13
PropertyNotSupported = &H14
End Enum
Private Type GdiplusStartupInput
GdiplusVersion As Long
DebugEventCallback As Long
SuppressBackgroundThread As Long
SuppressExternalCodecs As Long
End Type
PNG'yi çizdiren işlevimiz:
Alıntı:
Private Sub ciz(ByRef hedef As PictureBox ByVal dosyayolu As String ByVal x As Long ByVal y As Long)
Dim gSA As GdiplusStartupInput
gSA.GdiplusVersion = 1
Dim durum As GpStatus
Dim grafik As Long
Dim resim As Long
Dim token2 As Long
durum = GdiplusStartup(token2 gSA)
If durum = ok And token2 <> 0 Then 'gdiplus başlatıldı
durum = GdipCreateFromHDC(hedef.hDC grafik) 'yeni bir grafik oluştur
If durum = ok And grafik <> 0 Then 'grafik oluşturma başarılı
durum = GdipLoadImageFromFile(StrPtr(dosyayolu) resim) 'resmi yükle
If durum = ok And resim <> 0 Then 'resim oluşturma başarılı
Call GdipDrawImage(grafik resim x y) 'resmi çiz
Call GdipDisposeImage(resim) 'resmi bellekten kaldır
Else 'resim oluşturma başarısız
MsgBox "Hata: " & durum vbCritical "Hata"
End If 'bitti
Call GdipDeleteGraphics(grafik) 'grafiği bellekten kaldır
Else
MsgBox "Hata: " & durum vbCritical "Hata"
End If
Call GdiplusShutdown(token2) 'gdiplus'ı kapat
token2 = 0
Else
MsgBox "Hata: " & durum vbCritical "Hata"
End If
End Sub
Örnek kullanılış:
Alıntı:
Private Sub Command1_Click()
Call ciz(Picture1 "c:\tmp\furkan.png" 0 0)
End Sub
Forumaski paylaşım sitesidir.Bu nedenle yazılı, görsel ve diğer materyaller sitemize kayıtlı üyelerimiz tarafından kontrol edilmeksizin eklenmektedir.Bu nedenden ötürü doğabilecek yasal sorumluluklar yazan kullanıcılara aittir.Sitemiz hak sahiplerinin şikayetleri doğrultusunda yazılı, görsel ve diğer materyalleri 48 saat içerisinde sitemizden kaldırmaktadır.
Bildirimlerinizi bu linkten bize yapabilirsiniz.