Exemplo n.º 1
0
/// <summary>
/// Draws a 32 bits per pixel image of previously specified width, height and stride, to the associated hwnd
/// </summary>
/// <param name="pImage">The pointer to image buffer</param>
/// <param name="size">The image size</param>
/// <param name="rect">The rectangle in the window to render the image</param>
void ImageRenderer::DrawImage(const BYTE* pImage, const D2D1_SIZE_U& size, const D2D1_RECT_F& rect)
{
    // Check image buffer pointer
    if (!pImage)
    {
        return;
    }

    // Validate image size
    if (0 == size.width || 0 == size.height)
    {
        return;
    }

    // Ensure bitmap is created.
    HRESULT hr = EnsureBitmap(size);

    if (SUCCEEDED(hr))
    {
        // Copy the image from image buffer to D2D1 bit map
        hr = m_pBitmap->CopyFromMemory(NULL, pImage, size.width * sizeof(UINT));
        if (SUCCEEDED(hr))
        {
            // Draw the bitmap stretched to the size of the window
            m_pRenderTarget->DrawBitmap(m_pBitmap, rect);
        }
    }
}
Exemplo n.º 2
0
bool MCGImageImageRep::LockBitmap(uindex_t p_index, MCGFloat p_density, MCImageBitmap *&r_bitmap)
{
	if (p_index > 0)
		return false;
	
	if (!EnsureBitmap())
		return false;

	Retain();
	
	r_bitmap = m_bitmap;
	
	return true;
}