Windows Xp下BMP位元影像轉JPEG格式

來源:互聯網
上載者:User

一、基於C#的Bitmap類

 

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;

namespace ConsoleBmpToJpeg
{
class Program
{

static void Main(string[] args)
{
string bmpFilePath = "testBmp.bmp";
Bitmap m_bitmap = new Bitmap(bmpFilePath);//讀取指定目錄下的位元影像檔案並構造位元影像對象

string jpgFilePath = "jpegResult.jpg";
m_bitmap.Save(jpgFilePath, ImageFormat.Jpeg);//儲存圖片檔案


//說明:
//1.儲存圖片格式還有很多其它選擇,比如gif,png等等
//2.可以將轉換的結果儲存為檔案流,也可以儲存為記憶體流
}
}
}

 

 

 

   說明:此方法只能基於WinXp下可以用,在WinCe下,構造位元影像那一語句是無法正常啟動並執行,不知道為什麼,可能是WinCe下沒有提供這麼進階的函數吧。最後還是用C++通過IImageFactory介面來進行的格式轉換的。

 

 

 

二、基於C++語言ATL支援類CImage

  用VS2005建立WinXp下的C++程式,並在建立程式的時候,選擇ATL支援

然後主檔案中代碼如下:

// WinXpCppAtl.cpp : 定義控制台應用程式的進入點。//#include "stdafx.h"#include "WinXpCppAtl.h"#include <atlimage.h>//Cyan:CImage類的標頭檔#ifdef _DEBUG#define new DEBUG_NEW#endif// 唯一的應用程式物件CWinApp theApp;using namespace std;int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]){int nRetCode = 0;// 初始化 MFC 並在失敗時顯示錯誤if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)){// TODO: 更改錯誤碼以符合您的需要_tprintf(_T("錯誤: MFC 初始化失敗\n"));nRetCode = 1;}else{// TODO: 在此處為應用程式的行為編寫代碼。CImage m_Image;m_Image.Load(_T("\\recvBmpData.bmp"));m_Image.Save(_T("\\recvBmpData.jpg"));}return nRetCode;}

  注意:此方法可以進行檔案操作也可以進行記憶體中轉碼操作,但是卻也只能在WinXp下進行,在WinCe下無法成功。雖然WinCe下的ATL也有此CImage類,但是提供的方法比XP下有限,無法滿足WinCe平台下的格式轉換要求。

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.