------ JPG图片旋转90度 '以下代码在bas############# Private Type POINTAPI X As Long y As Long End Type
Private Type Bitmap bmType As Long bmWidth As Long bmHeight As Long bmWidthBytes As Long bmPlanes As Integer bmBitsPixel As Integer BmBits As Long End Type Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long Private Declare Function GetTickCount Lib "kernel32" () As Long Private Declare Function SelectObject Lib "gdi32" (ByVal hDC As Long, ByVal hObject As Long) As Long Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hDC As Long) As Long Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hDC As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long Private Declare Function DeleteDC Lib "gdi32" (ByVal hDC As Long) As Long Private Declare Function ReleaseDC Lib "user32" (ByVal hWnd As Long, ByVal hDC As Long) As Long Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC 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 dwRop As Long) As Long Private Declare Function PlgBlt Lib "gdi32" (ByVal hdcDest As Long, lpPoint As POINTAPI, ByVal hdcSrc As Long, ByVal nXSrc As Long, ByVal nYSrc As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hbmMask As Long, ByVal xMask As Long, ByVal yMask As Long) As Long
Public Sub Rotate90(Pic As PictureBox) Dim DefPoints(3) As POINTAPI Dim MemDC As Long Dim BHandle As Long Dim OldObject As Long Dim picINFO As Bitmap Dim Width As Long, Height As Long, Temp As Long Pic.AutoSize = True: Pic.AutoRedraw = True GetObject Pic.Image, Len(picINFO), picINFO Width = picINFO.bmWidth Height = picINFO.bmHeight MemDC = CreateCompatibleDC(Pic.hDC) BHandle = CreateCompatibleBitmap(Pic.hDC, Width, Height) OldObject = SelectObject(MemDC, BHandle) BitBlt MemDC, 0, 0, Width, Height, Pic.hDC, 0, 0, vbSrcCopy DefPoints(0).X = 0 DefPoints(0).y = Width DefPoints(1).X = 0 DefPoints(1).y = 0 DefPoints(2).X = Height DefPoints(2).y = Width Pic.Move Pic.Left, Pic.Top, Pic.Height, Pic.Width Set Pic.Picture = Nothing PlgBlt Pic.hDC, DefPoints(0), MemDC, 0, 0, Width, Height, 0, 0, 0 SelectObject MemDC, OldObject DeleteDC MemDC DeleteObject BHandle End Sub
'窗体代码############# Private Sub Command1_Click()'旋转JPG图片90度 Dim t As Long t = GetTickCount Rotate90 Picture1 End Sub Private Sub Command2_Click()'打开JPG图片 CommonDialog1.Filter = " *.jpg |*.jpg" CommonDialog1.ShowOpen If CommonDialog1.Filename <> "" Then Picture1.Picture = LoadPicture(CommonDialog1.Filename) End Sub
------ c++ 注意的是 一个要在使用gdi+之前调用gdiplusstartup 之后要gdiplusshutdown 图像格式不像托管的那样直接拿来就用