Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Compress Bmp to Jpeg

Posted on 2009-04-09
2
675 Views
Last Modified: 2012-05-06
Hi all,

I have a Application which does live Video Capturing , using Webcam, and show it to the user(every thing locally). still under stating :-)

Environment:- DirectShow, Win32api, C

Now, want to Compress and Decompress the video frames and show it .

In this regard, as my first step.....
--when ever a Button_click event is fired , i want to grab the image and save that image as JPEG.
--i could able to Grab the image (which is of DIB format).
--i even have the Library which compresses & De-Compresses BMP-JPEG -BMP where Input is .bmp file and Output is .Jpeg

-- When button clicked, i have the BitmapInfoheader & Image Bits.
can you please tell me how to Compress the .bmp(not from file) and save as .jpeg.

/////////////    code which captures Image on Button Clicked   /////////////
 
DWORD GrabFrame()
{	
       BYTE *lpCurrImage = NULL;
        m_pWC->GetCurrentImage(&lpCurrImage) 
        ......
        m_pImageBytes = pImage; // Copies the Image into m_pImageBytes		
        MakeBMPHeader();        // Header
...
}
void MakeBMPHeader()
{	
	DWORD  dwBitmapInfoSize;
	dwBitmapInfoSize = sizeof(BITMAPINFO);
	m_pBmp   = (BITMAPINFO *)new BYTE [dwBitmapInfoSize];
	m_pBmp->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    m_pBmp->bmiHeader.biWidth = m_un32ImageWidth;
    m_pBmp->bmiHeader.biHeight = m_un32ImageHeight*-1;	
    m_pBmp->bmiHeader.biPlanes = 1;
    m_pBmp->bmiHeader.biBitCount =(unsigned short) m_un32ImageBits; //CamBits i.e 24
    m_pBmp->bmiHeader.biCompression = BI_RGB;
    m_pBmp->bmiHeader.biSizeImage = 0;
    m_pBmp->bmiHeader.biXPelsPerMeter = 0;
    m_pBmp->bmiHeader.biYPelsPerMeter = 0;
    m_pBmp->bmiHeader.biClrUsed = 0;
    m_pBmp->bmiHeader.biClrImportant = 0;
}
      
//////////////////////////////////////   Compression Library   . /////////////////////////////
       /////  .... Where it takes commmand line parameters (i) .Bmp file (ii) .Jpeg(any name of the file
 
int
main (int argc, char **argv)
{
struct jpeg_compress_struct cinfo;
	struct jpeg_error_mgr jerr;
cjpeg_source_ptr src_mgr;
	FILE * input_file;
	FILE * output_file;
      .......
      ......
if ((input_file = fopen(argv[i], READ_BINARY)) == NULL) {
		fprintf(stderr, "can't open %s\n", argv[i]);
		exit(EXIT_FAILURE);
    }
	else {
		fprintf(stderr, "Opened %s\n", argv[i]);
		i++;
	}
    if ((output_file = fopen(argv[i], WRITE_BINARY)) == NULL) {
		fprintf(stderr, "can't open %s\n", argv[i]);
		exit(EXIT_FAILURE);
    }
	else {
		fprintf(stderr, "Opened %s\n", argv[i]);
		i++;
	}
src_mgr = jinit_read_bmp(&cinfo);
	src_mgr->input_file = input_file;
(*src_mgr->start_input) (&cinfo, src_mgr);
jpeg_default_colorspace(&cinfo);
jpeg_stdio_dest(&cinfo, output_file);
jpeg_start_compress(&cinfo, TRUE);
	/* Process data */
while (cinfo.next_scanline < cinfo.image_height) {
		num_scanlines = (*src_mgr->get_pixel_rows) (&cinfo, src_mgr);
		(void) jpeg_write_scanlines(&cinfo, src_mgr->buffer, num_scanlines);
	}
 
	/* Finish compression and release memory */
	(*src_mgr->finish_input) (&cinfo, src_mgr);
	jpeg_finish_compress(&cinfo);
	jpeg_destroy_compress(&cinfo);
 
	/* Close files */
	fclose(input_file);
	fclose(output_file);
 
	return 0;			/* suppress no-return-value warnings */
}

Open in new window

0
Comment
Question by:kishan66
2 Comments
 
LVL 9

Expert Comment

by:JohnGaby
ID: 24109342
0
 

Accepted Solution

by:
kishan66 earned 0 total points
ID: 24591793
i found solution myself.
anyways thank you.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question