当前位置: 编程技术>移动开发
本页文章导读:
▪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-
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
示例图:
最新技术文章: