使用GDI+加载图片的步骤是否有错?大侠过来看看!
下面的步骤是否有错?
我加载的jpg图片显示不出来!
Private Sub Form_Load()
Dim GpInput As GdiplusStartupInput
GpInput.GdiplusVersion = 1
If GdiplusStartup(token, GpInput) <> 0 Then Unload Me
GdipLoadImageFromFile strptr("c\1.jpg"), Img
GdipGetImageHeight Img, jpgHeight
GdipGetImageWidth Img, jpgWidth
GdipCreateFromHDC me.hdc, graphics
Me.ScaleWidth = jpgWidth
Me.ScaleHeight = jpgHeight
GdipDrawImageRect graphics, Img, 0, 0, jpgWidth, jpgHeight
[解决办法]
帮楼主顶起来.......
[解决办法]
看起来应该是GdipLoadImageFromFile 用法错误,这里给你例子:
Dim gdip_Token As LongDim gdip_pngImage As LongDim gdip_Graphics As LongDim GpInput As GdiplusStartupInputGpInput.GdiplusVersion = 1If GdiplusStartup(gdip_Token, GpInput) <> Ok Then MsgBox "加载GDI+失败!", vbCritical, "加载错误" EndEnd IfPicture1.AutoRedraw = TrueIf GdipCreateFromHDC(Picture1.hDC, gdip_Graphics) <> Ok Then MsgBox "出现错误!", vbCritical, "错误" GdiplusShutdown gdip_Token EndEnd IfGdipLoadImageFromFile StrConv("d:\p1.jpg", vbUnicode), gdip_pngImage '加载文件If GdipDrawImage(gdip_Graphics, gdip_pngImage, 0, 0) <> Ok Then Debug.Print "显示失败。。。"GdipDisposeImage gdip_pngImageGdipDeleteGraphics gdip_GraphicsGdiplusShutdown gdip_Token