当前位置:  编程技术>移动开发
本页文章导读:
    ▪jni课程网站        jni教程网站 http://www.eoeandroid.com/forum.php?mod=viewthread&tid=170988http://hi.baidu.com/it_freeman/item/a40df8246b14892c76272c98ajni内存泄漏问题:http://www.ibm.com/developerworks/cn/java/j-lo-jnileak/index.html?ca=drs- ......
    ▪ 橡皮擦成效的实现        橡皮擦效果的实现 废话少说,直接贴代码,希望对大家有帮助。 public class DrawView extends View{ private Canvas pcanvas; private Paint paint; private Path path; private Bitmap originBitmap; private Bitmap pureBitmp.........
    ▪ 舆图描线的简单示例       地图描线的简单示例 首先,需要将CoreLocation.framework和MapKit.framework加入到项目中。     mapLinesViewController.h   #import <UIKit/UIKit.h> #import <MapKit/MapKit.h> #import "MapRouteLayerView.h" @interface .........

[1]jni课程网站
    来源: 互联网  发布时间: 2014-02-18
jni教程网站


http://www.eoeandroid.com/forum.php?mod=viewthread&tid=170988





http://hi.baidu.com/it_freeman/item/a40df8246b14892c76272c98a


jni内存泄漏问题:

http://www.ibm.com/developerworks/cn/java/j-lo-jnileak/index.html?ca=drs-

    
[2] 橡皮擦成效的实现
    来源: 互联网  发布时间: 2014-02-18
橡皮擦效果的实现
废话少说,直接贴代码,希望对大家有帮助。

public class DrawView extends View{
	private Canvas pcanvas;
	private Paint paint;
	private Path path;
	
	private Bitmap originBitmap;
	private Bitmap pureBitmp;
	private Bitmap bitmapBuff;
	private float scaleWidth;
	private float scaleHeight;
	private float downx = 0,downy = 0;
	
	public DrawView(Context context) {
		super(context);

        setBackgroundResource(R.drawable.pic);
        path = new Path();
        paint = new Paint();
        paint.setAlpha(0);
        paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
        paint.setAntiAlias(true);
        
        paint.setDither(true);
        paint.setStyle(Paint.Style.STROKE);  
        paint.setStrokeJoin(Paint.Join.ROUND);  
        paint.setStrokeCap(Paint.Cap.ROUND);  
        paint.setStrokeWidth(15.6f); 
        
        initLayer(context);
	}
	
	@Override
	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);
		canvas.drawPath(path, paint);
		canvas.drawBitmap(bitmapBuff, 0, 0, null);
	}

    private void initLayer(Context context){
    	InputStream stream = context.getResources().openRawResource(R.drawable.layer);
        originBitmap = BitmapFactory.decodeStream(stream);
        int width = originBitmap.getWidth();
        int height = originBitmap.getHeight();
        
        Display currentDisplay = ((Activity)context).getWindowManager().getDefaultDisplay();
        float newWidth = currentDisplay.getWidth();
        float newHeight = currentDisplay.getHeight();
        
        scaleWidth = ((float) newWidth / width);
        scaleHeight = ((float) newHeight / height);

        Matrix matrix = new Matrix();
        matrix.postScale(scaleWidth, scaleHeight);

        pureBitmp = Bitmap.createBitmap(originBitmap, 0, 0, width, height,matrix, true);
        bitmapBuff = Bitmap.createBitmap(pureBitmp.getWidth(),pureBitmp.getHeight(), Bitmap.Config.ARGB_8888);
        
        pcanvas = new Canvas(bitmapBuff);
        pcanvas.drawBitmap(pureBitmp, 0, 0, null);
    }
    
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		int action = event.getAction();
	    switch (action) {
	    case MotionEvent.ACTION_DOWN:
	      downx = event.getX();
	      downy = event.getY();
	      path.reset();
	      path.moveTo(downx, downy);
	      break;
	    case MotionEvent.ACTION_MOVE:
	      float upx = event.getX();
	      float upy = event.getY();
	      touchMove(upx, upy);
	      invalidate();
	      break;
	    case MotionEvent.ACTION_UP:
	      pcanvas.drawPath(path, paint);
	      path.reset();
	      invalidate();
	      break;
	    case MotionEvent.ACTION_CANCEL:
	      break;
	    default:
	      break;
	    }
		return true;
	}
	
	private void touchMove(float upx, float upy){
		float dx = Math.abs(downx-upx);
	      float dy = Math.abs(downy-upy);
	      if (dx >= 4 || dy >= 4) {
	        path.quadTo(downx, downy, (downx + upx)/2, (downy + upy)/2);
	        downx = upx;
		    downy = upy;
	      }
	}
}

    
[3] 舆图描线的简单示例
    来源: 互联网  发布时间: 2014-02-18
地图描线的简单示例

首先,需要将CoreLocation.framework和MapKit.framework加入到项目中。

 

 

mapLinesViewController.h

 

#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import "MapRouteLayerView.h"

@interface mapLinesViewController : UIViewController {
	MKMapView *mapView;
	MapRouteLayerView *routeView;
}

@property(nonatomic, retain) MKMapView *mapView;
@property(nonatomic, retain) MapRouteLayerView *routeView;

