I am using libgdx 0.9.8 and trying to load .obj files as Mesh.But as specified in various tutorials and in the documentation its not taking Stream as paramtetr rather its asking for FileHandle. What should be passsed is it because of the version ?
I am currently using this code, but I am still struggling with texture loading:
ObjLoader model = new ObjLoader();
meshCar = model.loadObj(
Gdx.files.internal("data/car_white.obj"),
Gdx.files.internal("data/car_white"),
true
);
Related
There are the Bitmap for Android and UIImage for iOS. Is there a way to display both somehow in the Xamarin Forms Image control?
Obviously I need the Dependency Service. I will have two implementations that create either a bitmap or an uiimage using some source, but how do I bring those two products together to a single forms control? Both Android and iOS methods have to return something, that the image control can understand and display. I don't know what that might be.
Edit: I look for a way where I don't use storage space, if possible.
Edit2:
I tried Jasons suggestion and it works fine.
I create a bitmap in the Android project and return a MemoryStream object:
MemoryStream stream = new MemoryStream();
newImage.Compress(Bitmap.CompressFormat.Png, 0, stream);
return stream;
Then I consume it in my Xamarin.Forms Image control:
var stream = DependencyService.Get<ICrossPlatformImageProcesor>().Combine_Images(imagePath);
stream.Position = 0;
img_ImageView.Source = Xamarin.Forms.ImageSource.FromStream(() => stream);
I will have two implementations that create either a bitmap or an uiimage using some source, but how do I bring those two products together to a single forms control?
You can simply use Image Control of xamarin forms, images can be loaded specifically for each platform, or they can be downloaded for display.
For more information, you can refer to Working with Images.
I look for a way where I don't use storage space, if possible.
I'm not quite understand this, if you mean don't use memory, then I think it is not possible. If you mean your images are not saved in storage, then possibly you have an URL address on internet of your images?
Anyway, Image control in Xamarin.Forms support image source form ImageSource instance, file, Uri, and resources, to load image from uri, you can simply code like this:
var webImage = new Image { Aspect = Aspect.AspectFit };
webImage.Source = ImageSource.FromUri(new Uri("https://xamarin.com/content/images/pages/forms/example-app.png"));
I am trying to download an image using this code in my unity project my an android game.
public static Texture2D userTexture=new Texture2D(64, 64, TextureFormat.DXT5, false); //TextureFormat must be DXT5
public static IEnumerator UserPictureCallback(){
Debug.Log("USerPicture called");
FbDebug.Log("USerPicture called");
WWW url = new WWW("http://i1.wp.com/a0.twimg.com/sticky/default_profile_images/default_profile_1_normal.png?resize=64%2C64");
yield return url;
//profilePic.renderer.material.mainTexture = textFb2;
Debug.Log(url);
url.LoadImageIntoTexture(userTexture);
Debug.Log("Working");
}
And then I am trying to draw it in GUI using DrawTexture.
GUI.DrawTexture(new Rect(5,0,50,50),FB.userTexture,ScaleMode.StretchToFill, false, 0.0f);
But the image texture is not getting downloaded or at least it is not showing in the GUI. Can somebody help me with this?
I recently faced the same problem. I was creating an scrollable image gallery in Unity, where images are downloaded in real-time from the a web server. On iOS devices I was reaching very fast the memory limit (with consequent app crash). That was caused due to a very big number of www objects leaved in the memory and never deleted or released. Also a very big number of Texture2D objects leaked.
The main misunderstanding is considering a Texture2D like a variable of an object that self-contained the image information. Texture2D only point to a referenced asset so we need to create one before assigning to our GUI object. Without creating one we will overwrite the referenced asset in our project, leading to very crazy behaviour.
So this the code that works for me on iOS and just use the minimum of memory
public void DownloadImage(string url)
{
StartCoroutine(coDownloadImage(url));
}
IEnumerator coDownloadImage(string imageUrl)
{
WWW www = new WWW( imageUrl );
yield return www;
thumbnail.mainTexture = new Texture2D(www.texture.width, www.texture.height, TextureFormat.DXT1, false);
www.LoadImageIntoTexture(thumbnail.mainTexture as Texture2D);
www.Dispose();
www = null;
}
A brief comment:
You receive a url you will download the image from.
Start the coroutine that manage the download
Create the www object in the local scope
yield waiting the download to complete
Create a new Texture2D object/asset with parameters and assign to your final object mainTexture or what do you want
Use the "www.LoadImageIntoTexture()" function to COPY the image inside the created asset (this is the fundamental part)
Dispose and set to null the www object to prevent memory leaking or orphans
Hope it helps who will face the same problem.
An interesting lecture is this website where they implement a WebImageCache system to avoid re-downloading the same image many times.
http://studiofive27.com/index.php/unity-cached-web-images/
I know it is possible to save bitmap to png or jpg
now i want to save bitmap to .tiff,anybody can help?
Android does not have native support for saving TIFF files.
You best bet would be to get the raw byte array, and then using either a Java or NDK library (like libtiff) to save it as a TIFF.
I believe this is is a repost from here:
Convert a bitmap image to an uncompressed tif image in Java
To answer the question, the above answer suggested the following using the Java Advanced Imaging (JAI) library:
TIFFImageWriterSpi spi = new TIFFImageWriterSpi();
ImageWriter writer = spi.createWriterInstance();
ImageWriteParam param = writer.getDefaultWriteParam();
param.setCompressionMode(ImageWriteParam.MODE_DISABLED);
ImageOutputStream ios = ImageIO.createImageOutputStream(new File("output.tif"));
writer.setOutput(ios);
writer.write(null, new IIOImage(bmp, null, null), param);
You always can save the Bitmap as .png and convert it to .tiff
Android hasn't support for tiff images. You should use some library for working with tiff. For example my: https://github.com/Beyka/Android-TiffBitmapFactory
My goal is to validate some XML document against Schematron file in Android.
At the moment I am trying to use this library for Java.
So far, it doesn't seem to be working at all, I simply get empty array as the result of transform. This is piece of code from the library method I adjusted a bit.
Source xsltSource = (Source) jur.resolve( "iso_svrl_for_xslt2.xsl", null );
Source schemaSource = new StreamSource(this.schemaAsStream);
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(xsltSource);
transformer.transform(xsltSource, new StreamResult( baos ));
Does anyone have an idea how to get Transformer working for Android?
Thanks in advance.
The Extensible Stylesheet Language Transformations (XSLT) APIs can be used for many purposes. For example, with a sufficiently intelligent stylesheet, you could generate PDF or PostScript output from the XML data. But generally, XSLT is used to generate formatted HTML output (that we can consume in our Android Webview), or to create an alternative XML representation of the data. This will help you.
I am developing an app in which I need the image in TIFF format. But in android you can convert your bitmap/image to only JPEG/PNG image.
Is there a good way to convert JPEG/PNG file to TIFF format on android?
Android Do Not Support java.awt.image.*
check this.
http://developer.android.com/reference/packages.html
I'm not sure that Android SDK supports Java Image I/O, but check out following question: Java API to convert JPEG to TIFF
Android does not support TIFF files.
You can get the Bitmap's raw pixel data array and convert it to TIFF manually using any of the links from the previous comment.
If you are willing to add some C++ to your project via the Android NDK, then libtiff should do what you want.
I've recently found this great library on Github by Beyka (which uses libtiff and others natively) that provides many utilities for handling, opening, and writing .tiff files.
An example of converting JPEG to TIFF:
TiffConverter.ConverterOptions options = new TiffConverter.ConverterOptions();
//Set to true if you want use java exception mechanism
options.throwExceptions = false;
//Available 128Mb for work
options.availableMemory = 128 * 1024 * 1024;
//compression scheme for tiff
options.compressionScheme = CompressionScheme.LZW;
//If true will create one more tiff directory, else file will be overwritten
options.appendTiff = false;
TiffConverter.convertToTiff("in.jpg", "out.tif", options, progressListener);