locked
Problem in Rescaling Image in DirectX C++

    Question

  • Dear All

    I am using DirectX C++ to develop 2d Game

    Here i have to use 2D Sprite Animated Image.

    Microsoft::WRL::ComPtr<ID2D1Bitmap> is used for painting.

    In-need of sprite creation i have to rescale the image before painting.

    Kindly suggest me to solve this problem

    Thanks and Regards

    Mohamed Nazar

    Tuesday, February 26, 2013 10:02 AM

Answers

All replies

  • Hi,

    Would you please explain your question more detail. Maybe you can use image to show the result after rescale.

    Best regards,
    Jesse


    Jesse Jiang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, February 27, 2013 5:42 AM
    Moderator
  • Hi Jesse Jiang

              Thanks for the kind reply

    I am developing 2d Game in DirectX C++

    Here i am using Microsoft::WRL::ComPtr<ID2D1Bitmap> image for painting

    The below syntax is used for painting

    m_d2dContext->DrawBitmap(playButton.Get(), D2D1::RectF(playBtnX, playBtnY, playBtnW, playBtnH));

    This is happening while rendering then only resize also happens

    Now I have to rescale the image before rendering

    In QT there is an abstract method scale(image,width,height)

    In DirectX C++ there is any method such as Qt?

    Kindly suggest me a solution for this problem.

    Thanks and Regards

    Mohamed Nazar A

    Wednesday, February 27, 2013 7:34 AM
  • Hi,

    Yes, you can try CLSID_D2D1Scale to add a effect on a bitmap object.
    http://msdn.microsoft.com/en-US/library/windows/apps/hh706339

    Here is the sample codes
    http://code.msdn.microsoft.com/windowsapps/Direct2D-Image-Effects-2979be08

    Best regards,
    Jesse


    Jesse Jiang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, February 27, 2013 7:42 AM
    Moderator
  • Hi Jesse Jiang

              Thanks for the kind reply

    As per your link I have used the below code to rescale the image

        ComPtr<ID2D1Effect> scaleEffect;
        m_d2dContext->CreateEffect(CLSID_D2D1Scale, &scaleEffect);

        scaleEffect->SetInput(0, spriteImage.Get());

        scaleEffect->SetValue(D2D1_SCALE_PROP_CENTER_POINT, D2D1::Vector2F(256.0f, 192.0f));
        scaleEffect->SetValue(D2D1_SCALE_PROP_SCALE, D2D1::Vector2F(2.0f, 2.0f));

        m_d2dContext->BeginDraw();
        m_d2dContext->DrawImage(scaleEffect.Get());
        m_d2dContext->EndDraw();

    This code crops the image But i need to resize the Image without cliping

    Kindly  can you help me to solve this error.

    Thanks and Regards

    Mohamed Nazar A


    Tuesday, March 5, 2013 6:08 AM
  • Hi,

    Did you include these library into your project?
    d2d1.lib
    d3d11.lib
    dxgi.lib
    dxguid.lib

    You can add them in these steps
    Right Click your project->Properties->Configuration properties->Linker->Input->Additional Dependencies

    Best regards,
    Jesse


    Jesse Jiang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, March 5, 2013 7:07 AM
    Moderator
  • Hi

    Already these library are included


    My problem is i need to create a 2dSprite Image this sprite should support all screen size

    For this i have to resize the image and after that only i have to crop it.

    The above code given by you is just it crops without resizeing.

    If is use the below code

    m_d2dContext->DrawBitmap(spriteImage.Get(),D2D1::RectF(spriteX,spriteY,spriteX+spriteW,spriteY+spriteH), 1.0f, D2D1_BITMAP_INTERPOLATION_MODE_LINEAR, D2D1::RectF(currentFrame*spriteW, 0, spriteW, spriteH));

    It crop the image without resizeing

    Now what i need is the image should be resized before painting.

    Kindly Provide me best suggestion for this problem

    Thanks & Regards

    Mohamed Nazar

    Wednesday, March 6, 2013 9:01 AM
  • Hi,

    How about SetTransform()?

    Monday, October 21, 2013 3:13 AM