1、绘图,如:线、形状。
2、保存成透明的png文件。
3、如何操作?或 思路是怎么样的?感觉只用Gdi+很难实现,但用 libpng 又太麻烦了,有点牛刀小用的感觉。
4、再简单点,如何将打开的一幅png图片,在剪切后保存为 png 文件? 剪切功能已实现。使用Gdi+ 的 DrawImage 和 DrawImageRectRectI

解决方案 »

  1.   

    新建一空白bitmap,然后画线,然后保存为png:Private Type GdiplusStartupInput
       GdiplusVersion As Long
       DebugEventCallback As Long
       SuppressBackgroundThread As Long
       SuppressExternalCodecs As Long
    End TypePrivate Declare Function GdiplusStartup Lib "gdiplus" (token As Long, inputbuf As GdiplusStartupInput, Optional ByVal outputbuf As Long = 0) As Long
    Private Declare Function GdipCreateBitmapFromScan0 Lib "gdiplus" (ByVal Width As Long, ByVal Height As Long, ByVal stride As Long, ByVal PixelFormat As Long, scan0 As Any, bitmap As Long) As Long
    Private Declare Function GdipCreatePen1 Lib "gdiplus" (ByVal color As Long, ByVal Width As Single, ByVal unit As Long, pen As Long) As Long
    Private Declare Function GdipGetImageGraphicsContext Lib "gdiplus" (ByVal Image As Long, graphics As Long) As Long
    Private Declare Function GdipDrawLine Lib "gdiplus" (ByVal graphics As Long, ByVal pen As Long, ByVal x1 As Single, ByVal y1 As Single, ByVal x2 As Single, ByVal y2 As Single) As Long
    Private Declare Function CLSIDFromString Lib "ole32" (ByVal lpsz As Long, pclsid As Any) As Long
    Private Declare Function GdipSaveImageToFile Lib "gdiplus" (ByVal Image As Long, ByVal filename As Long, clsidEncoder As Any, encoderParams As Any) As Long
    Private Declare Function GdipDeletePen Lib "gdiplus" (ByVal pen As Long) As Long
    Private Declare Function GdipDeleteGraphics Lib "gdiplus" (ByVal graphics As Long) As Long
    Private Declare Function GdipDisposeImage Lib "gdiplus" (ByVal Image As Long) As Long
    Private Declare Function GdiplusShutdown Lib "gdiplus" (ByVal token As Long) As LongPrivate Sub Command1_Click()
        Const PNGFile As String = "D:\1.png"
        Const PixelFormat32bppARGB As Long = &H26200A
        Const CLSID_PNG As String = "{557CF406-1A04-11D3-9A73-0000F81EF32E}"
        
        Dim token As Long
        Dim GpInput As GdiplusStartupInput
        Dim ReturnValue As Long
        
        Dim bitmap As Long
        Dim graphics As Long
        Dim pen As Long
        
        Dim PngClsid(15) As Byte
        Dim Params(7) As Long
        
        '初始化GDI
        GpInput.GdiplusVersion = 1
        ReturnValue = GdiplusStartup(token, GpInput)
        If ReturnValue <> 0 Then MsgBox "GDI初始化失败": Exit Sub    '新建Bitmap
        GdipCreateBitmapFromScan0 100, 100, 0, PixelFormat32bppARGB, ByVal 0, bitmap
        
        '新建pen
        GdipCreatePen1 &H80FF0000, 10, 0, pen '半透明的红色
        
        '画线
        GdipGetImageGraphicsContext bitmap, graphics
        GdipDrawLine graphics, pen, 10, 20, 60, 70
        
        '保存为PNG
        CLSIDFromString StrPtr(CLSID_PNG), PngClsid(0)
        GdipSaveImageToFile bitmap, StrPtr(PNGFile), PngClsid(0), Params(0)
        
        '扫地工作
        GdipDeletePen pen
        GdipDeleteGraphics graphics
        GdipDisposeImage bitmap
        GdiplusShutdown token
    End Sub
      

  2.   

    1楼,如何把PICTUREBOX上画的保存为PNG呢?