当前位置: 首页>>代码示例>>C++>>正文


C++ Bitmap类代码示例

本文整理汇总了C++中Bitmap的典型用法代码示例。如果您正苦于以下问题:C++ Bitmap类的具体用法?C++ Bitmap怎么用?C++ Bitmap使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Bitmap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: GetWindow

    Bitmap GetWindow( HWND h ) {
        RECT rect;
        RECT rect2;

        Bitmap ret;
        if( !GetClientRect( h, &rect ) ) {
            return ret;
        }
        if( !GetWindowRect( h, &rect2 ) ) {
            return ret;
        }



        int width = rect2.right - rect2.left;
        int height = rect2.bottom - rect2.top;
        if( width <= 0 || height <= 0 ) { return ret; }
        int x = ( int )( rect2.left ); // + ((int)(rect.right-rect.left) - (int)(rect2.right-rect2.left))/2;
        int y = ( int )( rect2.top ); // + ((int)(rect.bottom-rect.top) - (int)(rect2.bottom-rect2.top)) - x;

        if( h == GetDesktopWindow() ) {
            width = GetSystemMetrics ( SM_CXVIRTUALSCREEN );
            height = GetSystemMetrics ( SM_CYVIRTUALSCREEN );
            x = GetSystemMetrics ( SM_XVIRTUALSCREEN );
            y = GetSystemMetrics ( SM_YVIRTUALSCREEN );
        }
        h = GetDesktopWindow();

        HDC hDC = GetDC( h );
        HDC hCaptureDC = CreateCompatibleDC( hDC );
        HBITMAP hCaptureBitmap = CreateCompatibleBitmap( hDC,
                                 width, height );
        HGDIOBJ hOld = SelectObject( hCaptureDC, hCaptureBitmap );
        BitBlt( hCaptureDC, 0, 0, width, height,
                hDC, x, y, SRCCOPY | CAPTUREBLT );


        SelectObject( hCaptureDC, hOld );

        BITMAPINFOHEADER bmi = {0};
        bmi.biSize = sizeof( BITMAPINFOHEADER );
        bmi.biPlanes = 1;
        bmi.biBitCount = 32;
        bmi.biWidth = width;
        bmi.biHeight = -height;
        bmi.biCompression = BI_RGB;
        bmi.biSizeImage = 0;// 3 * ScreenX * ScreenY;


        BYTE* ScreenData = ( BYTE* )malloc( 4 * width * height );

        GetDIBits( hCaptureDC, hCaptureBitmap, 0, height, ScreenData, ( BITMAPINFO* )&bmi, DIB_RGB_COLORS );

        ret.Write( width, height, ScreenData );
        free( ScreenData );


        // SaveCapturedBitmap(hCaptureBitmap); //Place holder - Put your code
        //here to save the captured image to disk
        ReleaseDC( h, hDC );
        DeleteDC( hCaptureDC );
        DeleteObject( hCaptureBitmap );

        return ret;
    }
开发者ID:Aslai,项目名称:Frog-Lies,代码行数:65,代码来源:bitmap.cpp

示例2: CopyAnd

void
Canvas::CopyAnd(const Bitmap &src)
{
  CopyAnd(0, 0, GetWidth(), GetHeight(),
          src.GetNative(), 0, 0);
}
开发者ID:jaaaaf,项目名称:LK8000,代码行数:6,代码来源:Canvas.cpp

示例3: setAlpha

void AlphaMask::setAlpha(Bitmap& bmp) const {
	if (!alpha) return;
	Image img = bmp.ConvertToImage();
	setAlpha(img);
	bmp = Bitmap(img);
}
开发者ID:BestRCH,项目名称:magicseteditor,代码行数:6,代码来源:mask_image.cpp

示例4: Draw

