導航:首頁 > 動漫圖片 > c語言里怎麼用png圖片

c語言里怎麼用png圖片

發布時間:2025-05-22 21:12:05

1. bmp格式轉換PNG格式 c語言或c++編程

BMP是最簡單的圖形存儲格式,在c++里有朋友封裝了一個類CDib.
只要把圖片使用附件中編輯--粘貼來源找到圖畫打開另存為選擇你想要的格式保存就可以了。也可以右鍵點擊選擇打開方式使用圖畫打開相同的方法。另外photoshop 和office2003的picture manage也有這個功能。

Private Sub mnuconvertBMPtoJPG_Click()
Dim tmpimage As imgdes ' Image descriptors
Dim tmp2image As imgdes
Dim rcode As Long
Dim quality As Long
Dim vbitcount As Long
Dim bdat As BITMAPINFOHEADER ' Reserve space for BMP struct
Dim bmp_fname As String
Dim jpg_fname As String

bmp_fname = "test.bmp"
jpg_fname = "test.jpg"

quality = 75
' Get info on the file we're to load
rcode = bmpinfo(bmp_fname, bdat)
If (rcode <> NO_ERROR) Then
MsgBox "Cannot find file", 0, "Error encountered!"
Exit Sub
End If

vbitcount = bdat.biBitCount
If (vbitcount >= 16) Then ' 16-, 24-, or 32-bit image is loaded into 24-bit buffer
vbitcount = 24
End If

' Allocate space for an image
rcode = allocimage(tmpimage, bdat.biWidth, bdat.biHeight, vbitcount)
If (rcode <> NO_ERROR) Then
MsgBox "Not enough memory", 0, "Error encountered!"
Exit Sub
End If

' Load image
rcode = loadbmp(bmp_fname, tmpimage)
If (rcode <> NO_ERROR) Then
freeimage tmpimage ' Free image on error
MsgBox "Cannot load file", 0, "Error encountered!"
Exit Sub
End If

If (vbitcount = 1) Then ' If we loaded a 1-bit image, convert to 8-bit grayscale
' because jpeg only supports 8-bit grayscale or 24-bit color images
rcode = allocimage(tmp2image, bdat.biWidth, bdat.biHeight, 8)
If (rcode = NO_ERROR) Then
rcode = convert1bitto8bit(tmpimage, tmp2image)
freeimage tmpimage ' Replace 1-bit image with grayscale image
imgdes tmp2image, tmpimage
End If
End If

' Save image
rcode = savejpg(jpg_fname, tmpimage, quality)
freeimage tmpimage

End Sub

........... Add these defines and declarations to your Global mole ...........
' Image descriptor
Type imgdes
ibuff As Long
stx As Long
sty As Long
endx As Long
endy As Long
buffwidth As Long
palette As Long
colors As Long
imgtype As Long
bmh As Long
hBitmap As Long
End Type

Type BITMAPINFOHEADER
biSize As Long
biWidth As Long
biHeight As Long
biPlanes As Integer
biBitCount As Integer
biCompression As Long
biSizeImage As Long
biXPelsPerMeter As Long
biYPelsPerMeter As Long
biClrUsed As Long
biClrImportant As Long
End Type

Declare Function bmpinfo Lib "VIC32.DLL" (ByVal Fname As String, bdat As BITMAPINFOHEADER) As Long
Declare Function allocimage Lib "VIC32.DLL" (image As imgdes, ByVal wid As Long, ByVal leng As Long, ByVal BPPixel As Long) As Long
Declare Function loadbmp Lib "VIC32.DLL" (ByVal Fname As String, desimg As imgdes) As Long
Declare Sub freeimage Lib "VIC32.DLL" (image As imgdes)
Declare Function convert1bitto8bit Lib "VIC32.DLL" (srcimg As imgdes, desimg As imgdes) As Long
Declare Sub imgdes Lib "VIC32.DLL" (srcimg As imgdes, desimg As imgdes)
Declare Function savejpg Lib "VIC32.DLL" (ByVal Fname As String, srcimg As imgdes, ByVal quality As Long) As Long

《圖像處理----做一個自己的photoshop》
大部分都是源碼,其中有bmp<-->jgep<-->GIF的代碼.

閱讀全文

與c語言里怎麼用png圖片相關的資料

熱點內容
26個英文字書寫圖片 瀏覽:845
如何把2003word圖片壓縮 瀏覽:790
圖片動漫蘿莉圖片大全 瀏覽:791
word插入的圖片超過邊界不顯示 瀏覽:169
word兩張圖片怎麼保存 瀏覽:832
復古衣服圖片男裝 瀏覽:429
衣服圖片簡單圖 瀏覽:902
長臉適合什麼短的發型圖片 瀏覽:549
冬天衣服褲子圖片卡通 瀏覽:395
唯美圖片大全高清傷感女生 瀏覽:140
160斤的女生圖片自拍 瀏覽:196
我愛閱讀手抄報簡單漂亮圖片 瀏覽:361
越南企業高清圖片 瀏覽:159
松鼠卡通圖片可愛趴著 瀏覽:278
漂亮夏季衣服圖片 瀏覽:402
初中生書包女生圖片 瀏覽:767
wps如何將製作好的內容做成圖片 瀏覽:200
文檔圖片顯示很亂如何調整 瀏覽:560
食品海報圖片大全 瀏覽:200
女生護腕圖片 瀏覽:493