Was muss ich in dem Code verändern für 300DPI und 90% Qualität?



  • HALLO!
    Folgender Code speichert mir ein JPEG, ich möchte wissen was ich verändern muss damit das gespeicherte JPEG 300DPI und 90% Qualität hat.
    BitCount muss bestimmt verändert werden.

    Danke schonmal

    me 🙂

    int StoreBitmapAsJPEG(LPSTR fileName, HBITMAP hBitmap)
    {
    	BITMAP 		bm; 		//-- Bitmap information --/
    	BITMAPINFO 	*pBmi;		//-- Part of bitmap file information --/
    	HDC  		hdc;		//-- Drawing context --/
    
    	HANDLE 		hMem;		//-- Handle to memory for bitmap --/
    	PBYTE 		pBuf;		//-- Memory for bitmap --/
    
    	LONG 		colorSize, dataSize; //-- Size needed to store Color/Data --/
    	WORD 		bitCount;	//-- Number of bits per pixel --/
    
    	struct jpeg_compress_struct cinfo;
    	struct my_jpeg_error_mgr jerr;
        FILE * fw;
    	JSAMPROW row_pointer[1];	/* pointer to a single row */
    	int row_stride;			/* physical row width in buffer */
    
    	// ----------
    	cinfo.err = jpeg_std_error(&jerr.pub);
    	jerr.fatal_error = 0;
    	jerr.pub.error_exit = JPEG_ErrorHandler;
    	jerr.pub.output_message = JPEG_ErrorHandler_output_message;
    	jpeg_create_compress(&cinfo);
    
    	//-- Get the information about the Bitmap --/
    	if (GetObject(hBitmap, sizeof(BITMAP), &bm) == 0)
    		return 1;
    
    	bitCount = 24;
    	colorSize = 0;
    
    	dataSize = bmAlignDouble(bm.bmWidth * bitCount) * bm.bmHeight;
    
    	//-- Create the file --/
    	if ((fw = fopen(fileName, "wb")) == NULL) {
    	    MessageBeep(-1);
    	    return 1;
    	}
    	jpeg_stdio_dest(&cinfo, fw);
    
    	cinfo.image_width = bm.bmWidth; 	/* image width and height, in pixels */
    	cinfo.image_height = bm.bmHeight;
    	cinfo.input_components = 3;	/* # of color components per pixel */
    	cinfo.in_color_space = JCS_RGB; /* colorspace of input image */
    
    	jpeg_set_defaults(&cinfo);
    
    	//-- Allocate memory for the bitmap info structure --/
    	pBmi = (BITMAPINFO *)malloc(sizeof(BITMAPINFOHEADER) + colorSize);
    
    	if (pBmi != NULL) {
    		//-- Fill in the Bitmap info header --/
    		pBmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    		pBmi->bmiHeader.biWidth = bm.bmWidth;
    		pBmi->bmiHeader.biHeight = -bm.bmHeight;
    		pBmi->bmiHeader.biPlanes = 1;
    		pBmi->bmiHeader.biBitCount = bitCount;
    		pBmi->bmiHeader.biCompression = 0;
    		pBmi->bmiHeader.biSizeImage = dataSize;
    		pBmi->bmiHeader.biXPelsPerMeter = 0;
    		pBmi->bmiHeader.biYPelsPerMeter = 0;
    		pBmi->bmiHeader.biClrUsed = 0;
    		pBmi->bmiHeader.biClrImportant = 0;
    		//-- Create the memory Bitmap --/
    		hMem = GlobalAlloc(GMEM_FIXED, dataSize);
    		if (hMem != NULL) {
    			pBuf = (PBYTE)GlobalLock(hMem);
    
    			//-- Get the bitmap bits in device independent format --/
    			hdc = GetDC(NULL);
    			if (GetDIBitsnew(hdc, hBitmap, 0, bm.bmHeight, pBuf, pBmi, DIB_RGB_COLORS) != 0) {
    		//	if (GetDIBits(hdc, hBitmap, 0, -1000, pBuf, pBmi, DIB_RGB_COLORS) != 0) {
    
    			ReleaseDC(NULL, hdc);
    			//	 {
    				 row_stride = bmAlignDouble(bm.bmWidth * bitCount);	/* JSAMPLEs per row in image_buffer */
    				 //BGRtoRGB(pBuf, bm.bmWidth, bm.bmHeight, row_stride / 3 - bm.bmWidth);
    
    			     //-- Write to file --/
    				 jpeg_start_compress(&cinfo, TRUE);
    
    				 while (cinfo.next_scanline < cinfo.image_height) {
    				 	row_pointer[0] = &pBuf[cinfo.next_scanline * row_stride];
    				    jpeg_write_scanlines(&cinfo, row_pointer, 1);
    					//Sleep(10);
    				 }
    		         jpeg_finish_compress(&cinfo);
    			}
    
    			//-- Clean up --/
    			GlobalUnlock(hMem);
    			GlobalFree(hMem);
    		}
    	}
    	jpeg_destroy_compress(&cinfo);
    	fclose(fw);
    	return 0;
    }
    


  • Ich hab mal gegoogled, weiß aber nicht, ob's stimmt:

    // Quality: integer zwischen 0 und 100
    jpeg_set_quality (&cinfo,Quality,TRUE);



  • Hallo, ich sehe grad nicht welche Bibliothek du benutzt. Was includierst du denn dafür?



  • die jpeglib 🙂



  • Hallo,

    wo bekommt man die den her?



  • ich denk mal da JPEGLIB



  • Ich hab jetzt die jpeg.lib eingebunden, aber es gibt noch 30 fehler!
    was muss ich noch tun?



  • Also nochmal:

    Ich bis absoluter Anfänger.
    Ich benutze MS Visual C++
    Ein fenster kann ich mit Winapi erstellen und eine Bitmap kann ich auch ordentlich laden.

    Was muss ich tun, damit der gezeigte code läuft.
    1. In das Projekt kopieren (klar)
    2. ?? (Bitte genau schreiben, was ich machen muss!)



  • Da ist doch sicher eine Doku dabei 🙄
    Ansonsten musst du wohl eine oder mehrere Header und Libs einbinden - weiß aber nicht welche 😃



  • Ich find eure Hilfe super nett und geil...Mike les dir die Doku durch, ist nicht leicht und ohne WINAPIdurchblick noch viel viel schwerer - bei Gelegenheit schick ich dir mal ein Projekt wenn ich das mal hinkrieg ohne Verlinkfehler 🙂

    jpegs


Anmelden zum Antworten