How to create a osg::Image object in Android? - openscenegraph

On iOS/windows I can create a osg::Image object by this:
osg::ref_ptr<osg::Image> icon = osgDB::readRefImageFile(filePath);
the filePath param could be the "Resource/a.png", which is a relative path in the project. but this could not work in Android. I also tried using an absolute path likeļ¼š
"/storage/emulated/0/res/a.png"
the path was the full sd card path to a.png, but didn't work either.
The Image object was used to be the icon of a osgEarth::Annotation::PlaceNode:
osg::ref_ptr<osg::Image> icon = osgDB::readRefImageFile(filePath);
node->setIconImage(icon.get());
On iOS, the icon could be displayed, but didn't display on Android. I am certain the problem was the osg::Image object didn't create properly on Android.
I appreciate very much if anyone could help. Thanks.

Related

Android Studio can't resolve resource drawable

I'm designing my layout, and I've exported many assets from Sketch. Everything's going fine, but on just one particular asset, I'm getting the following error:
The resource is there, included in the project, I can open it (a regular PNG) perfectly etc, and is no different from any other assets in any way.
When I click Details on the error above, I get:
java.lang.NumberFormatException: Color value '#drawable/comment_off' must start with #
at com.android.layoutlib.bridge.impl.ResourceHelper.getColor(ResourceHelper.java:79)
at com.android.layoutlib.bridge.impl.ResourceHelper.getDrawable(ResourceHelper.java:270)
at android.content.res.BridgeTypedArray.getDrawable(BridgeTypedArray.java:729)
at android.widget.ImageView.<init>(ImageView.java:152)
at android.widget.ImageView.<init>(ImageView.java:140)
at android.widget.ImageView.<init>(ImageView.java:136)
...
Why on Earth does Android Studio think that my drawable is a color, while it's a PNG image like all the other assets in my project?
You may want to check the spelling of your drawable folder to ensure it is correct, and that the image exists at the referenced assets folder.

Can not assigned a bitmap object to QR code image returning from encoder

I installed Xamarin studio and trying to use System.Drawing frame work but it is not working. The reason I want this framework is to be able to define a Bitmap object. This bitmap object is assigned to a qr code image. Can anyone help me on how i can assigned an image to bitmap since i can not use bitmap in xamarin studio framework.
What i wanna do is as follows:
//create a qr code
QRCodeEncoder encoder = new QRCodeEncoder();
// Assign a bitmap image to the encoder since the encoder.encode returns bitmap image
Bitmap img = encoder.Encode("http://www.monkeywow.com");
// save the image in to images folder
img.save("www.monkeywow.com/images/imp.jpg", ImageFormat.jpg);
The problem is I can not use Bitmap img since i can not import System.Drawing into Xamarin.
I tried that and did not work. Since the encoder returns bitmap, i do not know how to obtain the image so i can save it where ever i want.
To display an image on screen, use UIImage. For working with low level bitmaps, use the CoreImage framework.
http://docs.xamarin.com/guides/ios/application_fundamentals/working_with_images/
http://docs.xamarin.com/recipes/ios/media/coreimage/
Xamarin.iOS includes a few System.Drawing types, e.g. Rectangle[F], Point[F] and Size[F], inside monotouch.dll to ease code sharing between (cross platform) projects.
However the System.Drawing.dll assembly itself is not part of the mobile profile that ships with Xamarin.iOS.
Like #Jason mentioned are several, native, ways you can do graphics on iOS (OpenGL would be another one).
Another option is to use the code from https://github.com/mono/sysdrawing-coregraphics which offers a partial System.Drawing API on top of CoreGraphics.

UIImagePickerController to set a background image, not working

I am writing an iPhone app, where the user should be able to choose, an in-app background picture from his own photo album.
I am trying to enable this feature using a UIImagePickerController.
At this point I get the the box asking me to choose a picture and I save the picture.
But after that, when I want to use the image chosen as background, with this kind of code (which is the same as how I set the default background at start):
UIColor *backGrndPict=[[UIColor alloc] initWithPatternImage:
[UIImage imageNamed:pngPath]];
self.view.backgroundColor=backGrndPict;
Nothing works. I just get a white background.
Thanks for any tip.
Michel,
Just for clarification, are you saving the picture that the user selects as a .png file or in an UIImage?
If you did use the UIImage method, try double checking the retain count of the UIImage. Again, it may not be as simple as this, but that is what I did with my app and was getting the exact same issue.
If you did save it as a .png file, did you do an error check? Also, I have the "Applications" folder for my iOS simulator loaded on the screen perchance I have to verify both the availability and the integrity of the file in question.
Also, I tend to slip on the path sometimes too. I have have messed up the path one too many times by forgetting to use the saved path (the file that my app saved, almost always under the documents folder) vs. the default bundle path for the app which is where the bundled images are saved.
Hope it helps.

