I am working on an app that uses some part of GLPaint code to paint over an image.
I am new to iphone development and for now am working directly on the GLPaint app to show image.
I do not have any UIImageView in the background I tried the your snippet but the screen is still blank (white). I think the init method clears everything to prepare for painting. I am not sure how to bring the image for painting.
Please throw some light on this.
Thanks in advance.
So, you want to paint over some image, right? The easiest way to achieve this, is to simply set the "opaque" value of your eaglLayer to NO. Usually it's inside a method, named "- (BOOL) _createSurface". Look for the following line:
Code:
eaglLayer.opaque = YES;
and set it to
Code:
eaglLayer.opaque = NO;
Now your eaglLayer should be transparent and reveal whatever view you put behind it. This way you don't actually have to put the image, you want to paint over, into your eaglView. Instead you can simply have it inside some UIView, you add as subView behind your eaglView. Makes sense?
In case I didn't get you right on this one, please post some code. Thanks.
So, you want to paint over some image, right? The easiest way to achieve this, is to simply set the "opaque" value of your eaglLayer to NO. Usually it's inside a method, named "- (BOOL) _createSurface". Look for the following line:
Code:
eaglLayer.opaque = YES;
and set it to
Code:
eaglLayer.opaque = NO;
Now your eaglLayer should be transparent and reveal whatever view you put behind it. This way you don't actually have to put the image, you want to paint over, into your eaglView. Instead you can simply have it inside some UIView, you add as subView behind your eaglView. Makes sense?
In case I didn't get you right on this one, please post some code. Thanks.
Hi,
Given below is the PaintingView.m code in GLPaint where eaglLayer set transparent in the PaintingView.initWithCode(). I get a white screen showing it is transparent but the image pattern is not set in the window.
Code:
......
if ((self = [super initWithCoder:coder])) {
//[imageView release];
CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
//****************** eaglLayer set to transparent so that the image below the view is made visible
eaglLayer.opaque = NO;
//****************** The image is rendered as color pattern and set in the window behind .... There is no need for UIImageView
//********* Having a UIImageView brings up an image but did not help in painting over image
UIImage *patternImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Image" ofType:@"png"]];
[self.window setBackgroundColor:[UIColor colorWithPatternImage:patternImage]];
// In this application, we want to retain the EAGLDrawable contents after a call to presentRenderbuffer.
eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], kEAGLDrawablePropertyRetainedBacking, kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil];
context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
if (!context || ![EAGLContext setCurrentContext:context]) {
[self release];
return nil;
}
// Create a texture from an image
// First create a UIImage object from the data in a image file, and then extract the Core Graphics image
brushImage = [UIImage imageNamed:@"Particle.png"].CGImage;
NSLog(@"PaintingView -- Get the width and height of the image");
// Get the width and height of the image
width = CGImageGetWidth(brushImage);
height = CGImageGetHeight(brushImage);
......
I tried to learn how GLImageProcessing app brings up the butterfly image in the eaglLayer so that I could save the image with the painted pattern, but got complicated.
Given below is the PaintingView.m code in GLPaint where eaglLayer set transparent in the PaintingView.initWithCode(). I get a white screen showing it is transparent but the image pattern is not set in the window.
Code:
......
if ((self = [super initWithCoder:coder])) {
//[imageView release];
CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
//****************** eaglLayer set to transparent so that the image below the view is made visible
eaglLayer.opaque = NO;
//****************** The image is rendered as color pattern and set in the window behind .... There is no need for UIImageView
//********* Having a UIImageView brings up an image but did not help in painting over image
UIImage *patternImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Image" ofType:@"png"]];
[self.window setBackgroundColor:[UIColor colorWithPatternImage:patternImage]];
// In this application, we want to retain the EAGLDrawable contents after a call to presentRenderbuffer.
eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], kEAGLDrawablePropertyRetainedBacking, kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil];
context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
if (!context || ![EAGLContext setCurrentContext:context]) {
[self release];
return nil;
}
// Create a texture from an image
// First create a UIImage object from the data in a image file, and then extract the Core Graphics image
brushImage = [UIImage imageNamed:@"Particle.png"].CGImage;
NSLog(@"PaintingView -- Get the width and height of the image");
// Get the width and height of the image
width = CGImageGetWidth(brushImage);
height = CGImageGetHeight(brushImage);
......
I tried to learn how GLImageProcessing app brings up the butterfly image in the eaglLayer so that I could save the image with the painted pattern, but got complicated.
Please point out the mistake am doing here.
Thank you.
Hi,
I just grabbed the latest GLPaint demo and had to do 2 things, in order to get this to work:
1) add your background image inside the AppController.m file, like
Code:
- (void) applicationDidFinishLaunching:(UIApplication*)application {
//I'm using a UIImageView, because setting the image as pattern image does no longer seem to work. It used to in older versions of GLPaint.
UIImageView *backgroundImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"nameOfImage.png"]];
[self.window insertSubview:imageView atIndex:0];
[backgroundImageView release];
}
2) Inside the initWithCoder method add the following line:
I just grabbed the latest GLPaint demo and had to do 2 things, in order to get this to work:
1) add your background image inside the AppController.m file, like
Code:
- (void) applicationDidFinishLaunching:(UIApplication*)application {
//I'm using a UIImageView, because setting the image as pattern image does no longer seem to work. It used to in older versions of GLPaint.
UIImageView *backgroundImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"nameOfImage.png"]];
[self.window insertSubview:imageView atIndex:0];
[backgroundImageView release];
}
2) Inside the initWithCoder method add the following line:
Code:
self.backgroundColor = [UIColor clearColor];
Hope, this information was helpful to you.
Hey,
I tried it with the current GLPaint demo code, It worked as expected. I'll integrate the code with other components (color picker, save and clear tab bars) and post questions if I get into trouble again.
Thanks a lot for your help I really appreciate it.
Need help on using loading PaintingView(of GLPaint) without PaintingWindow
@NewiPhoneDeveloper
The paint over a image is working now. I could save just the painted pattern, but its okay for now. Facing another problem.
The GLPaint demo loads the PaintingView from the PaintingWindow. But in my app, the paint view comes as 3rd step. I am trying to load the paintingView from the 2nd UIViewController class (as I did for loading 2nd from 1st).
I use the following code to load 2nd UIViewController from the 1st UIViewController.
I actually created a paintViewController with an xib and placed the PaintingView and my other toolbar buttons over the view generated during xib creation (instead of UIWindow). And used the following code to load the paintingViewController.
The issue is resolved now. The problem was with the compilers. The painting view was compiled as Objective C and the other views I used some C++ classes which made them compiled into Objective C++. So ran into conflicts during integration. I was able to find the c alternative for those views and it works fine now.
I just grabbed the latest GLPaint demo and had to do 2 things, in order to get this to work:
1) add your background image inside the AppController.m file, like
Code:
- (void) applicationDidFinishLaunching:(UIApplication*)application {
//I'm using a UIImageView, because setting the image as pattern image does no longer seem to work. It used to in older versions of GLPaint.
UIImageView *backgroundImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"nameOfImage.png"]];
[self.window insertSubview:imageView atIndex:0];
[backgroundImageView release];
}
2) Inside the initWithCoder method add the following line:
Code:
self.backgroundColor = [UIColor clearColor];
Hope, this information was helpful to you.
Hello,
Your brilliant idea saved my life (i can say). It is really great thing for me.
If possible can you suggest me, how to do undo,redo in GLPaint.
I just grabbed the latest GLPaint demo and had to do 2 things, in order to get this to work:
1) add your background image inside the AppController.m file, like
Code:
- (void) applicationDidFinishLaunching:(UIApplication*)application {
//I'm using a UIImageView, because setting the image as pattern image does no longer seem to work. It used to in older versions of GLPaint.
UIImageView *backgroundImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"nameOfImage.png"]];
[self.window insertSubview:imageView atIndex:0];
[backgroundImageView release];
}
2) Inside the initWithCoder method add the following line:
Code:
self.backgroundColor = [UIColor clearColor];
Hope, this information was helpful to you.
Background setting with image View worked as a charm for me, i have another issue,please help out in UNDO , REDO in GLPaint based app