我想绘制一个图像的矩形 如何做到这一点?图像视图和矩形
Q
图像视图和矩形
4
A
回答
1
-(IBAction)Handeltap:(UIGestureRecognizer *)sender
{
if(sender.state==UIGestureRecognizerStateBegan)
{
tapPoint1 = [sender locationInView:sender.view];
NSLog(@"UIGestureRecognizerStateBegan and x=%d and y=%d",(int)tapPoint1.x,(int)tapPoint1.y);
img1=[[UIImageView alloc]initWithImage:nil];
[img1 setBackgroundColor:[UIColor lightTextColor]];
CGRect rect1=CGRectMake((float)tapPoint1.x,(float)tapPoint1.y,50,20);
NSLog(@"rect=%f and %f and %f and %f",rect1.origin.x,rect1.origin.y,rect1.size.width,rect1.size.height);
[img1 setFrame:rect1];
[self.view addSubview:img1];
[self.view bringSubviewToFront:img1];
}
if(sender.state==UIGestureRecognizerStateChanged)
{tapPoint2 = [sender locationInView:sender.view];
// NSLog(@"UIGestureRecognizerStateChanged and x=%d and y=%d",(int)tapPoint.x,(int)tapPoint.y);
[img1 setFrame:CGRectMake(img1.frame.origin.x,img1.frame.origin.y,(float)tapPoint2.x-img1.frame.origin.x,(float)tapPoint2.y-img1.frame.origin.y)];
}
if(sender.state==UIGestureRecognizerStateEnded)
{
tapPoint2 = [sender locationInView:sender.view];
NSLog(@"UIGestureRecognizerStateEnded and x=%d and y=%d",(int)tapPoint2.x,(int)tapPoint2.y);
[img1 setFrame:CGRectMake(img1.frame.origin.x,img1.frame.origin.y,(float)tapPoint2.x-img1.frame.origin.x,(float)tapPoint2.y-img1.frame.origin.y)];
}
}
添加轻敲手势并粘贴此
UILongPressGestureRecognizer *ges11=[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(Handeltap:)];
[self.view addGestureRecognizer:ges11];
坦克帮我..
1
0
如果你只是想简单的彩色矩形添加到图像,你可以做这样的:
UIImage *imageFile = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"myImageFile" ofType:@"jpg"]];
UIImageView *myImageFileView = [[UIImageView alloc] initWithImage:imageFile];
myImageFileView.frame = CGRectMake(0, 0, 320, 480); //size of image view
[self.view addsubview:myImageFileView]; //I assume this is within a view controller .m
UIView *rectangle = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)]; //A rectangle at point (0, 0) 50x50 in size.
rectangle.backgroundColor = [UIColor redColor]; //color the rectangle
[myImage addSubview:rectangle]; //add the rectangle to your image
[rectangle release];
[imageFile release];
[myImageFileView release];
相关问题
- 1. Java矩形图像
- 2. 非矩形图像
- 3. 非矩形图像
- 4. PyQt4:图形视图和像图大小
- 5. 画布矩形图像
- 6. 绘制矩形图像 - LibGdx
- 7. 图像地图中的高亮矩形
- 8. Android在图像视图中创建一个矩形
- 9. 无法在图像视图上绘制矩形
- 10. 将方形图像转换为矩形
- 11. 将矩形图像转换成梯形
- 12. CSS圆形裁剪矩形图像
- 13. 使用CSS在六角形图像内插入矩形图像
- 14. 将矩形图像绘制/翘曲为四边形图像
- 15. 如何将矩形图像设置为圆形图像
- 16. 使用ImageView和矩阵在图像上绘制图形
- 17. 如何更改UISlider的绘图矩形和拇指图像
- 18. 绘图矩形
- 19. 从图像中检测三角形,椭圆和矩形
- 20. 图形矩形名称和位置
- 21. 如何将图像从不规则矩形更改为矩形?
- 22. 获取图像JPG的矩形并在矩形中生成缩略图
- 23. 列表视图选择矩形
- 24. 矩形视图上的完美圆角
- 25. 如何在showcaseview中为列表视图制作矩形视图
- 26. 如何创建圆形图库视图/图像切换器/图像视图...?
- 27. 滚动视图和图像视图
- 28. 无法循环矩形图像矩阵的所有像素
- 29. 用矩形显示图像差异
- 30. c#检测图像中的矩形
你的意思是在图像上面画一些东西吗? – shannoga 2011-01-06 09:33:25
是的,我想在图像上画画。我可以在该图像上放置另一个图像或视图,这对我来说不是问题,但如何绘制该图像? – GameLoading 2011-01-06 09:53:21