0
A
回答
0
使用该功能参数为屏幕宽度和screenHeight
public Bitmap scaleCenterCrop(Bitmap source, int newHeight, int newWidth) {
int sourceWidth = source.getWidth();
int sourceHeight = source.getHeight();
// Compute the scaling factors to fit the new height and width, respectively.
// To cover the final image, the final scaling will be the bigger
// of these two.
float xScale = (float) newWidth/sourceWidth;
float yScale = (float) newHeight/sourceHeight;
float scale = Math.max(xScale, yScale);
// Now get the size of the source bitmap when scaled
float scaledWidth = scale * sourceWidth;
float scaledHeight = scale * sourceHeight;
// Let's find out the upper left coordinates if the scaled bitmap
// should be centered in the new size give by the parameters
float left = (newWidth - scaledWidth)/2;
float top = (newHeight - scaledHeight)/2;
// The target rectangle for the new, scaled version of the source bitmap will now
// be
RectF targetRect = new RectF(left, top, left + scaledWidth, top + scaledHeight);
// Finally, we create a new bitmap of the specified size and draw our new,
// scaled bitmap onto it.
Bitmap dest = Bitmap.createBitmap(newWidth, newHeight, source.getConfig());
Canvas canvas = new Canvas(dest);
canvas.drawBitmap(source, null, targetRect, null);
return dest;
}
如何让屏幕宽度和高度看this
+0
如何获得屏幕宽度和屏幕高度? – user1730789
+0
看到编辑答案 –
0
获取屏幕尺寸和那些参数传递到以下功能:
Bitmap.createScaledBitmap(originalimage, width, height, true);
相关问题
- 1. 图像自动高度缩放宽度
- 2. CGAffineTransform仅缩放宽度和高度
- 3. 将div的背景图像缩放到固定宽度;自动缩放高度
- 4. android在矩阵缩放后得到位图的宽度和高度
- 5. 用css将图像缩放为宽度和高度均可缩放
- 6. 如何仅通过高度或宽度缩放位图
- 7. 位图不能缩放到高度Android
- 8. SWF缩放和定位,宽度100%,高度自动调整
- 9. 在android中获取缩放图像的位图高度和宽度
- 10. 100%的高度和宽度导致我的图像“缩放”
- 11. 使用SVG时高度和宽度不缩放使用SVG时高度和宽度不缩放
- 12. imageView中的位图高度和宽度
- 13. 确定位图的宽度和高度
- 14. 在cocos2d中查找缩放图像的宽度和高度
- 15. pygtk缩放图像的宽度和高度
- 16. 将网站缩放到可见区域的100%宽度/高度
- 17. 根据Imageviews的高度和宽度在onCreate()中创建缩放的位图
- 18. 将div宽度缩放到图像宽度
- 19. 元素高度/宽度缩放问题
- 20. 如何将Silverlight应用程序缩放到50%宽度/高度?
- 21. Android:尝试缩放ImageView,因此图像填充宽度并缩放到高度
- 22. 如何根据宽度和高度像素在Android中缩放位图?
- 23. 使页面宽度和高度达到100%,文本缩放以匹配高度?
- 24. 无收缩的宽度和高度
- 25. 将ImageView缩放到父母高度,同时保持宽高比
- 26. 当原始图像的高度和宽度较小时,图像缩放不起作用缩放高度和宽度
- 27. 试图缩放OpenGL程序的宽度(但不是高度)?
- 28. jssor更改缩略图宽度高度
- 29. 旋转位图android时获取位图的宽度和高度?
- 30. 简单的宽度/高度和左/顶位置的变换(缩放)
你是否试过秤类型:fitxy? property – KOTIOS
不,我想按比例缩放它 – user1730789
是可以编程appyied也 – KOTIOS