Как загрузить рисунок PNG на форму - VB

Узнай цену своей работы

Формулировка задачи:

Такой вопрос, как заставить Image или PictureBox понимать формат рисунка .PNG кто сталкивался помогите пожалуйста.

Решение задачи: «Как загрузить рисунок PNG на форму»

textual
Листинг программы
Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
Private Enum GpStatus
    Ok = 0
    GenericError = 1
    InvalidParameter = 2
    OutOfMemory = 3
    ObjectBusy = 4
    InsufficientBuffer = 5
    NotImplemented = 6
    Win32Error = 7
    WrongState = 8
    Aborted = 9
    FileNotFound = 10
    ValueOverflow = 11
    AccessDenied = 12
    UnknownImageFormat = 13
    FontFamilyNotFound = 14
    FontStyleNotFound = 15
    NotTrueTypeFont = 16
    UnsupportedGdiplusVersion = 17
    GdiplusNotInitialized = 18
    PropertyNotFound = 19
    PropertyNotSupported = 20
End Enum
 
Private Type GdiplusStartupInput
    GdiplusVersion As Long
    DebugEventCallback As Long
    SuppressBackgroundThread As Long
    SuppressExternalCodecs As Long
End Type
 
Private Declare Function GdipDrawImageRect Lib "gdiplus" (ByVal graphics As Long, ByVal image As Long, ByVal x As Single, ByVal y As Single, ByVal Width As Single, ByVal Height As Single) As GpStatus
Private Declare Function GdipLoadImageFromFile Lib "gdiplus" (ByVal FileName As String, image As Long) As GpStatus
Private Declare Function GdipGetImageWidth Lib "gdiplus" (ByVal image As Long, Width As Long) As GpStatus
Private Declare Function GdipGetImageHeight Lib "gdiplus" (ByVal image As Long, Height As Long) As GpStatus
Private Declare Function GdipDisposeImage Lib "gdiplus" (ByVal image As Long) As GpStatus
Private Declare Function GdiplusStartup Lib "gdiplus" (token As Long, inputbuf As GdiplusStartupInput, Optional ByVal outputbuf As Long = 0) As GpStatus
Private Declare Function GdipCreateFromHDC Lib "gdiplus" (ByVal hdc As Long, graphics As Long) As GpStatus
Private Declare Function GdipDeleteGraphics Lib "gdiplus" (ByVal graphics As Long) As GpStatus
 
Private token As Long
 
Private Function LoadImage(ByVal FileName As String, ByVal hDestDC As Long) As GpStatus
    Dim lngWidth As Long, lngHeight As Long
    Dim graphics As Long, img As Long
    Dim GpInput As GdiplusStartupInput
    Dim tmp_status As GpStatus
   
    GpInput.GdiplusVersion = 1
    tmp_status = GdiplusStartup(token, GpInput)
        If tmp_status <> Ok Then GoTo The_End:
    tmp_status = GdipCreateFromHDC(hDestDC, graphics)
        If tmp_status <> Ok Then GoTo The_End:
    tmp_status = GdipLoadImageFromFile(StrConv(FileName, vbUnicode), img)
        If tmp_status <> Ok Then GoTo The_End:
    tmp_status = GdipGetImageHeight(img, lngHeight)
        If tmp_status <> Ok Then GoTo The_End:
    tmp_status = GdipGetImageWidth(img, lngWidth)
        If tmp_status <> Ok Then GoTo The_End:
    tmp_status = GdipDrawImageRect(graphics, img, 0, 0, lngWidth, lngHeight)
        If tmp_status <> Ok Then GoTo The_End:
    tmp_status = GdipDisposeImage(img)
        If tmp_status <> Ok Then GoTo The_End:
    tmp_status = GdipDeleteGraphics(graphics)
The_End:
    LoadImage = tmp_status
End Function
 
 
Private Sub Command1_Click()
LoadImage "C:\mspaint.png", Picture1.hdc
End Sub
 
Private Sub Form_Load()
    Me.AutoRedraw = True
    'LoadImage "C:\mspaint.png", Me.hdc
    Me.Refresh
End Sub

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

15   голосов , оценка 4.067 из 5
Похожие ответы