• 大小: 512KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-16
  • 语言: 其他
  • 标签: vc  

资源简介

vc图像编程实例:jpeg格式转换成bmp vc图像编程实例:jpeg格式转换成bmp vc图像编程实例:jpeg格式转换成bmp vc图像编程实例:jpeg格式转换成bmp

资源截图

代码片段和文件信息

// jpegcompresstest.cpp : 定义控制台应用程序的入口点。
//

#include “stdafx.h“
#include 
#include 
#include 
extern “C“
{
#include “..\libjpeg\jpeglib.h“
}

BYTE srcBmpP[4096000];
//BYTE jpeg_buffer[409600]; //用于内存/

// unconditional swaps
#define Swap16(s) \
((short) ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff)))
#define Swap32(l) \
((int) ((((l) & 0xff000000) >> 24) | \
(((l) & 0x00ff0000) >> 8)  | \
(((l) & 0x0000ff00) << 8)  | \
(((l) & 0x000000ff) << 24)))


void Screen(char filename[])
{
//获取当前整个屏幕DC
HDC hDC = GetDC(NULL);

//获得颜色模式
int BitPerPixel = GetDeviceCaps(hDC BITSPIXEL);
int Width = GetDeviceCaps(hDC HORZRES);
int Height = GetDeviceCaps(hDC VERTRES);

//创建与获得的CDC兼容的内存设备描述
HDC hMemDC = CreateCompatibleDC(hDC);

//建立和屏幕兼容的bitmap
HBITMAP hMemBitmap hOldMemBitmap;

//初始化memBitmap
hMemBitmap = CreateCompatibleBitmap(hDC Width Height);

//将memBitmap选入内存DC
hOldMemBitmap = (HBITMAP)Selectobject(hMemDC hMemBitmap);

//复制屏幕图像到内存DC
BitBlt(hMemDC0 0 Width Height hDC 0 0 SRCCOPY);

//以下代码保存hMemDC中的位图到文件
BITMAP bmp;
//获得位图信息
Getobject( hMemBitmap (int)sizeof(BITMAP) &bmp );

// FILE *fp = fopen(filename “w+b“);

//位图信息头 
BITMAPINFOHEADER bih = {0};
//每个像素字节大小
bih.biBitCount = bmp.bmBitsPixel;
//无压缩
bih.biCompression = BI_RGB;
//高度
bih.biHeight = bmp.bmHeight;
bih.biPlanes = 1;
bih.biSize = sizeof(BITMAPINFOHEADER);

//图像数据大小
bih.biSizeImage = bmp.bmWidthBytes * bmp.bmHeight;

//宽度
bih.biWidth = bmp.bmWidth;

//位图文件头
BITMAPFILEHEADER bfh = {0};

//到位图数据的偏移量
bfh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);

//文件总的大小
bfh.bfSize = bfh.bfOffBits + bmp.bmWidthBytes * bmp.bmHeight;

//字符“BM“,表示位图文件
bfh.bfType = (WORD)0x4d42;

//写入位图文件头 
// fwrite(&bfh 1 sizeof(BITMAPFILEHEADER) fp);
//写入位图信息头
// fwrite(&bih 1 sizeof(BITMAPINFOHEADER) fp);
//申请内存保存位图数据
//BYTE * p = new BYTE[bmp.bmWidthBytes * bmp.bmHeight];

//获取位图数据
GetDIBits(hMemDC hMemBitmap 0 Height srcBmpP (LPBITMAPINFO) &bih DIB_RGB_COLORS);


//写入位图数据
// fwrite(srcBmpP 1 bmp.bmWidthBytes * bmp.bmHeight fp);

// delete [] p;
// fclose(fp);
Selectobject(hMemDC hOldMemBitmap); 
}

int image_width = 1280; //不是固定需要获取
int image_height = 800; //不是固定需要获取
int bitsPerPixel = 32; //不是固定需要获取

