:2.979KB : :1 :2019-12-20 15:42:51
Png等图片转换到JPG格式的工具源码,支持bmp、jpg、gif、tiff、png互转,被转换的图像数据启动GDI+获取图像格式对应的Clsid。
判断文件是否为有效(完整)的图片
:param img_path:图片路径
:return:True:有效 False:无效
局_GpInput.GdiplusVersion = 1
GdiplusStartup (Token, 局_GpInput, 0) ' 启动 GDI+
局_pStr = “{557CF401-1A04-11D3-9A73-0000F81EF32E}”
局_Clsid = 取空白字节集 (16)
CLSIDFromString (A2W (局_pStr), 局_Clsid) ' 获取图像格式对应的Clsid
局_nLength = 取字节集长度 (参_图像数据)
局_hMem = GlobalAlloc (#GMEM_FIXED, 局_nLength)
CreateStreamOnHGlobal (局_hMem, 真, 局_Stream)
局_lpvoid = GlobalLock (局_hMem)
写到内存 (参_图像数据, 局_lpvoid, 局_nLength)
GlobalUnlock (局_hMem)
局_pStream = GetObjectPtr (局_Stream, 局_Stream, 0)
GdipCreateBitmapFromStream (取字节集数据 (指针到字节集 (局_pStream, 4), #整数型, 1), 局_bitmap)
CreateStreamOnHGlobal (0, 真, 局_DataStream)
局_pStream = GetObjectPtr (局_DataStream, 局_DataStream, 0)
局_pStream = 取字节集数据 (指针到字节集 (局_pStream, 4), #整数型, 1)
GdipSaveImageToStream_int (局_bitmap, 局_pStream, 局_Clsid, 0)
GetHGlobalFromStream_int (局_pStream, 局_hMemDataStream)
局_pDataStream = GlobalLock (局_hMemDataStream)
局_nStreamSize = GlobalSize (局_hMemDataStream)
.如果真 (局_pDataStream ≠ 0)
新图像 = 取空白字节集 (局_nStreamSize)
CopyMemory (新图像, 局_pDataStream, 局_nStreamSize)
.如果真结束
GlobalUnlock (局_hMemDataStream)
GdipDisposeImage (局_bitmap)
GlobalFree (局_hMem)
返回 (新图像)
GdiplusShutdown (Token) ' 关闭 GDI+