/*
** Draws the meter on the double buffer
**
*/
bool CMeterBitmap::Draw(Graphics& graphics)
{
	if (!CMeter::Draw(graphics)) return false;

	int newY, newX;

	if (m_FrameCount == 0 || !m_Image.IsLoaded()) return false;	// Unable to continue

	Bitmap* bitmap = m_Image.GetImage();

	int x = GetX();
	int y = GetY();

	if (m_Extend)
	{
		int value = (int)m_Value;
		value = max(0, value);		// Only positive integers are supported

		int transitionValue = (int)m_TransitionStartValue;
		transitionValue = max(0, transitionValue);		// Only positive integers are supported

		// Calc the number of numbers
		int numOfNums = 0;

		if (m_Digits > 0)
		{
			numOfNums = m_Digits;
		}
		else
		{
			int tmpValue = value;

			do
			{
				++numOfNums;
				if (m_FrameCount == 1)
				{
					tmpValue /= 2;
				}
				else
				{
					tmpValue /= m_FrameCount;
				}
			}
			while (tmpValue > 0);
		}

		// Blit the images
		int offset;
		if (m_Align == ALIGN_RIGHT)
		{
			offset = 0;
		}
		else if (m_Align == ALIGN_CENTER)
		{
			offset = numOfNums * (m_W + m_Separation) / 2;
		}
		else
		{
			offset = numOfNums * (m_W + m_Separation);
		}

		do
		{
			offset = offset - (m_W + m_Separation);

			Rect r(x + offset, y, m_W, m_H);

			int realFrames = (m_FrameCount / (m_TransitionFrameCount + 1));
			int frame = (value % realFrames) * (m_TransitionFrameCount + 1);

			// If transition is ongoing the pick the correct frame
			if (m_TransitionStartTicks > 0)
			{
				int diffTicks = (int)(CSystem::GetTickCount64() - m_TransitionStartTicks);

				int range = ((value % realFrames) - (transitionValue % realFrames)) * (m_TransitionFrameCount + 1);
				if (range < 0)
				{
					range += m_FrameCount;
				}
				int frameAdjustment = range * diffTicks / ((m_TransitionFrameCount + 1) * m_MeterWindow->GetTransitionUpdate());
				if (frameAdjustment > range)
				{
					m_TransitionStartTicks = 0;		// The transition is over. Draw with the real value.
				}
				else
				{
					frame = (transitionValue % realFrames) * (m_TransitionFrameCount + 1);
					frame += frameAdjustment;
					frame %= m_FrameCount;
				}
			}

//			LogWithArgs(LOG_DEBUG, L"[%u] Value: %f Frame: %i (Transition = %s)", GetTickCount(), m_Value, frame, m_TransitionStartTicks > 0 ? L"true" : L"false");

//.........这里部分代码省略.........
开发者ID:Dinesh-Ramakrishnan,项目名称:rainmeter,代码行数:101,代码来源:MeterBitmap.cpp

示例5: Copy

void
Canvas::Copy(const Bitmap &src)
{
  Copy(0, 0, src.GetWidth(), src.GetHeight(), src, 0, 0);
}
开发者ID:Adrien81,项目名称:XCSoar,代码行数:5,代码来源:Canvas.cpp

示例6: BitmapSizeFromData

// adapted from http://cpansearch.perl.org/src/RJRAY/Image-Size-3.230/lib/Image/Size.pm
Size BitmapSizeFromData(const char *data, size_t len)
{
    Size result;
    ByteReader r(data, len);
    switch (GfxFormatFromData(data, len)) {
    case Img_BMP:
        if (len >= sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER)) {
            BITMAPINFOHEADER bmi;
            bool ok = r.UnpackLE(&bmi, sizeof(bmi), "3d2w6d", sizeof(BITMAPFILEHEADER));
            CrashIf(!ok);
            result.Width = bmi.biWidth;
            result.Height = bmi.biHeight;
        }
        break;
    case Img_GIF:
        if (len >= 13) {
            // find the first image's actual size instead of using the
            // "logical screen" size which is sometimes too large
            size_t ix = 13;
            // skip the global color table
            if ((r.Byte(10) & 0x80))
                ix += 3 * (1 << ((r.Byte(10) & 0x07) + 1));
            while (ix + 8 < len) {
                if (r.Byte(ix) == 0x2C) {
                    result.Width = r.WordLE(ix + 5);
                    result.Height = r.WordLE(ix + 7);
                    break;
                }
                else if (r.Byte(ix) == 0x21 && r.Byte(ix + 1) == 0xF9)
                    ix += 8;
                else if (r.Byte(ix) == 0x21 && r.Byte(ix + 1) == 0xFE) {
                    const char *commentEnd = r.Find(ix + 2, 0x00);
                    ix = commentEnd ? commentEnd - data + 1 : len;
                }
                else if (r.Byte(ix) == 0x21 && r.Byte(ix + 1) == 0x01 && ix + 15 < len) {
                    const char *textDataEnd = r.Find(ix + 15, 0x00);
                    ix = textDataEnd ? textDataEnd - data + 1 : len;
                }
                else if (r.Byte(ix) == 0x21 && r.Byte(ix + 1) == 0xFF && ix + 14 < len) {
                    const char *applicationDataEnd = r.Find(ix + 14, 0x00);
                    ix = applicationDataEnd ? applicationDataEnd - data + 1 : len;
                }
                else
                    break;
            }
        }
        break;
    case Img_JPEG:
        // find the last start of frame marker for non-differential Huffman/arithmetic coding
        for (size_t ix = 2; ix + 9 < len && r.Byte(ix) == 0xFF; ) {
            if (0xC0 <= r.Byte(ix + 1) && r.Byte(ix + 1) <= 0xC3 ||
                0xC9 <= r.Byte(ix + 1) && r.Byte(ix + 1) <= 0xCB) {
                result.Width = r.WordBE(ix + 7);
                result.Height = r.WordBE(ix + 5);
            }
            ix += r.WordBE(ix + 2) + 2;
        }
        break;
    case Img_JXR:
    case Img_TIFF:
        if (len >= 10) {
            bool isBE = r.Byte(0) == 'M', isJXR = r.Byte(2) == 0xBC;
            CrashIf(!isBE && r.Byte(0) != 'I' || isJXR && isBE);
            const WORD WIDTH = isJXR ? 0xBC80 : 0x0100, HEIGHT = isJXR ? 0xBC81 : 0x0101;
            size_t idx = r.DWord(4, isBE);
            WORD count = idx <= len - 2 ? r.Word(idx, isBE) : 0;
            for (idx += 2; count > 0 && idx <= len - 12; count--, idx += 12) {
                WORD tag = r.Word(idx, isBE), type = r.Word(idx + 2, isBE);
                if (r.DWord(idx + 4, isBE) != 1)
                    continue;
                else if (WIDTH == tag && 4 == type)
                    result.Width = r.DWord(idx + 8, isBE);
                else if (WIDTH == tag && 3 == type)
                    result.Width = r.Word(idx + 8, isBE);
                else if (WIDTH == tag && 1 == type)
                    result.Width = r.Byte(idx + 8);
                else if (HEIGHT == tag && 4 == type)
                    result.Height = r.DWord(idx + 8, isBE);
                else if (HEIGHT == tag && 3 == type)
                    result.Height = r.Word(idx + 8, isBE);
                else if (HEIGHT == tag && 1 == type)
                    result.Height = r.Byte(idx + 8);
            }
        }
        break;
    case Img_PNG:
        if (len >= 24 && str::StartsWith(data + 12, "IHDR")) {
            result.Width = r.DWordBE(16);
            result.Height = r.DWordBE(20);
        }
        break;
    case Img_TGA:
        if (len >= 16) {
            result.Width = r.WordLE(12);
            result.Height = r.WordLE(14);
        }
        break;
    case Img_WebP:
        if (len >= 30 && str::StartsWith(data + 12, "VP8 ")) {
//.........这里部分代码省略.........
开发者ID:Nargesf,项目名称:Sumatrapdf,代码行数:101,代码来源:GdiPlusUtil.cpp

示例7: pango_context_set_matrix

void FontSupport::drawText(const WFont& font, const WRectF& rect,
			   const WTransform& transform, Bitmap& bitmap,
			   WFlags<AlignmentFlag> flags,
			   const WString& text)
{
  PANGO_LOCK;

  enabledFontFormats = enabledFontFormats_;

  PangoMatrix matrix;
  matrix.xx = transform.m11();
  matrix.xy = transform.m21();
  matrix.yx = transform.m12();
  matrix.yy = transform.m22();
  matrix.x0 = transform.dx();
  matrix.y0 = transform.dy();

  std::string utf8 = text.toUTF8();

  std::vector<PangoGlyphString *> glyphs;
  int width;

  pango_context_set_matrix(context_, &matrix);

  /*
   * Oh my god, somebody explain me why we need to do this...
   */
  WFont f = font;
  f.setSize(font.sizeLength().toPixels()
	    / pango_matrix_get_font_scale_factor(&matrix));

  GList *items = layoutText(f, utf8, glyphs, width);
  pango_context_set_matrix(context_, nullptr);

  AlignmentFlag hAlign = flags & AlignHorizontalMask;

  /* FIXME handle bidi ! */

  double x;
  switch (hAlign) {
  case AlignmentFlag::Left:
    x = rect.left();
    break;
  case AlignmentFlag::Right:
    x = rect.right() - pangoUnitsToDouble(width);
    break;
  case AlignmentFlag::Center:
    x = rect.center().x() - pangoUnitsToDouble(width/2);
    break;
  default:
    x = 0;
  }

  AlignmentFlag vAlign = flags & AlignVerticalMask;

  PangoFont *pangoFont = matchFont(font).pangoFont();
  PangoFontMetrics *metrics = pango_font_get_metrics(pangoFont, nullptr);

  double ascent
    = pangoUnitsToDouble(pango_font_metrics_get_ascent(metrics));
  double descent 
    = pangoUnitsToDouble(pango_font_metrics_get_descent(metrics));

  pango_font_metrics_unref(metrics);

  double baseline = ascent;
  double height = ascent + descent;

  double y;
  switch (vAlign) {
  case AlignmentFlag::Top:
    y = rect.top() + baseline;
    break;
  case AlignmentFlag::Middle:
    y = rect.center().y() - height / 2 + baseline;
    break;
  case AlignmentFlag::Bottom:
    y = rect.bottom() - height + baseline;
    break;
  default:
    y = 0;
  }

  FT_Bitmap bmp;
  bmp.buffer = bitmap.buffer();
  bmp.width = bitmap.width();
  bmp.rows = bitmap.height();
  bmp.pitch = bitmap.pitch();
  bmp.pixel_mode = FT_PIXEL_MODE_GRAY;
  bmp.num_grays = 16; // ???

  GList *elem;
  unsigned i = 0;

  for (elem = items; elem; elem = elem->next) {
    PangoItem *item = (PangoItem *)elem->data;
    PangoAnalysis *analysis = &item->analysis;

    PangoGlyphString *gl = glyphs[i++];

//.........这里部分代码省略.........
开发者ID:AlexanderKotliar,项目名称:wt,代码行数:101,代码来源:FontSupportPango.C

示例8: uvtrans

bool plDistributor::IFailsProbBitmap(int iFace, const Point3& bary) const
{
    // If we don't have a probability map, or we don't have
    // valid coordinates into it, just return false. That is,
    // with no valid probability map, everything goes.
    int uvwChan = 1;
    Matrix3 uvtrans(true);
    Bitmap* bm = nil;
    UINT filtType = BMM_FILTER_PYRAMID;
    if( fProbBitmapTex )
    {
        uvwChan = fProbBitmapTex->GetMapChannel();
        fProbBitmapTex->GetUVTransform(uvtrans);

        bm = fProbBitmapTex->GetBitmap(TimeValue(0));

        if( bm && !bm->HasFilter() )
        {
            switch( fProbBitmapTex->GetFilterType() )
            {
            default:
            case FILTER_PYR:
                filtType = BMM_FILTER_PYRAMID;
                break;
            case FILTER_SAT:
                filtType = BMM_FILTER_SUM;
                break;
            case FILTER_NADA:
                filtType = BMM_FILTER_NONE;
                break;
            }
        }
    }
    else if( fProbLayerTex )
    {
        uvwChan = fProbLayerTex->GetMapChannel();
        fProbLayerTex->GetUVTransform(uvtrans);

        bm = fProbLayerTex->GetBitmap(TimeValue(0));

    }

    if( !bm )
        return false;

    if( !bm->HasFilter() )
        bm->SetFilter(filtType);

    bm->PrepareGChannels(&bm->Storage()->bi);

    if( !fSurfMesh->mapSupport(uvwChan) )
        return false;

    if( !fSurfMesh->mapFaces(uvwChan) || !fSurfMesh->mapVerts(uvwChan) )
        return false;

    // Lookup the appropriate texel value
    Point3 uvw;
    uvw = fSurfMesh->mapVerts(uvwChan)[fSurfMesh->mapFaces(uvwChan)[iFace].getTVert(0)] * bary[0];
    uvw += fSurfMesh->mapVerts(uvwChan)[fSurfMesh->mapFaces(uvwChan)[iFace].getTVert(1)] * bary[1];
    uvw += fSurfMesh->mapVerts(uvwChan)[fSurfMesh->mapFaces(uvwChan)[iFace].getTVert(2)] * bary[2];

    uvw = uvw * uvtrans;

    float fu = uvw.x - int(uvw.x);
    if( fu < 0 )
        fu += 1.f;
    float fv = 1.0f - (uvw.y - int(uvw.y));
    if( fv < 0 )
        fv += 1.f;
    float du = 1.f / bm->Width();
    float dv = 1.f / bm->Height();

    BMM_Color_fl evCol;
    bm->GetFiltered(fu, fv, du, dv, &evCol);
    
    float frac;
    switch( fProbColorChan )
    {
    case kRed:
        frac = evCol.r;
        break;
    case kGreen:
        frac = evCol.g;
        break;
    case kBlue:
        frac = evCol.b;
        break;
    case kAlpha:
        frac = evCol.a;
        break;
    case kAverageRedGreen:
        frac = (evCol.r + evCol.g) / 2.f;
        break;
    case kAverageRedGreenTimesAlpha:
        frac = (evCol.r + evCol.g) / 2.f * evCol.a;
        break;
    case kAverage:
        frac = (evCol.r + evCol.g + evCol.b ) / 3.f;
        break;
//.........这里部分代码省略.........
开发者ID:Asteral,项目名称:Plasma,代码行数:101,代码来源:plDistributor.cpp

示例9: main

int main (int argc, char * Files []) {

	cout << "PCX to VBM Converter Version 0.1Beta\n" << "Working . . .\n";

	if ( argc < 2 ) {
		cout << "Not Enough Arguments\n" << "Usage:\n" <<
			"\tpcx2vbm pcxfile1 pcxfile2 . . . pcxfilen" <<
			"\tWhere pcxfile1 to pcxfile2 are PCX files to be converted\n";
	}

	for (int tru = 1; tru <= (argc - 1); tru++) {

		//make names usable
      //char * thisFile = strcpy(thisFile, *(Files + tru));
      //char * writeFile = strcpy(writeFile, *(Files + tru));
      char thisFile[128];
      char writeFile[128];
      //char * thisFile = new char [12];
      //char * writeFile = new char [12];
      strcpy(thisFile, *(Files + tru));
      strcpy(writeFile, *(Files + tru));
		int repplace = 0;
		for (int tru2 = 0; tru2 < 20; tru2++) {
			char thechar = *(writeFile + tru2);
			if (thechar == '.') {
				repplace = tru2;
            break;
			}
		}
		char * vbmstr = ".vbm";
		memcpy(writeFile + repplace, vbmstr, 4);

		cout << "Converting " << thisFile <<  " to " << writeFile << "\n";

		LINEAR_BITMAP * TempBitmap = new LINEAR_BITMAP;
		UCHAR PCXPal[256][3];

		//load the pcx file
		TempBitmap = LoadPCX(thisFile, PCXPal);
		if (TempBitmap == NULL) {
			delete TempBitmap;
			cout << "\nCan't load file: " << thisFile << "\n";
			return 1;
		}

		//transfer stuff from one bitmap to another
		Bitmap * MyBitmap = new Bitmap;
		UCHAR * tPointer = (UCHAR *)&(TempBitmap->Data);
		//convert stuff
		MyBitmap->MakeNewBmp (TempBitmap->Width, TempBitmap->Height, tPointer, PCXPal);
		//save it
		MyBitmap->SaveToDisk (writeFile);
      //TheScreen->SetMode13h(); //set mode13h (don't forget)
      //MyBitmap->PutRegular (0, 0, VGAMEMORY);
      //getch();
      //TheScreen->SetTextMode(); //set mode13h (don't forget)
      delete MyBitmap;
	}

	cout << "Done";

	return 0;
}
开发者ID:lucian303,项目名称:GameKit,代码行数:63,代码来源:PCX2VBM.CPP

示例10: ASSERT

//************************************
// Method:    getBitmapFromComplex
// FullName:  CFFTMachine::getBitmapFromComplex
// Access:    protected 
// Returns:   Bitmap*
// Qualifier:
// Parameter: LPCOMPLEX pSource
// Parameter: INT nWidth
// Parameter: INT nHeight
//************************************
Bitmap* CFFTMachine::getBitmapFromComplex(LPCOMPLEX* ppSource,INT  in_nWidth,INT in_nHeight)
{
	ASSERT(ppSource);
	BYTE* pBuffer = NULL;
	pBuffer = new BYTE[in_nWidth * in_nHeight * 3];
	
	//change the coordinate and calculate the value to display
	/*
			0	   --->		cols (x)
		  0	+-------+-------+	
	  		|	1	|   2   |
		  |	|		|		|
		  |	+-------+-------+
		  Y	|	3  	|	4	|
			|		|		|
	   rows	+-------+-------+
	    (y)

		Coordinate transform
		1<->4; 2<->3 
	*/

	if(pBuffer != NULL)
	{
		FillMemory(pBuffer, in_nWidth * in_nHeight * 3, 0);
		INT nWidth_2  = in_nWidth/2;
		INT nHeight_2 = in_nHeight/2;
		
		for(INT y=0; y<in_nHeight; y++)
		{
			for (INT x=0; x<in_nWidth; x++)	
			{
				BYTE nPixelVal = 0;
				//in the part1 --> move to part 4
				if((x<nWidth_2)&&(y<nHeight_2))
					nPixelVal = valueTransform(ppSource[y + nHeight_2][x + nWidth_2].real);
				//in the part2 --> move to part 3
				else if ((x>=nWidth_2)&&(y<nHeight_2))
					nPixelVal = valueTransform(ppSource[y + nHeight_2][x - nWidth_2].real);
				//in the part3 --> move to part 2
				else if((x<nWidth_2)&&(y>=nHeight_2))
					nPixelVal = valueTransform(ppSource[y - nHeight_2][x + nWidth_2].real);
				//in the part4 --> move to part 1
				else
					nPixelVal = valueTransform(ppSource[y - nHeight_2][x - nWidth_2].real);					
					
				*(pBuffer + 3*(y*in_nWidth + x) + 0) = nPixelVal;	//R
				*(pBuffer + 3*(y*in_nWidth + x) + 1) = nPixelVal;	//G
				*(pBuffer + 3*(y*in_nWidth + x) + 2) = nPixelVal;	//B
			}
		}
		//adjust image
		for (INT j=0;j<nHeight_2;j++)
		{
			for(INT k=0;k<in_nWidth;k++)
			{
				BYTE temp = *(pBuffer + 3*(j*in_nWidth + k) + 0);
				*(pBuffer + 3*(j*in_nWidth + k) + 0) = *(pBuffer + 3*((in_nHeight- j -1)*in_nWidth+k));	//R
				*(pBuffer + 3*(j*in_nWidth + k) + 1) = *(pBuffer + 3*((in_nHeight- j -1)*in_nWidth+k));
				*(pBuffer + 3*(j*in_nWidth + k) + 2) = *(pBuffer + 3*((in_nHeight- j -1)*in_nWidth+k));
				*(pBuffer + 3*((in_nHeight- j -1)*in_nWidth+k) + 0) =  temp;
				*(pBuffer + 3*((in_nHeight- j -1)*in_nWidth+k) + 1) =  temp;
				*(pBuffer + 3*((in_nHeight- j -1)*in_nWidth+k) + 2) =  temp;
			}
		}
	}

	Bitmap* pRetBmp = NULL; 
	BITMAPINFO t_BMPinfo;
	BITMAPINFOHEADER* pBMPInfoHeader = &(t_BMPinfo.bmiHeader); 
	memset(pBMPInfoHeader, 0, sizeof(BITMAPINFOHEADER));
	//Create bitmap header	
	pBMPInfoHeader->biSize			= sizeof(BITMAPINFOHEADER);
	pBMPInfoHeader->biWidth			= in_nWidth;
	pBMPInfoHeader->biHeight		= in_nHeight;
	pBMPInfoHeader->biPlanes		= 1;
	pBMPInfoHeader->biCompression	= BI_RGB;
	pBMPInfoHeader->biBitCount		= IMP_MONOBMP_BITS * 3;
	pBMPInfoHeader->biSizeImage		= in_nWidth * in_nHeight * 3;

	if(pBuffer != NULL)	pRetBmp = Bitmap::FromBITMAPINFO(&t_BMPinfo,pBuffer);		
	
	if(pRetBmp == NULL)
	{
		delete[] pBuffer;
		pBuffer = NULL;
	}

	
#ifdef _DEBUG
//.........这里部分代码省略.........
开发者ID:phamquy,项目名称:ImageProc,代码行数:101,代码来源:FFTMachine.cpp

示例11: if

void FirmOffensive2::put_info(int refreshFlag)
{
    if( !should_show_info() )
        return;

    vga.active_buf->put_bitmap( INFO_X1, INFO_Y1, image_gameif.read("MISSBASE") );

    int hitPoints;
    String str;
    int offsetX = 0;
    int offsetY = 0;

    if( hit_points > (float)0 && hit_points < (float)1 )
        hitPoints = 1;		// display 1 for value between 0 and 1
    else
        hitPoints = (int) hit_points;

    if ( max_hit_points() )
    {
        offsetX = -35;
        offsetY = -14;
        short*	hitPointBitmap =NULL;
        int ratio = hitPoints *40 / (int)max_hit_points();
        int size = hitPoints *76 / (int)max_hit_points();

        //106 x 35 --- 15 to 90 ie. 0 to 40
        hitPointBitmap = (short *)mem_add( BitmapW::size(15 +size, 35) );
        if (ratio <11)
            vga.active_buf->put_bitmap_trans( INFO_X1 +80 +20 +offsetX, INFO_Y1 +49 +offsetY, image_spict.read("MTR_B2"));
        else if (ratio <40)
            vga.active_buf->put_bitmap_trans( INFO_X1 +80 +20 +offsetX, INFO_Y1 +49 +offsetY, image_spict.read("MTR_B3"));
        else
            vga.active_buf->put_bitmap_trans( INFO_X1 +80 +20 +offsetX, INFO_Y1 +49 +offsetY, image_spict.read("MTR_B4"));

        vga.active_buf->read_bitmapW( INFO_X1 +80 +20 +offsetX, INFO_Y1 +49 +offsetY, INFO_X1 +94 +20 +size +offsetX, INFO_Y1 +80 +offsetY, hitPointBitmap );
        vga.active_buf->put_bitmap_trans( INFO_X1 +80 +20 +offsetX, INFO_Y1 +49 +offsetY, image_spict.read("MTR_B1"));
        vga.active_buf->put_bitmapW( INFO_X1 +80 +20 +offsetX, INFO_Y1 +49 +offsetY, hitPointBitmap );
        mem_del( hitPointBitmap );

        font_whbl.center_put( INFO_X1 +43, INFO_Y1 +45, INFO_X1 +65, INFO_Y1 +57, m.format((int)hitPoints,4));
        font_whbl.center_put( INFO_X1 +169, INFO_Y1 +45, INFO_X1 +191, INFO_Y1 +57, m.format((int)max_hit_points(),4) );
    }

    // font_whbl.center_put( INFO_X1 +12, INFO_Y1 +9, INFO_X2, INFO_Y1 +21, "Offensive Building 3", 0, 1 );
    font_whbl.center_put( INFO_X1 +12, INFO_Y1 +9, INFO_X2, INFO_Y1 +21, firm_name(), 0, 1 );

    FirmBuild* firmBuild = firm_res.get_build(firm_build_id);
    short *colorRemapTable = firmBuild->get_color_remap_table(nation_recno, firm_array.selected_recno == firm_recno);
    colorRemapTable = firm_res.calc_color_remap_table( colorRemapTable, 1.0f );

    FirmBitmap* firmBitmap = firm_res.get_bitmap(firmBuild->first_bitmap(1));
    if( firmBitmap )
    {
        Bitmap* bitmapPtr = (Bitmap *) firmBuild->res_bitmap.read_imported(firmBitmap->bitmap_ptr);

        int x1;
        int y1;
        int srcX2;
        int srcY2;

        if (config.building_size == 1)
        {
            x1 = INFO_X1 +130;
            y1 = INFO_Y1 +140;
        }
        else
        {
            x1 = INFO_X1 +120;
            y1 = INFO_Y1 +142;
        }

        x1 += firmBitmap->offset_x;
        y1 += firmBitmap->offset_y;
        int x2 = x1 + bitmapPtr->get_width() -1;
        int y2 = y1 + bitmapPtr->get_height() -1;
        int srcX1 = max(x1, INFO_X1+15)-x1;
        int srcY1 = 0;

        if (config.building_size == 1)
        {
            srcX2 = min(x2, INFO_X2)-x1;
            srcY2 = min(y2, INFO_Y1+227)-y1;
        }
        else
        {
            srcX2 = min(x2, INFO_X2)-x1;
            srcY2 = min(y2, INFO_Y2)-y1;
        }

        vga.active_buf->put_bitmap_area_trans_remap_decompress(x1, y1, (char *) bitmapPtr, srcX1, srcY1, srcX2, srcY2, colorRemapTable);
    }
    /*
    	if (config.building_size == 1)
    		return;

    	firmBitmap = firm_res.get_bitmap(firmBuild->first_bitmap(firm_cur_frame[0]));
    	if( firmBitmap && firmBitmap->display_layer == 1 )
    	{
    		Bitmap* bitmapPtr = (Bitmap *) firmBuild->res_bitmap.read_imported(firmBitmap->bitmap_ptr);

//.........这里部分代码省略.........
开发者ID:mecirt,项目名称:7k2,代码行数:101,代码来源:of_off2i.cpp

示例12: CreateCompatibleDC

bool RichEditHost::RenderTo(Graphics& graphics, const MiniRect& rcRender)
{
    if (!m_pTextServices || !m_pEdit)
    {
        return false;
    }

    MiniRect rcRootRender = rcRender;
    MiniRect rcRoot;
    m_pEdit->GetClientRect(rcRoot);
    rcRootRender += rcRoot.TopLeft();

    Bitmap* pBitmap = graphics.GetBitmap();
    byte* pBytes = (byte*)pBitmap->LockBits(rcRootRender);
    for (int i = 0; i < rcRender.Height(); ++i)
    {
        MiniARGB* pSrc = (MiniARGB*)(pBytes + i * pBitmap->GetBytesWidth());
        MiniARGB* pDst = (MiniARGB*)(m_dib.GetData() + (i + rcRender.top) * m_dib.GetBytesWidth()) + rcRender.left;
        for (int j = 0; j < rcRender.Width(); ++j)
        {
            uint32 c = gTable[pSrc->alpha];
            pDst->blue = (uint32)(c * (uint32)pSrc->blue + (1 << 23)) >> 24;
            pDst->green = (uint32)(c * (uint32)pSrc->green + (1 << 23)) >> 24;
            pDst->red = (uint32)(c * (uint32)pSrc->red + (1 << 23)) >> 24;
            pDst->alpha = 0xFF;
            pDst++;
            pSrc++;
        }
    }

    RECTL rc = {0, 0, m_size.cx, m_size.cy};
    HRESULT hr = m_pTextServices->TxDraw(DVASPECT_CONTENT, 0, 0, 0, m_dib, 0, &rc, 0, 0, 0, 0, TXTVIEW_ACTIVE);
    if (SUCCEEDED(hr))
    {
        if (m_bFocus && m_bShowCaret && m_bEnableCaret && m_bCaretState && !GetReadOnly())
        {
            if (!m_hCaret)
            {
                ::PatBlt((HDC)m_dib, m_rcCaret.left, m_rcCaret.top, m_rcCaret.Width(), m_rcCaret.Height(), DSTINVERT);
            }
            else
            {
                HDC hdcMem = CreateCompatibleDC((HDC)m_dib);
                HGDIOBJ hOld = ::SelectObject(hdcMem, m_hCaret);    
                ::BitBlt((HDC)m_dib, m_rcCaret.left, m_rcCaret.top, m_rcCaret.Width(), m_rcCaret.Height(), hdcMem, 0, 0, SRCINVERT);
                ::SelectObject(hdcMem, hOld);
                ::DeleteDC(hdcMem);
            }
        }

        for (int i = 0; i < rcRender.Height(); ++i)
        {
            MiniARGB* pSrc = (MiniARGB*)(m_dib.GetData() + (i + rcRender.top) * m_dib.GetBytesWidth()) + rcRender.left;
            MiniARGB* pDst = (MiniARGB*)(pBytes + i * pBitmap->GetBytesWidth());
            for (int j = 0; j < rcRender.Width(); ++j)
            {
                uint32 alpha = (uint32)pDst->alpha + 1;
                pDst->blue = ((uint32)pSrc->blue * alpha) >> 8;
                pDst->green = ((uint32)pSrc->green * alpha) >> 8;
                pDst->red = ((uint32)pSrc->red * alpha) >> 8;
                pDst++;
                pSrc++;
            }
        }
    }

    return true;
}
开发者ID:kenlist,项目名称:miniframework,代码行数:68,代码来源:richedithost.cpp

示例13: EncodeBitmap

static bool EncodeBitmap(Bitmap& image, const WCHAR* pcszEncodeFormat, UINT32* ulSize, unsigned char** pData)
{
    // Setup encoder parameters
    // Create stream with 0 size
    IStream* pIStream = nullptr;

    if (CreateStreamOnHGlobal(nullptr, TRUE, (LPSTREAM*)&pIStream) != S_OK)
    {

        Log(logERROR, "Failed to create stream on global memory!\n");
        return false;
    }

    CLSID pngClsid;
    GetEncoderClsid(pcszEncodeFormat, &pngClsid);

    // Setup encoder parameters
    EncoderParameters encoderParameters;
    EncoderParameters* pEncoderParameters = &encoderParameters;
    ULONG quality = 50; // setup compression level for jpeg

    if (wcscmp(pcszEncodeFormat, L"image/jpeg") == 0)
    {
        encoderParameters.Count = 1;
        encoderParameters.Parameter[0].Guid = EncoderQuality;
        encoderParameters.Parameter[0].Type = EncoderParameterValueTypeLong;
        encoderParameters.Parameter[0].NumberOfValues = 1;

        // setup compression level
        encoderParameters.Parameter[0].Value = &quality;
    }
    else if (wcscmp(pcszEncodeFormat, L"image/png") == 0)
    {
        pEncoderParameters = nullptr;
    }
    else
    {
        Log(logERROR, "Failed to save image: Unrecognized format.");
        return false;
    }

    //  Save the image to the stream
    Status SaveStatus = image.Save(pIStream, &pngClsid, pEncoderParameters);

    if (SaveStatus != Ok)
    {
        // this should free global memory used by the stream

        // according to MSDN

        pIStream->Release();
        Log(logERROR, "Failed to save to stream!\n");
        return false;
    }

    // get the size of the stream
    ULARGE_INTEGER ulnSize;
    LARGE_INTEGER lnOffset;
    lnOffset.QuadPart = 0;

    if (pIStream->Seek(lnOffset, STREAM_SEEK_END, &ulnSize) != S_OK)
    {
        pIStream->Release();
        Log(logERROR, "Failed to get the size of the stream!\n");
        return false;
    }

    // now move the pointer to the beginning of the file
    if (pIStream->Seek(lnOffset, STREAM_SEEK_SET, nullptr) != S_OK)
    {
        pIStream->Release();
        Log(logERROR, "Failed to move the file pointer to the beginning of the stream!\n");
        return false;
    }

    unsigned char* pBuff = (unsigned char*)malloc((size_t)ulnSize.QuadPart);
    PsAssert(pBuff != nullptr)

    if (pBuff == nullptr)
    {
        return false;
    }

    ULONG ulBytesRead;

    if (pIStream->Read(pBuff, (ULONG)ulnSize.QuadPart, &ulBytesRead) != S_OK)
    {
        pIStream->Release();
        free(pBuff);
        return false;
    }

    *pData  = pBuff;
    *ulSize  = ulBytesRead;
    /*
       // I am going to save it to the file just so we can
       // load the jpg to a gfx program
       FILE *fFile;
       fFile = fopen("c:\\test.jpg", "w");
       if(fFile)
//.........这里部分代码省略.........
开发者ID:oldwinter,项目名称:CodeXL,代码行数:101,代码来源:SaveImage.cpp

示例14: CallWindowProc

LONG BitmapButton::ProcessMessage(HWND hWnd, size_t msg, size_t wParam, LONG lParam)
{
	if (msg == WM_LBUTTONDOWN)
	{
		long res = CallWindowProc(DefaultHandler, hWnd, msg, wParam, lParam);
		SendMessage(hWnd, BM_SETSTATE, (WPARAM)BST_PUSHED, 0);
		InvalidateRect(hWnd, NULL, false);
		return res;
	}
	else if (msg == WM_LBUTTONUP)
	{
		long res = CallWindowProc(DefaultHandler, hWnd, msg, wParam, lParam);
		SendMessage(hWnd, BM_SETSTATE, (WPARAM)0, 0);
		InvalidateRect(hWnd, NULL, false);
		return res;
	}
	else if ((msg == WM_COMMAND) || (msg == BN_CLICKED))
	{
		if (clickHandler)
		{
			clickHandler();
			return true;
		}
		else if (dClickHandler)
		{
			(clickListener->*dClickHandler)();
			return true;
		}
		else 
			return false;
	}
	else if (msg == WM_ERASEBKGND)
	{
/*
		HBRUSH hOldBrush;
		HPEN hOldPen;
		RECT rect;
		HDC hDC;

		hDC = GetDC(hWnd);
		hOldBrush = (HBRUSH)SelectObject(hDC, erasePen);
		hOldPen = (HPEN)SelectObject(hDC, eraseBrush);

		GetUpdateRect(hWnd, &rect, FALSE);
		::Rectangle(hDC, rect.left, rect.top, rect.right, rect.bottom);

		SelectObject(hDC, hOldPen);
		SelectObject(hDC, hOldBrush);

		InvalidateRect(hWnd, NULL, FALSE);
*/
		return true;	
	}
	else if (msg == WM_PAINT)
	{
		HDC tmp = dc;
		PAINTSTRUCT ps;
		RECT rect;

		BeginPaint(hWnd, &ps);

		rect.left = 0; rect.right = Width();
		rect.top = 0; rect.bottom = Height();

		HBRUSH hOldBrush = (HBRUSH)SelectObject(dc, erasePen);
		HPEN hOldPen = (HPEN)SelectObject(dc, eraseBrush);
		::Rectangle(dc, rect.left, rect.top, rect.right, rect.bottom);

		SelectObject(dc, hOldPen);
		SelectObject(dc, hOldBrush);

		int state = SendMessage(hWnd, BM_GETSTATE, 0, 0);
		Bitmap *bit;
		int offset;
		if ((state & BST_PUSHED) == 0)
		{
			DrawEdge(dc, &rect, EDGE_RAISED, BF_ADJUST | BF_RECT);
			if (IsEnabled())
				bit = upBitmap;
			else
				bit = disabledBitmap;
			offset = 0;
		}
		else
		{
			DrawEdge(dc, &rect, EDGE_SUNKEN, BF_ADJUST | BF_RECT);
			bit = downBitmap;
			offset = 1;
		}

		bit->Copy(*this, (Width() - bit->Width()) / 2 + offset, (Height() - bit->Height()) / 2 + offset, bit->Width(), 
				  bit->Height(), 0, 0);

		dc = tmp;
		return false;
	}

	return false;
}
开发者ID:HHMedina,项目名称:DePaul-UNI-Projects,代码行数:99,代码来源:BitmapButton.cpp

示例15: draw_text_window_and_bar

void draw_text_window_and_bar(Bitmap **text_window_ds, bool should_free_ds,
                              int*xins,int*yins,int*xx,int*yy,int*wii,color_t *set_text_color,int ovrheight, int ifnum) {

    draw_text_window(text_window_ds, should_free_ds, xins, yins, xx, yy, wii, set_text_color, ovrheight, ifnum);

    if ((topBar.wantIt) && (text_window_ds && *text_window_ds)) {
        // top bar on the dialog window with character's name
        // create an enlarged window, then free the old one
        Bitmap *ds = *text_window_ds;
        Bitmap *newScreenop = BitmapHelper::CreateBitmap(ds->GetWidth(), ds->GetHeight() + topBar.height, game.GetColorDepth());
        newScreenop->Blit(ds, 0, 0, 0, topBar.height, ds->GetWidth(), ds->GetHeight());
        delete *text_window_ds;
        *text_window_ds = newScreenop;
        ds = *text_window_ds;

        // draw the top bar
        color_t draw_color = ds->GetCompatibleColor(play.top_bar_backcolor);
        ds->FillRect(Rect(0, 0, ds->GetWidth() - 1, topBar.height - 1), draw_color);
        if (play.top_bar_backcolor != play.top_bar_bordercolor) {
            // draw the border
            draw_color = ds->GetCompatibleColor(play.top_bar_bordercolor);
            for (int j = 0; j < play.top_bar_borderwidth; j++)
                ds->DrawRect(Rect(j, j, ds->GetWidth() - (j + 1), topBar.height - (j + 1)), draw_color);
        }

        // draw the text
        int textx = (ds->GetWidth() / 2) - wgettextwidth_compensate(topBar.text, topBar.font) / 2;
        color_t text_color = ds->GetCompatibleColor(play.top_bar_textcolor);
        wouttext_outline(ds, textx, play.top_bar_borderwidth + 1, topBar.font, text_color, topBar.text);

        // don't draw it next time
        topBar.wantIt = 0;
        // adjust the text Y position
        yins[0] += topBar.height;
    }
    else if (topBar.wantIt)
        topBar.wantIt = 0;
}
开发者ID:adventuregamestudio,项目名称:ags,代码行数:38,代码来源:display.cpp


注:本文中的Bitmap类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。