BYTE *m_buffer = srcBmpP; //

int m_remoteformat_bitsPerPixel  = 32;
//int m_usePixelFormat24 = false;
//static struct jpeg_destination_mgr jpegDstManager;
//static JOCTET *jpegDstBuffer; 
//static size_t jpegDstBufferLen;
static bool jpegError;
//static int jpegDstDataLen;

//static void JpegInitDestination(j_compress_ptr cinfo);
//static boolean JpegEmptyOutputBuffer(j_compress_ptr cinfo);
//static void JpegTermDestination(j_compress_ptr cinfo);
//
//static void
//JpegInitDestination(j_compress_ptr cinfo)
//{
// jpegError = false;
// jpegDstManager.next_output_byte = jpeg

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     目录          0  2007-01-28 22:10  jpegcompresstest\debug

     目录          0  2007-01-28 22:10  jpegcompresstest\jpegcompresstest\Debug

     文件       8176  2007-01-28 22:05  jpegcompresstest\jpegcompresstest\jpegcompresstest.cpp

     文件       4514  2007-01-28 15:43  jpegcompresstest\jpegcompresstest\jpegcompresstest.vcproj

     文件       1427  2007-01-28 22:07  jpegcompresstest\jpegcompresstest\jpegcompresstest.vcproj.MICROSOF-B2A6F0.Administrator.user

     文件       1004  2007-01-28 15:43  jpegcompresstest\jpegcompresstest\ReadMe.txt

     文件        221  2007-01-28 15:43  jpegcompresstest\jpegcompresstest\stdafx.cpp

     文件        276  2007-01-28 15:43  jpegcompresstest\jpegcompresstest\stdafx.h

     目录          0  2007-01-28 22:05  jpegcompresstest\jpegcompresstest

     文件       1527  2007-01-28 15:46  jpegcompresstest\jpegcompresstest.sln

     文件       1565  2002-12-11 15:06  jpegcompresstest\libjpeg\ansi2knr.1

     文件      23008  2002-12-11 15:06  jpegcompresstest\libjpeg\ansi2knr.c

     文件       5381  2002-12-11 15:06  jpegcompresstest\libjpeg\cderror.h

     文件       4863  2002-12-11 15:06  jpegcompresstest\libjpeg\cdjpeg.c

     文件       6307  2002-12-11 15:06  jpegcompresstest\libjpeg\cdjpeg.h

     文件       9501  2002-12-11 15:06  jpegcompresstest\libjpeg\change.log

     文件      10418  2002-12-11 15:06  jpegcompresstest\libjpeg\cjpeg.1

     文件      20458  2002-12-11 15:06  jpegcompresstest\libjpeg\cjpeg.c

     文件      12568  2002-12-11 15:06  jpegcompresstest\libjpeg\ckconfig.c

     文件      25163  2002-12-11 15:06  jpegcompresstest\libjpeg\config.guess

     文件      20756  2002-12-11 15:06  jpegcompresstest\libjpeg\config.sub

     文件      62320  2002-12-11 15:06  jpegcompresstest\libjpeg\configure

     目录          0  2007-01-28 22:10  jpegcompresstest\libjpeg\Debug

     文件       7669  2002-12-11 15:06  jpegcompresstest\libjpeg\djpeg.1

     文件      19955  2002-12-11 15:06  jpegcompresstest\libjpeg\djpeg.c

     文件      17524  2002-12-11 15:06  jpegcompresstest\libjpeg\example.c

     文件       5834  2002-12-11 15:06  jpegcompresstest\libjpeg\install-sh

     文件       9401  2002-12-11 15:06  jpegcompresstest\libjpeg\jcapimin.c

     文件       6042  2002-12-11 15:06  jpegcompresstest\libjpeg\jcapistd.c

     文件      16849  2002-12-11 15:06  jpegcompresstest\libjpeg\jccoefct.c

............此处省略124个文件信息

评论

共有 条评论