×

c生成png文件

c生成png文件(c++显示png图片)

admin admin 发表于2023-03-24 17:26:08 浏览55 评论0

抢沙发发表评论

本文目录一览:

C++如何将一个string格式的数组存为png图片?

我以前弄过一次,我的想法很简单就是创建一个xxx.png文件,然后把string写进去保存

具体一点就是:使用fopen(或者FILE文件操作)以w+或者a+模式打开一个xxx.png,它不存在的话,自然就会创建一个空文件,然后fwrite(或者其他文件写操作)进去,然后保存。

你可以尝试一下

c语言环境BMP格式怎样换成png格式

打开图片之后,保存时将图片格式换成PIG格式就好了。图片格式是计算机存储图片的格式,常见的存储的格式有:bmp,jpg,tiff,gif,pcx,tga,exif,fpx,svg,psd,cdr,pcd,dxf,ufo,eps,ai,raw等。-c生成png文件

bmp格式转换PNG格式 c语言或c++编程

BMP是最简单的图形存储格式,在c++里有朋友封装了一个类CDib.

只要把图片使用附件中编辑--粘贴来源找到图画打开另存为选择你想要的格式保存就可以了。也可以右键点击选择打开方式使用图画打开相同的方法。另外photoshop 和office2003的picture manage也有这个功能。 -c生成png文件

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-c生成png文件

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-c生成png文件

' because jpeg only supports 8-bit grayscale or 24-bit color images-c生成png文件

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

copyimgdes 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 module ...........-c生成png文件

' 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-c生成png文件

Declare Function allocimage Lib "VIC32.DLL" (image As imgdes, ByVal wid As Long, ByVal leng As Long, ByVal BPPixel As Long) As Long-c生成png文件

Declare Function loadbmp Lib "VIC32.DLL" (ByVal Fname As String, desimg As imgdes) As Long-c生成png文件

Declare Sub freeimage Lib "VIC32.DLL" (image As imgdes)

Declare Function convert1bitto8bit Lib "VIC32.DLL" (srcimg As imgdes, desimg As imgdes) As Long-c生成png文件

Declare Sub copyimgdes 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-c生成png文件

《图像处理----做一个自己的photoshop》

大部分都是源码,其中有bmp--jgep--GIF的代码.

vc中怎么把CBitmap转成png?

从CBitmap类到输出png有很长的路要走,非三言两语说得明白。

别说输出png,就是读入png,建CBitmap对象也不是很简单的。

你首先要(从互联网)获取PNG库libpng的源码(免费的),然后正确安装。读详细说明,了解 PNG 编码 和压缩方法。

PNG压缩要用到ZLIB库,你要(从互联网)获取ZLIB库,然后正确安装.

你要理解CBitmap类定义,弄清图素排列,颜色和写PNG必要的信息。

好了,按PNG库里的详细说明和步骤,调用一个一个的库函数,并输出PNG。

编译和链接libpng,zlib 库. 输出PNG文件。

GIF支持透明,PNG是否支持透明,我记不起来,如果支持,设某色为透明,应是小菜一碟。