Texture in the Unity Resources path doesn't load on Android - android

I'm developing a game for Android using Unity, and I need load some texture from the Resources path. But this only works in the editor, and when I build the project for Android, the image doesn't load.
My code looks like this:
public void setTipTextTexture(string texture){
texture = "TipTexts/" + texture;
this.tipTexture = Resources.Load(texture) as Texture;
}
What am I doing wrong?

Related

Jpeg image from Android camera cannot be loaded as Qt Pixmap

In my android application, I used ImageReader surface to capture the image from the camera and dump it into a file. Here is the relevant code:
void saveImage(Image img) {
Bytebuffer buf = img.GetPlanes()[0].getBuffer();
buf.rewind();
byte[] data = new byte[buf.remaining()];
buf.get(data);
saveToFile(data);
}
The generated file, when viewed through avplay, seems to display the image just fine. However, when I load the same content using Qt's QPixmap::loadFromData on Ubuntu, the method fails. The errors I get are:
Corrupt JPEG data: premature end of data segment
Invalid JPEG file structure: two SOI markers
I am wondering if anyone has any insight on how to overcome this problem. Not sure if it is a problem with Android MediaCodec class or the jpeg library Qt internally uses has a bug. Regards.

Gaussian blur with opencv in ios

I am trying to make a gaussian blur with opencv in ios. I have already included opencv into my app, but I don't know how to call it so that it makes a gaussian blur.
In Android I call it like this:
Mat source = Highgui.imread(filepath, Highgui.CV_LOAD_IMAGE_COLOR);
Mat destination = new Mat(source.rows(),source.cols(),source.type());
Imgproc.GaussianBlur(source, destination, new Size(45, 45), 0);
Highgui.imwrite(getDir().getPath() + File.separator +"Gaussian45.jpg", destination);
Is there something similar in iOS too?
Thanks for your answers.
By the looks of things, You have to convert it to a cv::Mat, then you can use the normal guassian blur c++ method and then convert it back to ULLImage
The above link demonstrates how to convert from and to the two image types. Once you have converted it to cv::Mat you simply use this method:
void GaussianBlur(InputArray src, OutputArray dst, Size ksize, double sigmaX, double sigmaY=0, int

Android development: how to open a .dcm file as a bitmap?

I'm currently trying to make an android dicom app
Following code opens pictures drom res/drawable in "ussual" image formats, but it doesn't work with .dcm
public class BitmapView extends View
{
public BitmapView(Context context) {
super(context);
}
#Override
public void onDraw(Canvas canvas) {
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.test);
canvas.drawColor(Color.BLACK);
canvas.drawBitmap(bmp, 10, 10, null);
}
}
in the main activity:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new BitmapView(this));
}
thanks in advance!
Dicom is a kind of generic container. Inside a Dicom file you can find a huge variety of image formats. From grayscale ones to RGB, from single frame to multiframe ones, with pixel value ranges not in the ordinary 8 bit (24/32 in RGB/RGBA) but also in 12 or 16 bit grayscales.
Dicom files include many elements (fields) indicating the type of the contents and even how such contents should be presented. It is not as simple as converting the Dicom image to BMP.
If you are retrieving Dicom images from a PACS, I would suggest using WADO service. This way, you can obtain Jpeg images (the results of having applied a presentation state to the contents of the Dicom file).
The other option is to use some utility to convert the Dicom file to a more conventional image format. There are some excellent open source tools, such as dcmj2pnm, from the DCMTK toolkit.
Dicom images are not recognized by Android and therefore you cannot open them using a BitmapFactory object.
Recently Imebra has been extended with Java wrappers that call the Imebra native code and comes with a pre-built JAR so you don't have to deal with JNI compilation.
In addition to the 2 options mentioned by jap1968 and Paolo, which are both good but require using some method for converting the image on a different platform then viewing it on the Android device and an internet connection, you can actually view the Dicom file itself on the Android device directly if you use a library that supports DCM and its different sub-types. One such toolkit has a free demo application on Google Play here:
https://play.google.com/store/apps/details?id=leadtools.datasetdemo

LibGDX and ObjLoader not displaying .mtl?

I am trying to load .obj files into an Android project with LibGDX. The files have no texture file, but include materials in .mtl files. I'm using the latest official nightly, and rendering the object file only results in the object appearing white. How do I get the ObjLoader to use the .mtl file?
#Override
public void create() {
objLoader = new ObjLoader();
model = objLoader.loadObj( Gdx.files.internal("data/obj.obj"), true);
}
#Override
public void render() {
Gdx.gl.glClearColor(0, 0, 0, 0);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
batch.begin();
model.render();
batch.end();
}
This is how the code to render the object is called.
Here is a link to the ObjLoader class
https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/graphics/g3d/loaders/wavefront/ObjLoader.java
What am I doing wrong? And why won't it load the .mtl file? From what I can understand, it should load a .mtl file that's in the same folder and same name as the .obj file.
EDIT
I have messed around a bit, putting some lines into the ObjLoader class to log what it is and isn't loading. It looks like it's loading the mtl file, and assigning each mtl to a Material instance, and it also looks like the obj is correctly asking for those materials.
Is there something I need to enable or otherwise do on the OpenGL end to make sure it's using these materials properly?
The ObjLoader and especially the MtlLoader it uses is very limited. Try using the new 3D api with fbx instead. Here's explained how to load a model: http://blog.xoppa.com/loading-models-using-libgdx/.
I found the very same issue, and that's exactly why I both reported it here:
https://github.com/libgdx/libgdx/issues/2441
and committed a fix to it here:
https://github.com/libgdx/libgdx/commit/d7e716351d26ddfba19ce9e0b3bdfb449dbc81b7
, supporting virtually all MTL parameters out there. Note that this is a WIP, and (hopefully) will get into trunk once it's finished.

Exception when trying to read pack file with TextureAtlas

Shouldn't this work?
TextureAtlas atlas = new TextureAtlas(Gdx.files.internal("data/texture.png"));
AtlasRegion region = atlas.findRegion("ape_glad");
Sprite ape= new Sprite(region);
Instead I get: com.badlogic.gdx.utils.GdxRuntimeException: Error reading pack file: data/texture.png at the first line above O.o
Thanks for helping!
First, you need to create a texture atlas, using TexturePacker is the recommended way for libgdx. It results in the texture image and another file (containing the required information for libgdx TextureAtlas).
In your code, you need to provide the atlas file to the constructor, see TextureAtlas() documentation, instead of the image itself:
TextureAtlas atlas = new TextureAtlas(Gdx.files.internal("data/texture.atlas"));
(Notice the use of the 'atlas'-file instead of the image file)

Categories

Resources