how can i use use local images in my titanium project - android

i'm trying to change my background of a window in titanium , unfortuantly its not working. i also tried to use many local images and they did't load. any help is highly appreciated
,How can use my resources ?
var win1 = Titanium.UI.createWindow({
title:'Hello',
backgroundImage:'back.png',
});

You can do that, just like that. backgroundImage is supported on window.
Just make sure you use the right path:
backgroundImage: Ti.FileSystem.resourcesDirectory + 'back.png'
Here I am assuming back.png (case sensitive) is actually in the resources directory root.

Related

Iconize Xamarin with Fontawesome

I'm new to Xamarin and I'm trying to use the Iconize NuGet package for Xamarin, but I'm not having much luck. At the moment I'm working with a simple Android app. I've installed Iconize per the instructions and, save for an error on the line:
FormsPlugin.Iconize.Droid.IconControls.Init(Resource.Id.toolbar, Resource.Id.tabs);
(the compiler didn't like the Resource.Id.toolbar or Resource.Id.tabs so I removed it) everything compiles and runs. However, when I try to add an IconButton with a Fontawesome image, I get "System.NullReferenceException: Object reference not set to an instance of an object." error that points back to
the line LoadApplication( new App() ); in the MainActivity.cs.
I'm trying to add the IconButton to a grid in code (not XAML) using
grid.Children.Add( new IconButton
{
Image = "fa-info-circle"
}, 3, 2 );
Any ideas on how to make this work? The examples on the Iconize page haven't been very useful and I haven't found any examples on Google.
Okay I finally found something that was useful. I found a clue on this page and some other information on the project issues page on Github.
Ultimately, to get the icon to display I used
grid.Children.Add( new IconButton
{
Text = "fa-info-circle",
}, 3, 2 );
It was the Text property and not the Image property that I should have used.
Hope this helpful to someone else.

Taking Screenshots Using Qt C++ on Android

thanks for checking my question out!
I'm currently working on a project using Qt C++, which is designed to be multi-platform. I'm a bit of a newcoming to it, so I've been asked to set up the ability to take screenshots from within the menu structure, and I'm having issues with the Android version of the companion app.
As a quick overview, it's a bit of software that send the content of a host PC's screen to our app, and I've been able to take screenshots on the Windows version just fine, using QScreen and QPixmap, like so:
overlaywindow.cpp
{
QPixmap screenSnapData = screenGrab->currentBackground();
}
screenGrabber.cpp
{
QScreen *screen = QGuiApplication::primaryScreen();
return screen->grabWindow( QApplication::desktop()->winId() );
}
Unfortunately, Android seems to reject QScreen, and with most suggestions from past Google searches suggesting the now-deprecated QPixmap::grab(), I've gotten a little stuck.
What luck I have had is within the code for the menu itself, and QWidget, but that isn't without issue, of course!
QFile doubleCheckFile("/storage/emulated/0/Pictures/Testing/checking.png");
doubleCheckFile.open(QIODevice::ReadWrite);
QPixmap checkingPixmap = QWidget::grab();
checkingPixmap.save(&doubleCheckFile);
doubleCheckFile.close();
This code does take a screenshot, but only of the button strip currently implemented, and not for the whole screen. I've also taken a 'screenshot' of just a white box with the screen's dimensions by using:
QDesktopWidget dw;
QWidget *screen=dw.screen();
QPixmap checkingPixmap = screen->grab();
Would anyone know of whether there was an alternative to using QScreen to take a screenshot in Android, or whether there's a specific way to get it working as compared to Windows? Or would QWidget be the right track? Any help's greatly appreciated!
as i can read in Qt doc : In your screenGrabber.cpp :
QScreen *screen = QGuiApplication::primaryScreen();
return screen->grabWindow( QApplication::desktop()->winId() );
replace with :
QScreen *screen = QGuiApplication::primaryScreen();
return screen->grabWindow( 0 ); // as 0 is the id of main screen
If you want to take a screenshot of your own widget, you can use the method QWidget::render (Qt Doc):
QPixmap pixmap(widget->size());
widget->render(&pixmap);
If you want to take a screenshot of another app/widget than your app, you should use the Android API...

Show image in TImage dynamically (at run time) without opendialog in c++ builder xe8

I want to show image (png,jpg etc) in dynamically created (as per requirement and fully through coding) TImage component, at runtime in C++ builder xe8 (not delphi). But I dont want to use opendialogbox (suggested in many web sites). I want to run this app on my android device. I tried to use LoadFromFile(), it crashes the app on android, but when I run this on windows, its running smoothly. I am just a beginner to c++ builder. So guys pls help. Thanx in advance for any kind of help.Here is what I did.
void __fastcall TForm1::TForm1(TComponent* Owner)
{
TImage* img = new TImage(this);
img->Parent = this;
img->Bitmap->LoadFromFile("D:\\res\\profile.png");
}
Did you see what is the error?
If you run the program with the provided by you code I assume the error would be that the file is not found, because there is no such directory "D:\" in android.
One way to set the path is to write a static path which points to your image. For example : "/storage/sdcard0/DCIM/Camera/MyImage.jpg";
The second way is to include the <System.IOUtils.hpp> header and to use some built-in functions like:
System::Ioutils::TPath::GetPicturesPath();
System::Ioutils::TPath::GetAlarmsPath();
You can check them out, they might be useful.

titanium - android tab icons for density specific resources not working

So following the concept here:
http://docs.appcelerator.com/titanium/2.1/index.html#!/guide/Using_density-specific_resources_on_Android
i created a folder that was
Resources/android/images/
and then under that is:
high/
medium/
low/
and within each of those are the different-density files (like about.png, say)
The problem is that when i reference them:
var aboutTab = Ti.UI.createTab({
icon: '/images/about.png',
title: 'about',
window: about
});
OR as others have suggested like so (that is, losing the leading slash on 'images'):
var aboutTab = Ti.UI.createTab({
icon: 'images/about.png',
title: 'about',
window: about
});
and then load up the app, sure the tabs themselves are there... but the icons are not. Note that if i have a plain old file present at:
Resources/images/about.png
then the icon will appear... but not otherwise. Is there... is there something i'm missing on this?
Plz read and understand with cool mind this is working with me "More control" Paragraph.
var aboutTab = Ti.UI.createTab({
icon: 'images/about.png', // "/" remove this and try again
title: 'about',
window: about
});
plz, remove you old application from your Device or Emulator. after this Clean then build i think then this is work properly.
Ok, so the standard answer never ended up working for me. I'm using Titanium 2.1 here. {insert insult about Ti developer heritage here}
The solution to this is simple - don't use the much vaunted "smart titanium density specific solution" as discussed here:
http://docs.appcelerator.com/titanium/2.1/index.html#!/guide/Using_density-specific_resources_on_Android
Instead, use this simple, homely code to fix your problems!
var density = (Titanium.Platform.displayCaps.dpi <= 160) ? 'low' : (Titanium.Platform.displayCaps.dpi > 160 && Titanium.Platform.displayCaps.dpi < 240) ? 'medium' : 'high';
var preamble = (Ti.Platform.osname === 'iphone' || (Ti.Platform.osname === 'ipad') )? 'images':'android/images/'+density + '/';
Ok, so the first bit sets the density - NOTE i do not know the proper density readings for Ti just now, i'm just putting this up until i work them out anyhoo - and the second bit uses it if the app is an android one.
Then, where i used to have:
var aboutTab = Ti.UI.createTab({
icon: 'images/about.png',
title: 'about',
window: about
});
i now have:
var aboutTab = Ti.UI.createTab({
icon: preamble + '/about.png',
title: 'about',
window: about
});
And that is that!
FINAL WORD:
i've noticed that this can behave very differently depending on the Titanium version used (2.1.3 vs 2.1.0) or the android sdk used. I've had best results with 2.1.0 and 4.2 android, and that includes using the 'images' prefix (you know, how the guides say to do it).
One thing i noticed was that I cannot have both the high/medium/low folders AND the hdpi folders, i need one or the other.
Another problem i faced was that sometimes the code wouldn't load the android/images/ folders across. The completely bullet-proof way to do this is to use the code i've described, but put the density-specific folders directly under your images folder, and refer to them via images/high/ etc. Content in images is always copied across, and the code shown always works, regardless of Ti version.
Final note, make sure that your images are case-sensitively named, because it will work in the windows emulator but not in actual (unix-based) device.

image won't show in tableView

I'm creating a tableView in appcelerator (Android) and I want to add an image to it. This is just a test because I also had some problems with it in my project and I wanted to try it out first somewhere else so I wouldn't ruin my whole project.
I first added the standard png's to see if he would show those, and he did. But when I add a png that I've created, he refuses to show it in the tableView. Does someone know why he refuses to show the image? (I created that png in photoshop by changing one of the standard png's and adding my image to it.)
var win = Titanium.UI.createWindow({
title:'tableViewRow',
backgroundColor:'#fff'
});
var regData = [
{leftImage:'KS_nav_ui.png', title:'gft', left:20, color:'black'},
{rightImage:'KS_nav_views.png', title:'grofvuil', left:20, color:'black'},
{leftImage:'glas.png', title:'glas', left:20, color:'black'}
];
var tbl = Titanium.UI.createTableView({
data:regData
});
win.add(tbl);
win.open();
Here's an image of the result I get in my android emulator (android api: Google APIs Android 2.2 and screen:HVGA)
If you are using AppC 1.8, you may just need a forward slash in your path '/'. (or backward if Windows)
I've solved it. What I did is I ran the application in an android amulator. I closed the app and went back to the homescreen (where you can save some apps). I pressed on menu and went to the settings. Than I went to applications. I opened 'manage applications' and remove the application. I closed the emulator and ran it again and the images were shown.
I don't know why you have to do it, but it worked for me. I hope I can save someone the frustration by posting the answer (I know I had them :D)

Categories

Resources