【问题标题】:SDL Image scaleSDL 图像比例
【发布时间】:2011-12-29 08:04:23
【问题描述】:

我正在使用 sdl 库,但它不支持缩放/调整表面大小,所以我下载了

SDL_image 1.2 和 SDL_gfx 库。我的功能/代码有效,但图像显示不良/低

质量。

假设我得到一个 100X100 的图像,如果我缩小到 95X95 或放大到 110X110

质量看起来非常低,但如果我将其保留为 100X100,它与它在

中出现的尺寸相同

质量好。如果按比例缩小图像,大多数图像质量都很好,但是……它没有

我的代码是:

int drawImage(SDL_Surface* display, const char * filename, int x, int y, int xx, int yy , const double newwidth, const double newheight, int transparent = NULL)
{



    SDL_Surface *image;
    SDL_Surface *temp;
    temp = IMG_Load(filename); if (temp == NULL) { printf("Unable to load image: %s\n", SDL_GetError()); return 1; }
    image = SDL_DisplayFormat(temp); SDL_FreeSurface(temp);

        // Zoom function uses doubles for rates of scaling, rather than
    // exact size values. This is how we get around that:
    double zoomx = newwidth  / (float)image->w;
    double zoomy = newheight / (float)image->h;

    // This function assumes no smoothing, so that any colorkeys wont bleed.
    SDL_Surface* sized = zoomSurface( image, zoomx, zoomy, SMOOTHING_OFF );



    // If the original had an alpha color key, give it to the new one.
    if( image->flags & SDL_SRCCOLORKEY )
    {
        // Acquire the original Key
        Uint32 colorkey = image->format->colorkey;

        // Set to the new image
        SDL_SetColorKey( sized, SDL_SRCCOLORKEY, colorkey );
    }



    // The original picture is no longer needed.
    SDL_FreeSurface( image );

    // Set it instead to the new image.
    image =  sized;



    SDL_Rect src, dest;
    src.x = xx; src.y = yy; src.w = image->w; src.h = image->h; // size 
    dest.x =  x; dest.y = y; dest.w = image->w; dest.h = image->h;

    if(transparent == true )
     {

         //Set the color as transparent
         SDL_SetColorKey(image,SDL_SRCCOLORKEY|SDL_RLEACCEL,SDL_MapRGB(image->format,0x0,0x0,0x0)); 

     }

    else {

    }


    SDL_BlitSurface(image, &src, display, &dest);

    return true;
}

drawImage(display, "Image.png", 50, 100, NULL, NULL, 100, 100,true);

【问题讨论】:

    标签: c++ c sdl


    【解决方案1】:

    在未经平滑处理的情况下缩放的图像会出现伪影。如果您从 SVG 开始并以您想要的比例渲染它,您可能会有更好的运气。 Here's an SVG -> SDL surface图书馆。

    【讨论】:

    • 你能举例说明如何使用它吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-11
    • 1970-01-01
    • 2015-11-24
    • 1970-01-01
    • 2012-10-31
    • 2017-11-14
    • 1970-01-01
    相关资源
    最近更新 更多