See the question and my original answer on StackOverflow

Here is how you can use mag's bitmap with Direct2D. You don't need BITMAPINFOHEADER since mag format is the same as DXGI_FORMAT_B8G8R8A8_UNORM:

BOOL MagImageScaling(HWND hwnd, void* srcdata, MAGIMAGEHEADER srcheader, void* destdata, MAGIMAGEHEADER destheader, RECT unclipped, RECT clipped, HRGN dirty)
    // note: all this (dc, surface, targte) can be created only once as long as the D3D device isn't reset
    ComPtr<ID2D1DeviceContext> dc;
    HR(d2Device->CreateDeviceContext(D2D1_DEVICE_CONTEXT_OPTIONS_NONE, dc.GetAddressOf()));

    ComPtr<IDXGISurface2> surface;
    HR(swapChain->GetBuffer(0, IID_PPV_ARGS(&surface)));

    ComPtr<ID2D1Bitmap1> target;
    HR(dc->CreateBitmapFromDxgiSurface(surface.Get(), NULL, target.GetAddressOf()));

    D2D1_BITMAP_PROPERTIES properties = {};
    properties.pixelFormat.alphaMode = D2D1_ALPHA_MODE_PREMULTIPLIED;

    // note: this is ok as srcheader.format (GUID_WICPixelFormat32bppRGBA) is compatible
    properties.pixelFormat.format = DXGI_FORMAT_B8G8R8A8_UNORM; 

    D2D1_SIZE_U size = {};
    size.width = srcheader.width;
    size.height = srcheader.height;

    ComPtr<ID2D1Bitmap> bitmap;
    HR(dc->CreateBitmap(size, properties, bitmap.GetAddressOf()));
    HR(bitmap->CopyFromMemory(NULL, srcdata, srcheader.stride));


    // note: we don't call this because we draw on the whole render target


    HR(swapChain->Present(1, 0));
    return TRUE;