Posts Tagged ‘Code Snippet’
Posts that have small parts from a bigger code.
Android: How to return RGB values from an image file
Posted by Dimitri | Filed under Programming
Surprisingly, it’s quite easy to get the RGB value from an image file in Android. It’s certainly a lot easier than retrieving the pixel values from the Camera Preview. All that is required is to load the image file into a Bitmap object and them call the getPixel() method from the loaded bitmap.
It’s also possible to call this method to create an array of alpha and RGB values (ARGB) without calling the copyPixelsToBuffer() method, avoiding the use of buffers in Android which make things more complicated than it should be. As an example, the following code prints the color values of the pixels from the 4 corners of the image in LogCat and creates a RGBA array that stores each pixel color value:
Unity: How to use a GUI Texture to play fullscreen videos
Posted by Dimitri | Filed under Programming
Warning: this tutorial only works with Unity Pro because the free version doesn’t come with video playback support. The code was created and tested with Unity version 3.3. It won’t work for versions 2.6 and below (requires some adaptation).
This Unity post explains how to set up a GUI Texture at the Unity editor and the code necessary to play a fullscreen video, that can be used for the studio logo animation at the beginning of the game, the game’s intro or any other video that needs to take the whole screen. It also explains how to properly scale the video based on the screen dimensions. At the end of the post, a Unity project featuring all the code explained here is available for download.
Import STL libraries to the Android NDK code
Posted by Dimitri | Filed under Programming
This is a quick tip for those who are beginning to write native Android code. As one may have noticed, it isn’t possible to use containers like, string, vector, list inside the NDK samples. These are all part of the STL (Standard Template Library), and are expected to be available when writing C++ code.
To add STL to your NDK code, locate the Application.mk file inside your project’s jni folder. If it isn’t there, create it. Please note that the Application.mk is not the Android.mk file! The Android.mk file instructs the compiler and the JNI on how NDK code should be handled. The Application.mk, works similarly as the Android manifest file for your NDK code, allowing the programmer to add permissions and define other applications’ properties, like such as ‘enabling’ the STL support.
Embedding the Unity Web Player with jQuery
Posted by Dimitri | Filed under Programming
This post explains how to use jQuery to embed the Unity Web Player on a page. This post was inspired by GFX47, after reading this tweet. Here, you will find a step-by-step explanation on how to load the script on a HTML file. This will be achieved by using a jQuery plugin.
Unity3D already comes the tools to export a HTML file with all the code needed to embed the player. With that, one might be wondering what are the advantages of using jQuery to embed the Web Player. Here’s a list of advantages:
Android: Retrieving the Camera preview as a Pixel Array
Posted by Dimitri | Filed under Featured, Programming
This post explains how to take the live images created by Android’s camera preview feature and return them as a RGB array, that can be used to all sorts of things, like custom effects preview and real-time image filtering. This post used the CameraPreview class that already comes bundled with Android’s SDK because it has everything already set-up, that way is just a matter of inserting more code. The techniques shown here works with Android 2.1 and should work with versions 1.6 and 1.5.
The first thing to do is to import the API Demos project to your Workspace. To do that, in Eclipse, click File -> New -> Android Project. In the dialog that has just opened, give the project a name at the first field (like API Demos 8) and select ‘Create project from existing source’. Now browse to <Android SDK folder>\samples\android-7\ApiDemos. Finally, mark Android 2.1 as the Build Target and click Finish: (more…)