dp转px

public class Dp2pxUtils {
public static int Dp2Px(Context context, float dp) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (dp * scale + 0.5f);
}
/**
* 根据手机的分辨率从 px(像素) 的单位 转成为 dp
*/
public static int px2dip(Context context, float pxValue) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (pxValue / scale + 0.5f);
}
}

获取图片实际尺寸

public class ImgUtils {

    /**
* 用bitmap获取图片的本来宽高
*/
public static int getImgOriginalWidth(String path) {
BitmapFactory.Options options = new BitmapFactory.Options();
//设置为true,表示解析Bitmap对象,该对象不占内存
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(path, options); int bitmapWidth = options.outWidth; return bitmapWidth;
}
/**
* 用bitmap获取图片的本来宽高
*/
public static int getImgOriginalHeight(String path) {
BitmapFactory.Options options = new BitmapFactory.Options();
//设置为true,表示解析Bitmap对象,该对象不占内存
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(path, options); int bitmapHeight = options.outHeight; return bitmapHeight;
}
}
public class ImgUtils {

    /**
* 用bitmap获取图片的本来宽高
*/
public static int getImgOriginalWidth(String path) {
BitmapFactory.Options options = new BitmapFactory.Options();
//设置为true,表示解析Bitmap对象,该对象不占内存
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(path, options); int bitmapWidth = options.outWidth; return bitmapWidth;
}
/**
* 用bitmap获取图片的本来宽高
*/
public static int getImgOriginalHeight(String path) {
BitmapFactory.Options options = new BitmapFactory.Options();
//设置为true,表示解析Bitmap对象,该对象不占内存
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(path, options); int bitmapHeight = options.outHeight; return bitmapHeight;
}
}

获取屏幕尺寸

public class ScreenUtil {

    public static int getScreenHight(Context context) {
DisplayMetrics displaymetrics = new DisplayMetrics();
((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getMetrics(displaymetrics);
return displaymetrics.heightPixels;
} public static int getScreenWidth(Context context) {
DisplayMetrics displaymetrics = new DisplayMetrics();
((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getMetrics(displaymetrics);
return displaymetrics.widthPixels;
}
}

工具类 dp转px 获取图片实际尺寸 获取屏幕尺寸的更多相关文章

  1. Netty源码分析第8章(高性能工具类FastThreadLocal和Recycler)---->第7节: 获取异线程释放的对象

    Netty源码分析第八章: 高性能工具类FastThreadLocal和Recycler 第七节: 获取异线程释放的对象 上一小节分析了异线程回收对象, 原理是通过与stack关联的WeakOrder ...

  2. 解决获取图片实际尺寸(宽高)的bug

    需求:获取图片的宽高其实是为了预先做好排版样式布局做准备. 可以利用图片onload事件监听获取图片的宽高属性值.在IE9以下版本只能使用图片的width与height属性,HTMl5中新加入了nat ...

  3. Android dp和px之间转换 及 获取坐标

    dp.px.sp转换 public class DensityUtil { /** * 将px值转换为dip或dp值,保证尺寸大小不变 * * @param pxValue * @param scal ...

  4. php 获取图片、swf的尺寸大小

    PHP获取图片大小函数.  getimagesize() 能够得到图片及flash(swf)的大小. 语法 1 list($width, $height, $type, $attr) = getima ...

  5. Android -- 加载大图片到内存,从gallery获取图片,获取图片exif信息

    1. 加载大图片到内存,从gallery获取图片 android默认的最大堆栈只有16M, 图片像素太高会导致内存不足的异常, 需要将图片等比例缩小到适合手机屏幕分辨率, 再加载. 从gallery ...

  6. 常用工具类,文件和内存的大小获取,shell脚本的执行

    /* * Copyright (C) 2012 The Android Open Source Project * * Licensed under the Apache License, Versi ...

  7. 工具类CTools实现字符编码转换和获取当前路径

    class CTools { public: CTools(void); public: ~CTools(void); public: static std::string UNICODE_to_UT ...

  8. 工具类BitMap 把网络URL图片转换成BitMap

    代码不复杂,直接把完整代码贴上. 这次是用到很旧的HttpURLConnection,那为什麽会用这个,因为我本来想转回okhttp的,可实在没时间转,项目就已经做下去了,结果转不回来. packag ...

  9. 如何在SpringBoot当中上传多个图片或者上传单个图片 工具类

    如何在SpringBoot当中上传多个图片[上传多个图片 ] 附赠工具类 1.SpringBoot 上传图片工具类 public class SpringUploadUtil { /*** * 上传图 ...

随机推荐

  1. python os用法笔记

    获取文件所在路径 import os os.path.dirname(__file__)  获取当前文件的所在路径 print (os.path.dirname(os.path.dirname(__f ...

  2. Windows平台注册mysql服务

    将mysql 注册为服务: ->mysqld --install 卸载服务: ->mysqld --remove 命令行启动mysql: ->net start mysql 命令行关 ...

  3. 示sudo: cd: command not found

    执行sudo cd 时出现 sudo: cd: command not found 原因shell shell是一个命令解析器 所谓shell是一个交互式的应用程序. shell执行外部命令的 时候, ...

  4. C++Primer 第六章

    //1.我们通过调用运算符来执行函数.调用运算符的形式是一对圆括号,他作用于一个表达式,该表达式是一个函数或者指向函数的指针.圆括号之内是用逗号分隔的实参列表,用于初始化函数形参.调用表达式的类型就是 ...

  5. TImageList 和 TlistView 组件(C++Builder)

    __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { //加载图标到Imagelist Graphics::TBitmap *bm ...

  6. [Linux]可用于管道操作的命令

    管道命令——| command1 | command2 | command3 注:管道命令必须能够接受来自前一个命令的数据成为standard input继续处理. cut 将一段信息的某一段切出来, ...

  7. (转)Aspone.Cells设置Cell数据格式 Setting Display Formats of Numbers and Dates

    Setting Display Formats Using Microsoft Excel: Right-click on any desired cell and select Format Cel ...

  8. 手把手教你用动软.NET代码生成器实例教程

    动软实战攻略 手把手教你用动软 文档编号:20110421 版权所有 © 2004-2011 动软 在线帮助:http://help.maticsoft.com 目录   一.        产品介绍 ...

  9. 夺命雷公狗---Thinkphp----7之栏目配合Model的增删改查

    我们首先来写一个查: public function lists(){ $type = M('Type')->select(); $this -> assign('type',$type) ...

  10. 夺命雷公狗---Thinkphp----1之目录介绍

    ThinkPHP框架 特点: 免费开源 敏捷开发(快速开发) 面向对象 MVC思想 yii,ci之类的框架都有这些特点.是06年到现在的一个老牌框架,现在还是个很不错的框架 可以在thinkphp的官 ...