I add WhirlyGlobe to my project, it works well. Now I need to add image as a mark, I use the code like this. But it seems not work well.
The label show a white area on the top of first character.
And the console log 'Texture::createInGL() glGenTextures()'.
What can I do to solve it.
Texture *theTex = new Texture(#"icon", #"png");
theTex->setUsesMipmaps(true);
SimpleIdentity theTexId = theTex->getId();
theScene->addChangeRequest(new AddTextureReq(theTex));
SingleLabel *gzLabel = [[[SingleLabel alloc] init] autorelease];
gzLabel.text = #"XXXXXX";
gzLabel.iconTexture = theTexId;
[gzLabel setLoc:GeoCoord::CoordFromDegrees(113.2759952545166, 23.117055306224895)];
[labels addObject:gzLabel];
Is the texture a power of two along each side?
Related
I am looking for example code how to merge NSImages into one new NSImage for Mac OS (not Iphone IOS). Thx
You can use the powerful filters from Core Image to merge two NSImages.
In this example we're using Core Image's "CIAdditionCompositing" filter.
First, make CIImages from the two NSImages you want to blend, for example using their URL:
let img1 = CIImage(contentsOfURL: yourFirstImageURL)
let img2 = CIImage(contentsOfURL: yourSecondImageURL)
Then initialize the CIFilter:
let filter = CIFilter(name: "CIAdditionCompositing")!
filter.setDefaults()
Merge the two images, you get to decide which one is in front of the other:
filter.setValue(img1, forKey: "inputImage")
filter.setValue(img2, forKey: "inputBackgroundImage")
let resultImage = filter.outputImage
Get back an NSImage:
let rep = NSCIImageRep(CIImage: resultImage!)
let finalResult = NSImage(size: rep.size)
finalResult.addRepresentation(rep)
finalResult // is your final NSImage
If you need to merge several images, simply take the result of the previous merge operation and add it again to another image using this same code.
Note: in this example I'm "force unwrapping" the optionals, for clarity. In your real code you should handle the possibility of failure and safely unwrap the optionals instead.
There is an issue of GLKView, I'm stuck here a lot. First, I create EAGLContext context and make it current:
EAGLContext* pOpenGLContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3];
if(!pOpenGLContext)
return nil;
if(![EAGLContext setCurrentContext:pOpenGLContext])
return nil;
Runs ok (I need version 3 so it sutes me)! Then I create GLKView, attached to previously created context:
GLKView* pOpenGLView = [[GLKView alloc] initWithFrame:Frame context:pOpenGLContext];
It's ok. But this code don't change anything at all :(
[pOpenGLView setDrawableColorFormat:GLKViewDrawableColorFormatRGBA8888];
[pOpenGLView setDrawableDepthFormat:GLKViewDrawableDepthFormat24];
[pOpenGLView setDrawableStencilFormat:GLKViewDrawableStencilFormatNone];
[pOpenGLView setDrawableMultisample:GLKViewDrawableMultisampleNone];
Then I do some final stuff:
pOpenGLView.delegate = self;
[pMainWindow addSubview:pOpenGLView];
...
However, after using GLKViewDrawableStencilFormatNone, I asks OpenGL for a depth and stencil formats... I get:
glGetIntegerv(GL_DEPTH_BITS, &OpenGLDepthBits); // = 32 (I need 24)
glGetIntegerv(GL_STENCIL_BITS, &OpenGLStencilBits); // = 8 (I need 0)
I need to turn stencil buffer off! I need to set 24-bit format depth buffer.
I have try to do like this also:
pOpenGLView.drawableColorFormat = GLKViewDrawableColorFormatRGBA8888;
pOpenGLView.drawableDepthFormat = GLKViewDrawableDepthFormat24;
pOpenGLView.drawableStencilFormat = GLKViewDrawableStencilFormatNone;
How can I get it? What is wrong here? Thank you.
I am trying to make a small calculator app.
When a UIButton is pressed, the Button title is added to a UITextField.
kind of:
myuitextfield.text = [myuitextfield.text stringByAppendingString:[button currentTitle];
When I reach the end of my textfield, the text gets truncated. How can I disable this, so the textfield starts scrolling automatically and allows adding more characters?
I tried every possible option in Interface Builder, without any luck.
Isn't the UITextField supposed to scroll automatically? I can see this behavior when a native keyboard is used and text is entered.
I have chosen UITextField, as I need only 1 Line.
To illustrate the Problem:
When I enter text using my custom UIButtons text gets truncated
When I tap the UITextField and enter text using the keyboard I can enter unlimited text and the text is not truncated.
If you are facing this issue on iOS7, I've managed to fix it after been inspired by this post. In my case I had a field for entering an email address and after reaching the edge, the user could carry on typing but the text would be invisible (off-field).
First, add a callback to your UITextField so that you can track a text change to the field:
[self.field addTarget:self action:#selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
Then evaluate the size in pixels of the entered string as it is typed and change the text alignment from left to right when reaching the edge of the field area:
- (void)textFieldDidChange:(NSNotification *)aNotif{
float maxNumPixelsOnScreen = 235; // Change this value to fit your case
CGSize maximumSize = CGSizeMake(maxNumPixelsOnScreen + 10, 1);
NSString *aString = self.field.text;
CGSize stringSize = [aString sizeWithFont:fieldFont
constrainedToSize:maximumSize
lineBreakMode:NSLineBreakByWordWrapping];
self.field.textAlignment = NSTextAlignmentLeft;
if (stringSize.width >= maxNumPixelsOnScreen)
self.field.textAlignment = NSTextAlignmentRight;
}
Note:
self.field is the offending UITextField
maximumSize: I'm adding 10 the the width to be slightly over the limit defined
fieldFont is the UIFont used to render the text field
Hope it helps!
you have to add UITextview and limit the number of lines to 2.Textfield doesnt work with two lines.Textview is same as textfields except the delegates and some properties differ.
I'd like to display a label on top of each bar column with the delegate method:
-(CPTLayer *)dataLabelForPlot:(CPTPlot *)plot
recordIndex:(NSUInteger)index {
CPTMutableTextStyle *textStyle = [CPTTextStyle textStyle];
textStyle.color = [CPTColor whiteColor];
textStyle.fontSize = 12.0f;
CPTTextLayer *textLayer = [[[CPTTextLayer alloc] initWithText:#"x" style:textStyle]
autorelease];
return textLayer;
}
In case that it is my project that brings this problem, I directly insert this code snippet into the CPTTestAppBarChartController.m file in the CPTTestApp-iPhone project downloaded from
here.
But it still takes about 2 mins to display the labels. How can I make it display faster?
Thanks.
How much data are you plotting? If it's a lot (100's of points), you might want to only create labels for the visible points. Reload the data using the -reloadDataInIndexRange: method to load new labels when new data moves into the visible range.
You can also create the text style once and store it in a static local variable or an ivar instead of creating a new one for every label. That will save a little bit of time if you have a lot of labels.
P.S. Be sure to use [CPTMutableTextStyle textStyle] instead of [CPTTextStyle textStyle] to create the text style.
I am using Monobjc and Mono to develop an application where the user can zoom in on images. The very first image shows up fine. But when the user navigates to the next image, it shows up blank with a white background. And the subsequent images also show up blank. Now when the same app is executed on 10.6 and 10.7, the images show up perfectly.
There is no additional code that I have written for setting up IKImageView. It is set up in InterfaceBuilder but that's pretty much it.
My code is -
//ImgeData is the binary format of the image.
NSData data = new NSData(ImageData);
NSBitmapImageRep imageRep = new NSBitmapImageRep(data);
NSImage image = new NSImage(new NSSize(imageRep.PixelsWide, imageRep.PixelsHigh));
image.AddRepresentation(imageRep);
image.Retain();
NSData imgDat = image.TIFFRepresentation;
if(imgDat != null)
{
var imgSrc = CGImageSource.CreateWithData(imgDat, null);
var imgRef = CGImageSource.CreateImageAtIndex(imgSrc, 0, null);
if (_ikImageView == null)
{
return;
}
_ikImageView.SetImageImageProperties(imgRef,null);
CGImage.Release(imgRef);
}
UPDATE - I realized that I can see the hand over the blank area. Is it possible the image has gotten hidden ?.
MORE Update - My Window contains NSView which inturn contains IKImageView. Now the entire IKImageView is replaced with a white patch. But if I move the mouse over the area, I see a hand coming up. This tells me that the image is getting rendered but IKImageView is not able to display itself.