Blackberry res folder naming convention - blackberry

I created a static function like this.
public static Bitmap Bitmap(String path) {
Bitmap bitmap = Bitmap
.getBitmapResource(Display.getWidth() + "/" + path);
System.out.println(Display.getWidth() + "" + path);
return bitmap;
}
However, when I called like this,
private Bitmap download = Config_GlobalFunction.Bitmap("btn_download.png");
The output gave me FRIDG could not find 320/btn_download.png.
In my res folder, I got an folder which was img and inside img got 6 different folders which were 160, 240, 320, 360, 480 and 640 folder.
How can I call correct folder's image based on Display.getWidth()?

It is possible to have a folder hierarchy under the /res folder but you must use getClass().getResourceAsStream(path) rather than Bitmap.getBitmapResource() in order to create your resource.
This example creates a Bitmap from the path /res/img/hi_res/ui/action_arrow.png:
String imagePath = "/img/hi_res/ui/action_arrow.png";
InputStream is = getClass().getResourceAsStream(imagePath);
byte[] imageBytes = IOUtilities.streamToBytes(is);
Bitmap b = Bitmap.createBitmapFromBytes(imageBytes, 0, imageBytes.length, 1);
It's a bit more work but it does mean you can have a nice folder structure, rather than hundreds of images lumped together in a single folder.

I've had problems with this before. BlackBerry apps don't seem to be well setup to handle resource files in subfolders. That is, you can store your resources in folders, but when bundled into your app (.cod file), they will essentially all be dumped into the same folder.
As you can see, that causes problems if you have multiple resources with the same name (but in different folders).
I used to use the Netbeans IDE to build BlackBerry apps, and with the Netbeans BlackBerry plugin, it seemed to handle this. But, with the RIM JDE, or Eclipse plugin, it doesn't. Perhaps it's something in the ant build script behind the toolset?
Anyway, I know you would like to do something similar to Android, where you would have:
res/drawable-hdpi/icon.png
res/drawable-mdpi/icon.png
res/drawable-xhdpi/icon.png
and pick the correct version of icon.png based on screen size / resolution. That's a good idea.
However, for simplicity, I would probably recommend changing your system to just use prefixes on your resource names, instead of folders. It's a pain, I know, but BlackBerry seems to handle it better.
So, just call your images:
res/img/320_btn_download.png
res/img/360_btn_download.png
res/img/480_btn_download.png
and then your code can be:
public static Bitmap Bitmap(String path) {
return Bitmap.getBitmapResource(Display.getWidth() + "_" + path);
}

if u want to get images depending on their resolutions then...give names to the images according to its resolution like 320x240_img1, 360x480_img1. no need to place these images in different folders....dump these images in ur res folder and call like this
int x = Display.getWidth();
int y = Display.getHeight();
String xx = Integer.toString(x);
String yy =Integer.toString(y);
_encImg = EncodedImage.getEncodedImageResource(xx+"x"+yy+".jpg");

Related

Opencv Reading Multiple images from Multiple folder

I have a folder which contain 100 or more sub folders and each of them contain many images.(Caltech Database)
I have problem with how to read them from the different folders ?
I want to store them as a single matrix with stacking columms of each image.
Use Boost Filesystem for C++. You can load all files in a directory and pass the file location to OpenCV in a string.
string folder = "../images/";
vector<string> imageFileLocations;
namespace fs = boost::filesystem;
vec v;
copy(fs::directory_iterator(folder), fs::directory_iterator(), back_inserter(v));
sort(v.begin(), v.end());
for (vec::const_iterator it(v.begin()); it != v.end(); ++it) {
if (fs::is_regular_file(*it)) {
string location = it->string();
imageFileLocations.push_back(location);
}
}
You'll have to add something recursive to be able to go into other folders. You can do that by checking if the iteraotr is at a file or a folder. See the Boost website for examples.

Setting/overriding an app deployment folder

