Bitmap and DrawPoint
Android UI 中有时需要画Bitmap,那么如何画Bitmap?
public void fillPointArrays(int color,Drawable drawable) {
Bitmap bitmap = Bitmap.createBitmap(pointSize, pointSize, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, pointSize, pointSize);
drawable.draw(canvas);
pointArray[color] = bitmap;
}
Resources r = this.getContext().getResources();
fillPointArrays(GREEN,r.getDrawable(R.drawable.green_point));
@Override
public boolean onTouchEvent(MotionEvent event) {
//获得触摸点的坐标
point = newPoint(event.getX(), event.getY());
refressCanvas();
return true;
}
onTouchEvent(MotionEvent event) 重载了View()的函数,用来监听屏幕的触摸,从event事件中可以获得触摸点的坐标。
//画点
private void drawPoint(Canvas canvas){
canvas.drawBitmap(pointArray[0],point.x*pointSize+xOffset,point.y*pointSize+yOffset,paint);
}
//根据触摸点坐标找到对应点
private Point newPoint(Float x, Float y){
Point p = new Point(0, 0);
for (int i = 0; i < maxX; i++) {
if ((i * pointSize + xOffset) <= x
&& x < ((i + 1) * pointSize + xOffset)) {
p.setX(i);
}
}
for (int i = 0; i < maxY; i++) {
if ((i * pointSize + yOffset) <= y
&& y < ((i + 1) * pointSize + yOffset)) {
p.setY(i);
}
}
return p;
}
分享到:
相关推荐
软件开发网在此之前给大家介绍过图片加载框架Glide的基本用法介绍,大家可以先参考一下,本篇内容更加深入的分析了Glide获取图片Path、Bitmap用法,以及实现的代码分析。 1. 获取Bitmap: 1)在图片下载缓存好之后...
处理bitmap内存溢出问题
赠送jar包:RoaringBitmap-0.7.45.jar; 赠送原API文档:RoaringBitmap-0.7.45-javadoc.jar; 赠送源代码:RoaringBitmap-0.7.45-sources.jar; 赠送Maven依赖信息文件:RoaringBitmap-0.7.45.pom; 包含翻译后的API...
机器视觉技术必备,从位图到halcon图像,bitmap图像转为halcon图像,bitmap to Hobject
android bitmap outofMemory 用来解决android中常见的bitmap outOfMemory
改用原始图像数据流回调函数RegisterImageStreamCallback进行抓图 但回调函数帧为YUV420格式 需要转成Bitmap才用用于显示及本地查看 在网上找了好多都是基于R Y+1 4075 V 128 G Y 0 3455 U 128 – 0 7169 V 128 B Y+...
C#语言下,官方好像没有提供直接的方式把Bitmap转为Mat,但是可以使用我的这个方式转变格式
Halcon_Bitmap转换方法 写的文档 开发笔记
赠送jar包:RoaringBitmap-0.7.45.jar; 赠送原API文档:RoaringBitmap-0.7.45-javadoc.jar; 赠送源代码:RoaringBitmap-0.7.45-sources.jar; 赠送Maven依赖信息文件:RoaringBitmap-0.7.45.pom; 包含翻译后的API...
一个在VC中将Bitmap转换为Byte[]的小例子。
c#.net Bitmap类的基本使用方法
将图片由bitmap类型转换为stream类型再转换为byte[]类型,然后再还原
赠送jar包:RoaringBitmap-0.5.11.jar; 赠送原API文档:RoaringBitmap-0.5.11-javadoc.jar; 赠送源代码:RoaringBitmap-0.5.11-sources.jar; 赠送Maven依赖信息文件:RoaringBitmap-0.5.11.pom; 包含翻译后的API...
主要介绍了 Android canvas drawBitmap方法详解及实例的相关资料,需要的朋友可以参考下
3个bitmap文件,用于认识bitmap文件格式的本质
海康SDK采图 生成BitMap类型的图片
android中对Bitmap图片设置任意角为圆角
this contains the bitmap file signature, the size of the bitmap and the offset to the array of bits that define the bitmap image. the next section is the bitmapinfoheader. this contains information ...
BMP2H264 Bitmap图像转换为H264