ShowBitMap

static FormWindowControl showBitmap(FormWindowControl _control, Bitmap _bitmap,
                                   int _width=0, int _height=0)
{
    real    ratio;
    Image   _image;
    ;
    if (_bitmap != connull())
        {
        _image = new Image();
        _image.setData(_bitmap);

        if (_width == 0 && _height == 0) // use default image hxw if no width or height pass in
            {
            _width = _image.width();
            _height = _image.height();
            }
        else // max width or height in not 0 is passed in
            {
            ratio = _image.width() > _image.height() ? _image.width() / _width : _image.height() / _height;

            _width = real2int(_image.width()/ratio);
            _height = real2int(_image.height()/ratio);

            _image.resize(_width, _height, InterpolationMode::InterpolationModeHighQuality);
            }

        _control.width(_width);
        _control.height(_height);
        _control.imagemode(0);
        _control.image(_image);
        }
    else
        {
        _control.imageResource(0);
        }

    return _control;
}

posted @ 2012-03-01 11:58  perock  阅读(289)  评论(0编辑  收藏  举报