rexis.cn

一张相片 一段故事

Archive for the ‘program’ Category

在iphone app中添加音量控制条

without comments

1. 添加MediaPlayer.framework
2. #import <MediaPlayer/MPVolumeView.h>
3. 代码

	MPVolumeView *volumeView = [[[MPVolumeView alloc]  initWithFrame:CGRectMake(18, 380, 284, 23)] autorelease];
	volumeView.center = CGPointMake(160,380);
	[volumeView sizeToFit];
	[self.view addSubview:volumeView];

Written by 北

七月 2nd, 2010 at 12:25 下午

Posted in iphone开发

Tagged with , ,

iphone程序中跳转到appstore评论界面

without comments

在程序中加入appstore的review跳转,实现方法很简单,就是让系统去打开一个review的链接,代码如下:

- (void) gotoWriteReviews {
	NSString* appID = NSLocalizedString(@"itunesconnect_appid", nil);	//这里是itunes connect生成的一串数字id
	NSString *u = [NSString stringWithFormat:@"http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=%@&onlyLatestVersion=true&pageNumber=0&sortOrdering=1&type=Purple+Software",appID];
	[[UIApplication sharedApplication] openURL:[NSURL URLWithString:u]];
}

Written by 北

五月 25th, 2010 at 12:13 下午

Posted in iphone开发

Tagged with , ,

在图片上盖一层mask

without comments

- (UIImage*) createImage:(UIImage*)_image withMask:(UIImage*)_mask {
	CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
	CGContextRef context = CGBitmapContextCreate(NULL,
						 _image.size.width,
						 _image.size.height,
						 8, 0,
						 colorSpace,
						kCGImageAlphaPremultipliedLast);
	CGColorSpaceRelease(colorSpace);
 
	CGRect rect = CGRectMake(0, 0, _image.size.width, _image.size.height);
	UIColor *bColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1];
	CGContextSetFillColorWithColor(context, [bColor CGColor]);                     //黑色是不透明,白色是透明
	CGContextFillRect(context, rect);
	CGContextClipToMask(context, rect, [_mask CGImage]);
	CGContextDrawImage(context, rect, [_image CGImage]);
 
	CGImageRef newImage = CGBitmapContextCreateImage(context);
	CGContextRelease(context);
 
	UIImage* _newImage = [[UIImage alloc] initWithCGImage:newImage];
	CGImageRelease(newImage);
 
	return [_newImage autorelease];
}

最先创建了一个灰度的颜色空间导致合成出来的mask颜色都是反的,黑色的显出白色,后来发现一篇例子是用RGB颜色空间来做再自己加上黑色填充后就得到了想要的效果,效果图:
lomo效果

Written by 北

五月 20th, 2010 at 11:59 下午

Posted in iphone开发

Tagged with , , ,

在UIViewController中用多线程更新UI的异常

without comments

在UIViewController中用多线程时,如果该线程方法中有更新UI操作的话,会抛出如下错误:

Tried to obtain the web lock from a thread other than the main thread or the web thread.
This may be a result of calling to UIKit from a secondary thread. Crashing now…

貌似是因为UIKit是非线程安全的,所以更新UI只能在主线程中操作,解决的办法:

- (void)performSelectorOnMainThread:(SEL)aSelector withObject:(id)arg waitUntilDone:(BOOL)wait

用该方法指定要执行的UI更新Method在主线程中执行.

Written by 北

十一月 15th, 2009 at 9:06 上午

Posted in program

json for objective-c

without comments

一个json对象和NSDictionary对象相互转换的framework

project home:
http://code.google.com/p/json-framework/

Written by 北

八月 18th, 2009 at 9:26 上午

Posted in program

Tagged with

iphone状态栏网络标志

without comments

控制状态栏网络标志(就是有数据连接时显示一个转阿转的小图标)
//显示
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

//隐藏
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;

Written by 北

八月 14th, 2009 at 12:50 下午

Posted in program

Tagged with

log4j配置环境变量迂回法

without comments

在log4j.properties中配置输入文件
log4j.appender.A1.File= ${JBOSS_HOME}/server/default/log/my.log

JAVA中加载配置
//从系统环境变量中取出JBOSS_HOME路径设置为系统property
System.setProperty(“JBOSS_HOME”, System.getenv(“JBOSS_HOME”));
//读取log4j配置
PropertyConfigurator.configure(this.class.getResource(“/”).getPath() + “log4j.properties”);
logger = Logger.getLogger(this.class);

Written by 北

五月 30th, 2009 at 2:10 上午

Posted in program

Tagged with

相册登场

without comments

用Fleaphp写了一个相册程序

雏形已经有了 不过还会陆续完善

地址:http://rexis.cn/blog/album/

Written by 北

七月 18th, 2008 at 1:15 上午

Posted in program

.net读取Excel文件中的图片

without comments

首先要在项目中引入一个Excel的COM组件excel.dll

假设C盘根目录下存在a.xls的文件,在单元格第2行第2列存在要读取的图片

//引用Excel命名空间
using Excel;//......

//下面从a.xls中的2,2格复制图片到剪贴板,然后从剪贴板读取图片并显示到pictureBox1中。

private void btnGetImageFromExcel_Click(object sender, EventArgs e)
{
//初始化excel对象
Excel.Application excel = new Excel.Application();

//打开xls文件(注意:后面的参数都用Type.Missing填充,表示使用参数的默认值)
excel.Workbooks.Open(@"C:\a.xls", System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing);

//选定到第2行第2列所在的单元格
Range r = (Range)excel.Cells[2, 2];
r.Select();

//将单元格复制到剪贴板中
r.CopyPicture(XlPictureAppearance.xlScreen, XlCopyPictureFormat.xlBitmap);

//退出excel
excel.Quit();

//判断剪贴板中是否存在图片,如果存在,则将图片显示到pictureBox1中
if (Clipboard.ContainsImage())
{
Image image=Clipboard.GetImage();
pictureBox1.Image = image;
}
}

Written by 北

八月 3rd, 2007 at 12:55 下午

Posted in program