Beyka / Android-TiffBitmapFactory

MIT License
133 stars 46 forks source link

JPG to TIff not converting correctly with last version #19

Closed eoherrer closed 7 years ago

eoherrer commented 7 years ago

Hi! Recently I upadted to the last version com.github.beyka:androidtiffbitmapfactory:0.9.7.4, but when I try to save the JPG image to Tiff isn't converting like the older version. Attached you will find the original and how is converted. Also here is the code I'm using it.

                  //Open some image
                  debugLog("Loading jpgBitmap ..");
                  Bitmap jpgBitmap = loadImage(resultImgUri.toString());

                  if(jpgBitmap != null) {

                    debugLog("jpgBitmap loaded");
                    //Create options for saving
                    TiffSaver.SaveOptions options = new TiffSaver.SaveOptions();
                    //By default compression mode is none
                    options.compressionScheme = CompressionScheme.LZW;
                    //By default orientation is top left
                    options.orientation = Orientation.LEFT_TOP;

                    //Add author tag to output file
                    options.author = "UPS";
                    //Add copyright tag to output file
                    options.copyright = "UPS Copyright";

                    //Save image as tif. If image saved succesfull true will be returned
                    debugLog("start saving tiff");

                    File tiffFile = sdkWrapper.generateTifFile();

                    boolean saved = TiffSaver.saveBitmap(tiffFile, jpgBitmap, options);

                    debugLog("finish saving tiff");

Please advice!!

Regards!!!

3.zip

eoherrer commented 7 years ago

I forgot to mention that later I convert to JPG again to show user how was the converting, here's the code

if (saved) { Uri resultTifUri = Uri.fromFile(tiffFile);

                      debugLog("Stored tif image as: " + resultTifUri.toString());

                      debugLog("Loading tif image to convert to JPG: " + resultTifUri.toString());

                      TiffBitmapFactory.Options jpgOptions = new TiffBitmapFactory.Options();
                      jpgOptions.inJustDecodeBounds = false;
                      Bitmap bmp = null;
                      bmp = TiffBitmapFactory.decodeFile(tiffFile, jpgOptions);

                      if(bmp != null) {
                        resultImgUri = sdkWrapper.storeImage(bmp, quality);

                        debugLog("Tif image converted to JPG: " + resultImgUri.toString());

                        jsonArgs.put("imageTiffUri", resultTifUri.toString());
                      }
                    }

And attached is the image

8ad91515-a2e1-4cc6-aad6-17b97f8263c1

eoherrer commented 7 years ago

The above example is with LZW compression, with CCITTFAX4 is worst attached the images.

4.zip

Beyka commented 7 years ago

Hello. I'm very sorry for this bug. Please use newest version 0.9.7.5, it contains old tiff creating algorithm with some improvements. Latest version should be fine.

eoherrer commented 7 years ago

Thanks for your quick response but I tried with the 0.9.7.5 and CCITTFAX4 Compression and didn't work :(.

Sorry I forgot to change the version, It is working now.

Beyka commented 7 years ago

Sorry I forgot to change the version, It is working now.

Oh! This is good, because I was disappointed by my work) I also created separate project to test save functions. Thank you for your feedback and testing my library. If you have any propositions - you can create an issue.