图片按比例显示:

核心代码:

获取缩放比例

private float getScaleRate(){
        float imgScale = (float)imgWidth/(float)imgHeight;
        float vpScale = (float)vpWidth/(float)vpHeight;
        float scale;
        if(imgScale > vpScale){
            scale = (float)imgWidth/(float)vpWidth;
        }else{
            scale = (float)imgHeight/(float)vpHeight;
        }
        return scale;
    }

此处 imgWidth/imgHeight为原图的宽高,vpWidth/vpHeight为屏幕(或父容器)的宽高

根据缩放比例获取图片显示的宽高

int imgDisplayWidth = (int)(imgWidth/scaleRate);
int imgDisplayHeight = (int)(imgHeight/scaleRate);

视频原理一样。

      最后推荐给一些想进大厂或者还没有拿到心仪offer的攻城狮们一本书,由大厂java面试官胡书敏编写,满满的干货,助你进到想去的公司。

 

博主上传资源下载链接:

自制免费无广告小说阅读APP下载:

https://download.csdn.net/download/yonghuming_jesse/10390364

全屏播放视频不拉伸源码:

https://download.csdn.net/download/yonghuming_jesse/10646274

科大讯飞语音评测服务接入源码:

https://download.csdn.net/download/yonghuming_jesse/10616924

android饺子播放器使用源码:

https://download.csdn.net/download/yonghuming_jesse/10619119

视频播放前显示视频第一帧源码:

https://download.csdn.net/download/yonghuming_jesse/10646332

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