How to save Bitmap to .tiff in Android? - android

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

Related

How to convert an image that is in png format to WSQ format for android

Hello I am currently developing an android app in biometric fingerprint reader , the app captures and sends the png format a SOAP service, but need to be sent in the WSQ format and then send it as an arrangement of bits in the service , thank you.
I guess after three years you already solved it somehow, but in case anyone else is looking for a solution, you can try the WSQ for Android library. (Disclaimer: I wrote the library.) Add the following dependency to your build.gradle file:
implementation 'com.gemalto.wsq:wsq-android:1.0'
and use the following code to produce the WSQ:
byte[] pngData = ...; //obtain the PNG data from somewhere
Bitmap png = BitmapFactory.decodeByteArray(pngData, 0, pngData.length);
byte[] wsqData = new WSQEncoder(png).encode();

How to detect if JPG is in RGB (or CMYK) format?

I need a (really fast) way to check if a JPG file is in RGB format (or any other format that Android can show).
Actually, at this moment, I just know if a JPG file can be show when I try to convert it to Bitmap using BitmapFactory.
I think this should not be the fastest way. So I try to get it by using ExifInterface. Unfortunately, ExifInterface (from Android) does not have any tag that indicates that the jpg can be shown in Android (color space tag or something).
Then, I think I have 2 ways:
1) A fast way to get bitmap from jpg: any tip of how to do it?
2) Or try to read Exif tags by my self, but without adding any other lib to the project: I don't have any idea of how to do it!
Ok so I did some looking around and I may have a solution for you but it may require a little work. The link is a pure java library that I think you can use in your project or at least modify and include a few classes. I have not worked with this yet but it looks like it will work.
http://commons.apache.org/proper/commons-imaging
final ImageInfo imageInfo = Imaging.getImageInfo(File file);
if(imageInfo.getColorType() == ImageInfo.COLOR_TYPE_CMYK){
}
else {
}

How to get the picture's shooting time in android development?

String picPath = "/mnt/sdcard/yepcolor/sina.png";
Bitmap bitmap = BitmapFactory.decodeFile(picPath);
I know the 'picPath' of the picture.Now, I want to get the picture's shooting time,and what should I do?Thanks.
As far as I know, png files doesn't contain such information. If you are reading jpeg files, however, you can use ExifInterface.

Android SKIA Image Decoding

HI,
I am currently studying how Android decode and image file. When I checked the code, it seems like it is calling the SKIA library. But, how do I know what are the image file format supported by android/skia basing on the source code?
I am not an expert in programming, so I am still trying to understand C++ and Java language.
I am now lost at SkImageDecoder* decoder = SkImageDecoder::Factory(stream); inside the BitmapFactory.cpp (JNI file). SkImageDecoder::Factory(stream) seems to be a template.
Anyone can explain me what is happening inside SKImageDecoder::Factory()? Any feedback will be greatly appreciated.
Thanks,
artsylar
In skia/include/images/SkImageDecoder.h file, there is the image list decoding supported by Skia:
enum Format {
kUnknown_Format,
kBMP_Format,
kGIF_Format,
kICO_Format,
kJPEG_Format,
kPNG_Format,
kWBMP_Format,
kWEBP_Format,
kLastKnownFormat = kWEBP_Format
};
In SkImageDecoder::Factory(stream) function, it will new a decoder instance according to analyze the Stream's header.
By looking at the source codes of Android, I think the following image formats are supported.
ICO (Windows ICON image format), BMP, JPEG, WBMP, GIF, and PNG.
Please correct me if I am wrong. Thank you.
PNG, JPEG, and GIF are the supported formats. The primary formats used on Android are PNG and JPEG.

Convert JPEG/PNG image to TIFF image format in android OS

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);

Categories

Resources