@end

 

mapLinesViewController.m

 

#import "mapLinesViewController.h"
#import <CoreLocation/CoreLocation.h>
#import "MapRouteLayerView.h"

@implementation mapLinesViewController

@synthesize routeView;
@synthesize mapView;

- (void)viewDidLoad {
    [super viewDidLoad];
	NSString *filePath = [[NSBundle mainBundle] pathForResource:@"route" ofType:@"csv"];
	NSString *fileContents = [NSString stringWithContentsOfFile:filePath];
	NSArray *pointStrings = [fileContents componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];	
	NSMutableArray *points = [[NSMutableArray alloc] initWithCapacity:pointStrings.count];	
	for(int idx = 0; idx < pointStrings.count; idx++) {
		NSString *currentPointString = [pointStrings objectAtIndex:idx];
		NSArray *latLonArr = [currentPointString componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@","]];		
		CLLocationDegrees latitude = [[latLonArr objectAtIndex:0] doubleValue];
		CLLocationDegrees longitude = [[latLonArr objectAtIndex:1] doubleValue];		
		CLLocation *currentLocation = [[[CLLocation alloc] initWithLatitude:latitude longitude:longitude] autorelease];
		[points addObject:currentLocation];
	}
	mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
	[self.view addSubview:mapView];
	routeView = [[MapRouteLayerView alloc] initWithRoute:points mapView:mapView];	
	[points release];
}

- (void)viewDidUnload {
	self.mapView = nil;
	self.routeView = nil;
}

- (void)dealloc {	
	[mapView release];
	[routeView release];
    [super dealloc];
}

@end

 

MapRouteLayerView.h

 

#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>

@interface MapRouteLayerView : UIView <MKMapViewDelegate> {
	MKMapView *mapView;
	NSArray *points;
	UIColor *lineColor;
}

@property(nonatomic, retain) NSArray *points;
@property(nonatomic, retain) MKMapView *mapView;
@property(nonatomic, retain) UIColor *lineColor; 

- (id)initWithRoute:(NSArray *)routePoints mapView:(MKMapView *)mapView;

@end

 

MapRouteLayerView.m

 

#import "MapRouteLayerView.h"

@implementation MapRouteLayerView

@synthesize mapView;
@synthesize points;
@synthesize lineColor; 

- (id)initWithRoute:(NSArray *)routePoints mapView:(MKMapView *)mapView {
	self = [super initWithFrame:CGRectMake(0, 0, mapView.frame.size.width, mapView.frame.size.height)];
	[self setBackgroundColor:[UIColor clearColor]];	
	[self setMapView:mapView];
	[self setPoints:routePoints];
	
	CLLocationDegrees maxLat = -90;
	CLLocationDegrees maxLon = -180;
	CLLocationDegrees minLat = 90;
	CLLocationDegrees minLon = 180;
	
	for(int idx = 0; idx < self.points.count; idx++) {
		CLLocation *currentLocation = [self.points objectAtIndex:idx];
		if(currentLocation.coordinate.latitude > maxLat)
			maxLat = currentLocation.coordinate.latitude;
		if(currentLocation.coordinate.latitude < minLat)
			minLat = currentLocation.coordinate.latitude;
		if(currentLocation.coordinate.longitude > maxLon)
			maxLon = currentLocation.coordinate.longitude;
		if(currentLocation.coordinate.longitude < minLon)
			minLon = currentLocation.coordinate.longitude;
	}
	
	MKCoordinateRegion region;
	region.center.latitude = (maxLat + minLat) / 2;
	region.center.longitude = (maxLon + minLon) / 2;
	region.span.latitudeDelta = maxLat - minLat;
	region.span.longitudeDelta = maxLon - minLon;
	
	[self.mapView setRegion:region];
	[self.mapView setDelegate:self];
	[self.mapView addSubview:self];
	
	return self;
}

- (void)drawRect:(CGRect)rect {
	if(!self.hidden && nil != self.points && self.points.count > 0) {
		CGContextRef context = UIGraphicsGetCurrentContext(); 		
		if(nil == self.lineColor)
			self.lineColor = [UIColor blueColor];		
		CGContextSetStrokeColorWithColor(context, self.lineColor.CGColor);
		CGContextSetRGBFillColor(context, 0.0, 0.0, 1.0, 1.0);
		CGContextSetLineWidth(context, 2.0);		
		for(int idx = 0; idx < self.points.count; idx++) {
			CLLocation *location = [self.points objectAtIndex:idx];
			CGPoint point = [mapView convertCoordinate:location.coordinate toPointToView:self];			
			if(idx == 0) {
				CGContextMoveToPoint(context, point.x, point.y);
			} else {
				CGContextAddLineToPoint(context, point.x, point.y);
			}
		}		
		CGContextStrokePath(context);
	}
}

#pragma mark mapView delegate functions
- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated {
	self.hidden = YES;
}

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
	self.hidden = NO;
	[self setNeedsDisplay];
}

- (void) dealloc {
	[points release];
	[mapView release];
	[lineColor release];
	[super dealloc];
}

@end

 

示例图:



    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android实现Back功能代码片段总结 iis7站长之家
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3