1、繪圖,如:線、形狀。
2、保存成透明的png檔案。
3、如何操作?或 思路是怎么樣的?感覺只用Gdi+很難實作,但用 libpng 又太麻煩了,有點牛刀小用的感覺。
4、再簡單點,如何將打開的一幅png圖片,在剪切后保存為 png 檔案? 剪切功能已實作。使用Gdi+ 的 DrawImage 和 DrawImageRectRectI
uj5u.com熱心網友回復:
新建一空白bitmap,然后畫線,然后保存為png:Private Type GdiplusStartupInput
GdiplusVersion As Long
DebugEventCallback As Long
SuppressBackgroundThread As Long
SuppressExternalCodecs As Long
End Type
Private 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 Long
Private 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
uj5u.com熱心網友回復:
學習1樓uj5u.com熱心網友回復:
1樓,如何把PICTUREBOX上畫的保存為PNG呢?轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/99692.html
標籤:API