Can I Capture phone screenshot using j2me app?

I am trying to develop a wireless phone projector, wherein I will be showing phone screen on projector using a projector connected PC.
I am bit confused on how to capture screenshot of any running application in j2me.
Can you help?
Just want to capture screenshot in j2me
I'm not really sure of what you wanted to do but if you are thinking of a way for your app to get a screenshot of its screen then what I can say is that you can and cannot do it. Why you cannot do it? Say your using a canvas in creating your screen. I think there isn't a way of converting the Canvas to an Image. The Canvas is limited to just drawing itself on the phone screen. But, like what I have said earlier, you can also create a screenshot of your app screen. What you need to have is an Image object over your Canvas. Why Image? It is because the Image object can be converted to an image file. And the image file will be your screenshot. But, of course, there should be something that dynamically creates the image source for the image object on the canvas.
Image myScreen = Image.createImage(createScreen());
A method that creates the screen:
InputStream createScreen(){
//dynamically creates the source of the screen
}
You can have a screenshot using myScreen. The drawback here is that rendering is quite slow. This is possible but I think this is kind of difficult to implement.
With this snippet code you can take a "screenshot" of the Canvases in your app:
public Image getScreenShot() {
Image screenshot = Image.createImage(getWidth(), getHeight());
Graphics g = screenshot.getGraphics();
paint(g);
return Image.createImage(screenshot);
}
Add getScreenShot() to any canvas that you want "screenshot" of it.Then you can get it's RGB and convert to byte[] and pass it on the network.
References:
developer.nokia

Images do not show up when I run my app on iOS device

I have images titled like so in my app:
image~iPhone.png
image#2x~iPhone.png
In interface builder I am loading image.png into my UIImageView. I also programatically load some images into a different view using imageWithContentsOfFile. The images all load fine when I run in the simulator but I get no images when I run on the device. If I use the full name of the image in interface builder it works but I want iOS to distinguish between high res and lower res. I have tried a lot of different things but can't figure this out. I see this error in the debugger as well:
Could not load the "image.png" image referenced from a nib in the bundle with identifier "com.mycompany.myproject"
Xcode 4
Deployment Target 4.1
Base SDK 4.3
Thanks for any help.
Ok...so after much experimenting I got it working.
I had two images named:
image#2x~iPhone.png
image~iPhone.png
and I was trying to load them using IB or imageWithContentsOfFile using
image.png
This worked fine in the simulator but not on my device. I just got a blank white screen where the image should be.
I finally renamed the high resolution image to:
image~iPhone#2x.png
Moving the '#2x' modifier after the device modifier(~iPhone) when referencing my images allowed it to work the way I understood that it should from reading Apple's docs. I was under the impression that you didn't need to include the device modifier when referencing images but I had to.
To sum up, I am now using
- image~iPhone.png
to reference my images in IB and programatically for some images. I now get iOS recognizing that I am on a retina screen and loading the #2x images accordingly. So the #2x modifier had to go at the end and the ~iPhone modifier had to be included in the name of the '.png'.
That is what worked for me. Hope it helps someone else. Note that I am only building my app for iOS4.1 and above so there might be some issues with this if you are supporting previous version.
iOS does not automatically pick the right image for the device like that. You are going to have to write code to check which device it is, and set the image by full name.
e.g. if ([[UIScreen mainScreen] scale] == 2) // set hi res image
Or, you can just use the same image in both, and set the content mode to scale to fill. It will look the same.
EDIT: Try writing either ~iphone (lowercase), or just don't write ~iPhone at all on the file name. If your app is not universal, then writing the ~iphone suffix is completely pointless.
iOS file system is case sensitive and device modifiers should be lowercase, it should be
image~iphone.png
image#2x~iphone.png
The #2x comes before the device modifier.
See the resource programming guide

Resources