如何获得bitmap的坐标点?

wsxeragon 2016-04-04 10:54:25

图片太大了,只能吧ImageView定死了,红色是ImageView的范围,如何才能获得bitmap图片的左上角和右下角的坐标?
...全文
467 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
wei220000 2016-04-05
  • 打赏
  • 举报
回复
获取ImageView的matrix,根据matrix的getValues获得3x3矩阵。 Matrix matrix = imageView.getImageMatrix(); Rect rect = imageView.getDrawable().getBounds(); float[] values = new float[9]; matrix.getValues(values); ImageState mapState = new ImageState(); mapState.setLeft(values[2]); mapState.setTop(values[5]); mapState.setRight(mapState.getLeft() + rect.width() * values[0]); mapState.setBottom(mapState.getTop() + rect.height() * values[0]); public class ImageState { private float left; private float top; private float right; private float bottom;}
peter_nj_RD 2016-04-05
  • 打赏
  • 举报
回复
引用 1 楼 a511341250 的回复:
imageView.setScaleType(ScaleType.CENTER_CROP); 我感觉你需要的是这个
+1 bitmap图片的左上角和右下角的坐标 View.getLetf() View.getRight() View.getTop() View.getBottom() View边框的四个点
ESC尛蜜蜂 2016-04-05
  • 打赏
  • 举报
回复
imageView.setScaleType(ScaleType.CENTER_CROP); 我感觉你需要的是这个
class CSBitmap //Bitmap类,特紧约型数据结构,GetPixel效率高,放弃调色板,自动支持4种色深,特有的12位颜色更接近人眼可识别颜色数目;有多种缩放,色深转换,拷贝,剪切,和hBitmap转换,显示等功能;支持串行化。支持1,12,24,32位位图,对应适用于所有函数,相比于HBitmap和CSBitmap对象要简单,可直接操作数据区;同时可用于1,4,8,12,16,24,32位二维数列的储存,部分基本函数(GetPixel,SetPixel)支持; { public: CSBitmap(void); ~CSBitmap(void); unsigned int Width; //Bitmap的宽 unsigned int Height; //Bitmap的高 DWORD BitSize; //Bitmap的数据区大小(字节) BYTE* pBitData; //Bitmap的数据区指针 unsigned int BitCount; //Bitmap的色深 bool SetAttribute(unsigned int mWidth=NULL, unsigned int mHeight=NULL, unsigned int mBitCount=NULL); //设置Bitmap的属性,Bitmap会被清除 mWidth Bitmap的宽度,为NULL则不改变 mHeight Bitmap的高度,为NULL则不改变 mBitCount Bitmap的色深,为NULL则不改变 bool ImportBits(BYTE* lpBits, int mBitSize=NULL); //拷贝Bits数据进对象数据区 lpBits 拷贝数据的指针 mBitSize 拷贝数据的字节数 COLORREF GetPixel(unsigned int x, unsigned int y); //获得的原始数值,当为12,24,32位数时,则为RGB值 X,y 需要获取坐标 bool SetPixel(unsigned int x, unsigned int y, COLORREF clr); //获得的原始数值,当为12,24,32位数时,则为RGB值 X,y 需要设置坐标 bool StretchDIB(CSBitmap* DestBmp, unsigned int mWidth, unsigned int mHeight, unsigned int mFlag=0); //缩放 DestBmp用于获取缩放后图片的指针 mWidth, mHeight缩放后大小 mFlag缩放算法 取值 算法 缩小 放大 0 逆向寻算法 效率高,质量一般 效率高,质量中 1 双线性补 效率低,质量一般 效率低,质量高 2 平均值算法 效率低,质量好 效率高,质量差 static BYTE GetRValue12(COLORREF Clr12Bit); static BYTE GetGValue12(COLORREF Clr12Bit); static BYTE GetBValue12(COLORREF Clr12Bit); //用于12位图的获取RGB分量,24位图,32位图的COLOR分离请用GDI的GetPixel() Clr12Bit 对12位图GetPixel获得的原始值 static COLORREF RGB12(BYTE R, BYTE G, BYTE B); //用于12位图的RGB合成,24位图,32位图的COLOR合成请用GDI的RGB() static COLORREF Color24To1(COLORREF Color24); //24位色深COLORREF转1位色深(黑白)值 static COLORREF Color24To12(COLORREF Color24); //24位色深COLORREF转12位色深值 static COLORREF Color1To24(COLORREF Color2); //1位色深COLORREF转24位,32位色深(黑白)值 static COLORREF Color12To24(COLORREF Color12); //12位色深COLORREF转24位,32位色深(黑白)值 bool ConvertTo1Bit(CSBitmap* DestBmp); //12,24,36位图片转换成1位色深图 DestBmp用于接收数据的DestBmp指针,转换过程中包括自动参数重置 bool ConvertTo12Bit(CSBitmap* DestBmp); //1,24,36位图片转换成12位色深图 DestBmp用于接收数据的DestBmp指针,转换过程中包括自动参数重置 bool ConvertTo24Bit(CSBitmap* DestBmp); //1,12,36位图片转换成24位色深图 DestBmp用于接收数据的DestBmp指针,转换过程中包括自动参数重置 bool FromHandle(HBITMAP hBitmap); //从HBITMAP获得CSBitmap对象 bool CopyPaste(CSBitmap* DestBmp, unsigned int x, unsigned int y); //复制本CSBitmap至另一DestBmp的指定位置 DestBmp 目标,对象 X,y复制后图片左上角位置 bool PaintDIB(CDC* dcDest, int x,int y,unsigned int mWidth, unsigned int mHeight); //把本图片显示至CDC对象上,支持1,12,24,26位图 dcDest 目标dc(兼容DC) x,y 拷贝到dc上的位置 mWidth,mHeight拷贝后的大小 const CSBitmap& operator=(const CSBitmap &SBmp); }; //重载了 = 赋值操作符

80,472

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