当前位置:首页 » 操作系统 » bmp转png源码

bmp转png源码

发布时间: 2025-02-01 06:30:08

A. 急求把bmp压缩成jpg的代码,最好用.net写的

给你一段代码,支持很多格式之间的相互转换:
从我的一个项目中截取出来的代码段,你看其中代码就可以了,控件无所谓
private void button1_Click(object sender, EventArgs e)
{//浏览图像文件
OpenFileDialog MyDlg = new OpenFileDialog();
MyDlg.Filter = "Image 图像文件 (JPeg, Gif, Bmp, etc.)|*.jpg;*.jpeg;*.gif;*.bmp;*.tif; *.tiff; *.png| JPeg files (*.jpg;*.jpeg)| *.jpg;*.jpeg|GIF图像文件(*.gif)|*.gif |BMP图像文件(*.bmp)|*.bmp|Tiff图像文件(*.tif;*.tiff)|*.tif;*.tiff|Png图像文件(*.png)| *.png |所有文件(*.*)|*.*";
if (MyDlg.ShowDialog() == DialogResult.OK)
{
string MyFileName = MyDlg.FileName;
this.pictureBox1.Image = Image.FromFile(MyFileName);
}
}
private void button2_Click(object sender, EventArgs e)
{//转换图像文件
if (this.pictureBox1.Image == null)
{
MessageBox.Show("请首先选择一幅图像!", "信息提示",MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
SaveFileDialog MyDlg = new SaveFileDialog();
if (MyDlg.ShowDialog() == DialogResult.Cancel)
return;
string MyFileName = MyDlg.FileName;
try
{
if (this.radioButton1.Checked)
{
this.pictureBox1.Image.Save(MyFileName + ".bmp",System.Drawing.Imaging.ImageFormat.Bmp);
}
if (this.radioButton2.Checked)
{
this.pictureBox1.Image.Save(MyFileName + ".gif",System.Drawing.Imaging.ImageFormat.Gif);
}
if (this.radioButton3.Checked)
{
this.pictureBox1.Image.Save(MyFileName + ".jpg",System.Drawing.Imaging.ImageFormat.Jpeg);
}
if (this.radioButton4.Checked)
{
this.pictureBox1.Image.Save(MyFileName + ".png",System.Drawing.Imaging.ImageFormat.Png);
}
if (this.radioButton5.Checked)
{
this.pictureBox1.Image.Save(MyFileName + ".tif",System.Drawing.Imaging.ImageFormat.Tiff);
}
if (this.radioButton6.Checked)
{
this.pictureBox1.Image.Save(MyFileName + ".wmf",System.Drawing.Imaging.ImageFormat.Wmf);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "信息提示",MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}

B. 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的代码.

热点内容
安卓怎么冻结苹果id账号 发布:2025-02-01 08:45:16 浏览:639
pythonforosx 发布:2025-02-01 08:43:50 浏览:763
ftp建站工具 发布:2025-02-01 08:42:07 浏览:532
linux开启ntp 发布:2025-02-01 08:31:42 浏览:284
excel密码加密 发布:2025-02-01 08:17:01 浏览:539
陌陌在手机哪个文件夹 发布:2025-02-01 08:13:49 浏览:317
proe50解压打不开 发布:2025-02-01 08:11:17 浏览:390
密码按错三次怎么办 发布:2025-02-01 08:00:24 浏览:851
传送门什么配置好玩 发布:2025-02-01 08:00:17 浏览:1000
android监听输入法状态 发布:2025-02-01 07:52:44 浏览:283