Is there a way to set or override a project deployment folder in Mono for Android? For example, my application right now deploys to /data/data/SolutionEngine/files/.__override__
The nature of the application is that it loads plug-ins using Reflection, and by default it looks in the /Adapters sub-folder from the app root. This is how it works on the desktop and the Compact Framework, so for simplicity we'd like to continue to do the same on Android.
If I have a single solution that has the app and some plug-ins in it, I'd like those files to get deployed in the proper structure when I start debugging.
You could write out the plugins as android assets (see screenshot below). Please Note: You might need to change the extension to .mp3. See here. I didn't have this issue though.
Once you do that, you should be able to get the assets by using the Asset Manager. You can copy them to a different folder or do whatever with them. Here is a sample of reading them into memory and them writing out the name.
const String pluginPath = "Plugins";
var pluginAssets = Assets.List(pluginPath);
foreach (var pluginAsset in pluginAssets)
{
var file = Assets.Open(pluginPath + Java.IO.File.Separator + pluginAsset);
using (var memStream = new MemoryStream())
{
file.CopyTo(memStream);
//do something fun.
var assembly = System.Reflection.Assembly.Load(memStream.ToArray());
Console.WriteLine(String.Format("Loaded: {0}", assembly.FullName));
}
}

read file from res folder blackberry

