Android Question using pngtastic in B4A

Discussion in 'Android Questions' started by Robert Valentino, Apr 9, 2015.

  1. Robert Valentino

    Robert Valentino Well-Known Member Licensed User

    I would like to use PNGTastic to compress PNG files generated by my program (need to EMail them).

    The ones I generate are in the 190k range but after something like TinyPNG they become 75k Big difference.

    This (according to the posting is a Small standalone Java lib) that will do the same thing for me.

    I am embarrassed to say I have NO idea where to start (other than a #AddionalJar statement which I am not completely such what I should say afterwards)

    ANY help would be greatly appreciated

  2. Jeffrey Cameron

    Jeffrey Cameron Active Member Licensed User

    If your images do not need to be in PNG format you may consider saving in JPG format instead of PNG? That way you can increase the image compression and create smaller images initially, something like:
    Public Sub SaveBitmapAsJPG(Dir As String, FileName As String, Picture As Bitmap, QualityPercent As Int)
    Dim Out As OutputStream = File.OpenOutput(Dir, FileName, False)
    If QualityPercent < 0 OR QualityPercent > 100 Then
            QualityPercent = 
    End If
         Picture.WriteToStream(Out, QualityPercent, 
    End Sub
    Peter Simpson likes this.
  3. Robert Valentino

    Robert Valentino Well-Known Member Licensed User

    I have tried all the image types JPEG, PNG and GIF

    For some reason my screen shots do not compress well with JPEG at 50% the file size is 154.5KB with PNG the files size is 94.8KB

    Tiny PNG makes the shrinks the full PNG file down to 33KB and it looks a little better then what the JPEG does with a 50% setting.

    Getting a 120KB saving bonus makes it Easy to Email the file to someone (in this case the file is a Players Golf Score Card)

    Based on it's write up I am assuming I would get similar compression with PNGTastic

    I have included the Files so you can see.

    NOTE: These are not real score cards just typed in numbers for testing

    JPEG at 50%
    GolfScoreRound-20150405 - 13_02.jpeg

    GolfScoreRound-20150405 - 13_02.png

    GolfScoreRound-20150405 - 13_02 - Tiny.png
  4. walterf25

    walterf25 Well-Known Member Licensed User

    Hi, I actually started playing with the JavaObject and the #AdditionalJar methods today, and i got this working, however I don't really see a big difference when compressing a png file, for example, I tried compressing a 316kb picture and the lowest i can get it to is 237kb.
    If you want to play around here's the code i'm using, you need to somehow make a jar file from the project file from the link you provided in the first post.

    'You need to first copy any image from your dirAssets folder to your DirDefaultExternal folder
    File.Copy(File.DirAssets, "screenshot.png"File.DirDefaultExternal, "screenshot.png")

    'Initialize the pngOptimizer class
    Dim optimizer As JavaObject

    'Then you need to instatiate the pngImage class and pass the filename path
    Dim png As JavaObject
    "com.googlecode.pngtastic.core.PngImage"Array(File.Combine(File.DirDefaultExternal, "screenshot.png")))

    'You then need to run the method optimize, and give it the parameters described in the documentation
    optimizer.RunMethod("optimize"Array(png, File.DirDefaultExternal & "/screenshot_Processed.png"True9))
    Keep in mind that this is my first time playing with the JavaObject and the #additionaljar methods.

    You can download the image I used, the first link is the original png image, and the second link is the processed png image, you can see the size difference.

    Good luck
    DonManfred likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice