矩形操作工具箱
2015-10-13 10:21
267 查看
/* * Copyright (C) 2013 Peng fei Pan <sky@xiaopan.me> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package me.xiaopan.android.graphics; import android.graphics.Point; import android.graphics.Rect; /** * 矩形操作工具箱 */ public class RectUtils { /** * 缩放Rect * @param rect * @param scaleX * @param scaleY * @return rect */ public static Rect zoom(Rect rect, float scaleX, float scaleY){ rect.left *= scaleX; rect.top *= scaleY; rect.right *= scaleX; rect.bottom *= scaleY; return rect; } /** * 缩放Rect * @param rect * @param scale * @return rect */ public static Rect zoom(Rect rect, float scale){ rect.left *= scale; rect.top *= scale; rect.right *= scale; rect.bottom *= scale; return rect; } /** * 映射矩形,将源尺寸中的一个矩形映射到目标尺寸中 * @param rectIntSourceSize 源尺寸中的一个矩形 * @param sourceSize 源尺寸 * @param targetSize 目标尺寸 * @return 源尺寸中的矩形映射到目标尺寸中后的矩形 */ public static Rect mapping(Rect rectIntSourceSize, Point sourceSize, Point targetSize){ Rect rect = new Rect(rectIntSourceSize); float scaleX = (float) targetSize.x / sourceSize.x; float scaleY = (float) targetSize.y / sourceSize.y; rect.left *= scaleX; rect.top *= scaleY; rect.right *= scaleX; rect.bottom *= scaleY; return rect; } /** * 映射矩形,将源尺寸中的一个矩形映射到目标尺寸中 * @param rectIntSourceSize 源尺寸中的一个矩形 * @param sourceSize 源尺寸 * @param targetSize 目标尺寸 * @param isTargetSizeInterchange 是否将targetSize的宽高互换 * @return 源尺寸中的矩形映射到目标尺寸中后的矩形 */ public static Rect mapping(Rect rectIntSourceSize, Point sourceSize, Point targetSize, boolean isTargetSizeInterchange){ if(isTargetSizeInterchange){ targetSize.x = targetSize.x + targetSize.y; targetSize.y = targetSize.x - targetSize.y; targetSize.x = targetSize.x - targetSize.y; } Rect rect = new Rect(rectIntSourceSize); float scaleX = (float) targetSize.x / sourceSize.x; float scaleY = (float) targetSize.y / sourceSize.y; rect.left *= scaleX; rect.top *= scaleY; rect.right *= scaleX; rect.bottom *= scaleY; return rect; } }
相关文章推荐
- arcgis10.3下载,arcgis pro的下载地址
- 项目的创建流程
- Imputing missing data with R; MICE package
- 神经网络入门2
- OWIN是什么?OWIN的英文全称是Open Web Interface for .NET。
- Leetcode 4 Median of Two Sorted Arrays
- 获取一张文字位图
- STL - 容器 - vector简单应用
- TSql stuff 函数用法
- Add and Search Word - Data structure design 解答
- 性能测试之Nginx性能调优课程
- 神经网络入门1
- 获取文本宽度和高度
- 服务协议
- 查看 MySQL 数据库中每个表占用的空间大小
- 放松时刻——C#分割字符串
- 复制 实现两台服务器的数据同步
- Android 屏幕适配
- C++中引用传递与指针传递区别
- How to Build ffmpeg with NDK r9