I want to read file from "res" folder on blackberry. The file that i used is a file javascript.
I used this code InputStream in = classs.getResourceAsStream("file.js");. But i get "could not find this path" and I use also
String srcFile = "/res/ressourcesWeb/file.js";
FileConnection srcConn = (FileConnection) Connector.open(srcFile, Connector.READ);
InputStream in = srcConn.openInputStream();
but i got an exception.
Can any one help me to read the file and give me the right path that should I use?
Your res folder has to be inside src folder to be accessed from your code.
src folder is the root folder of your project package. And all folders outside of src folder are invisible for the code at runtime.
Check this post for more details: Blackberry runtime error: FRIDG: could not find img/logo.png
There's file location principle described.
You actually do not need to put your resources under the src folder for them to be accessible from your code.
That is one way to do it, but I don't think it's the best way. Files under the src folder should really be source code, not images, or other resources. For JavaScript resources, it's debatable whether those should be under src or not. Most projects I've seen have used the src folder for only Java source code.
In any case, if you would like to keep your file (or other resources, like images) outside the src folder, you can do so. The BlackBerry plugin for Eclipse actually sets it up like this by default, when you create a new project. There is a res folder at the top level, next to (not under) src.
If you have
src\
src\com\mycompany\myapp\
res\
res\resourcesWeb\
res\resourcesWeb\file.js
Then, you can open the file like this:
String jsPath = "/resourcesWeb/file.js";
InputStream input = getClass().getResourceAsStream(jsPath);
byte [] content = IOUtilities.streamToBytes(input);
String contentAsString = new String(content);
P.S. You also can probably do this:
String jsPath = "/file.js";
InputStream input = getClass().getResourceAsStream(jsPath);
and not specify the path to the resource. Obviously, this will only work if there are no naming conflicts in your resource folders (e.g. you don't have /res/resourcesWeb/file.js and also /res/otherPath/file.js)

ABCPDF Font Printing Layout - Machine Dependent

I am using ABCPDF to print a PDF file to a local printer via EMF file. I've based this very closely on ABC PDF's sample "ABCPDFView" project. My application worked fine on my Windows 7 and Windows XP dev boxes, but when I moved to a Windows 2003 test box, simple embedded fonts (like Times New Roman 12) rendered completely wrong (wrong spot, and short and squat, almost like the DPI's were crazily wrong).
Note that I've hardcoded the DPI to 240 here b/c I'm using a weird mainframe print driver that forces 240x240. I can discount that driver as the culprit as, if I save the EMF file locally during print, it shows the same layout problems. If I render to PNG or TIFF files, this looks just fine on all my servers using this same code (put .png in place of .emf). Finally, if I use the ABCPDFView project to manually add in a random text box to my PDF, that text also renders wrong in the EMF file. (Side note, if I print the PDF using Acrobat, the text renders just fine)
Update: I left out a useful point for anyone else having this problem. I can work around the problem by setting RenderTextAsText to "0" (see code below). This forces ABCPDF to render the text as polygons and makes the problem go away. This isn't a great solution though, as it greatly increases the size of my EMF files, and those polygons don't render nearly as cleanly in my final print document.
Anyone have any thoughts on the causes of this weird font problem?
private void DoPrintPage(object sender, PrintPageEventArgs e)
{
using (Graphics g = e.Graphics)
{
//... omitted code to determine the rect, used straight from ABC PDF sample
mDoc.Rendering.DotsPerInch = 240 ;
mDoc.Rendering.ColorSpace = "RGB";
mDoc.Rendering.BitsPerChannel = 8;
mDoc.SetInfo(0, "RenderTextAsText", "0");//the magic is right here
byte[] theData = mDoc.Rendering.GetData(".emf");
using (MemoryStream theStream = new MemoryStream(theData))
{
using (Metafile theEMF = new Metafile(theStream))
{
g.DrawImage(theEMF, theRect);
}
}
//... omitted code to move to the next page
}
Try upgrading to the new version of abcpdf 8, it has its own rendering engine based on Gecko and so you can bypass issues like this when abcpdf is using the inbuilt server version of IE for rendering.
I was originally RDPing in with 1920x1080 resolution, by switching to 1024x768 res for RDP, the problem went away. My main program runs as a service, and starting this service from an RDP session w/ 1024x768 fixes it.
I have an email out w/ ABC PDF to see if they can explain this and offer a more elegant solution, but for now this works.
Please note that this is ABC PDF 7, I have no idea if this issue applies to other versions.
Update: ABC PDF support confirmed that its possible the service is caching the display resolution from the person that started the process. They confirmed that they've seen some other weird issues with Remote Desktop and encouraged me to use this 1024x768 workaround and/or start the service remotely.

How to write a simple .txt content processor in XNA?

I don't really understand how Content importer/processor works in XNA.
I need to read a text file (Content/levels/level1.txt) of the form:
x x
x x
x x
where x's are just integers, into an int[,] array.
Any tips on writting a SIMPLE .txt importer??? By searching google/msdn I only found .x/.fbx file importer examples. And they seem too complicated.
Do you actually need to process the text file? If not, then you can probably skip most of the content pipeline.
Something like:
string filename = "Content/TextFiles/sometext.txt";
string path = Path.Combine(StorageContainer.TitleLocation, filename);
string lineOfText;
StreamReader sr = new StreamReader(path);
while ((lineOfText = sr.ReadLine()) != null)
{
// do something
}
Also, be sure to set the "Build Action" to "None" and the "Copy to Output Directory" to "Copy if newer" on the text files you've added. This tells the content pipeline not to compile the text file but rather copy it to the output directory for use as is.
I got this (more or less) from the RacingGame sample provided by Microsoft. It foregoes much of the content pipeline and simply loads and processes text files (XML) for much of its level data.
XNA 4.0 uses
System.IO.Stream stream = TitleContainer.OpenStream("tilename.txt");
See http://msdn.microsoft.com/en-us/library/bb199094.aspx and also http://blogs.msdn.com/b/shawnhar/archive/2010/12/09/reading-files-in-xna-game-studio-4-0.aspx
There doesn't seem to be a lot of info out there, but this blog post does indicate how you can load .txt files through code using XNA.
Hopefully this can help you get the file into memory, from there it should be straightforward to parse it in any way you like.
XNA 3.0 - Reading Text Files on the Xbox
http://www.ziggyware.com/readarticle.php?article_id=69 is probably a good place to start. It covers creating a basic content processor.

Resources