Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Encode PNG

  1. #1
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    897
    Thanks
    0
    Thanked 166 Times in 148 Posts

    Default Encode PNG

    Hi there.
    I get image data from an application and I need to find a way to save this image data as a png on the hard drive.
    The image data I get comes in this format:
    int width
    int height
    float[] rgba // 4 floats from this array form a pixel. The lines are filled from left to right from top to bottom.
    rgba.length == width * height * 4

    I get this data from an OpenGL texture.
    I googled for a png encoder on the net but all that I found take Image objects as input.
    So I figured I need some kind of wrapper for this data, but the Image interface has a lot of methods which I dont really want to implement since most of them are not needed for me.

    Are their any suggestions what I should do? I was thinking about using a BufferedImage and fill the pixels, but if possible I would like to keep it simple and efficient.

    Thank you very much.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,372
    Thanks
    183
    Thanked 836 Times in 779 Posts
    Blog Entries
    5

    Default Re: Encode PNG

    See BufferedImage (Java Platform SE 7 ) and Lesson: Working with Images (The Java™ Tutorials > 2D Graphics) , idea would be to create a BufferedImage object, draw to it with your pixels, then save using ImageIO class methods.

  3. #3
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    897
    Thanks
    0
    Thanked 166 Times in 148 Posts

    Default Re: Encode PNG

    So I will not get around creating a BufferedImage as it seems. Oh well, thank you for the clarification.

Similar Threads

  1. Replies: 7
    Last Post: June 6th, 2012, 04:16 PM
  2. [SOLVED] Help reading a file to decode or encode
    By mickey2012 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 29th, 2012, 10:46 PM
  3. encode a png image in ascii format..
    By entwicklerin in forum File I/O & Other I/O Streams
    Replies: 9
    Last Post: January 16th, 2012, 10:17 AM
  4. Encode and decode - Caesar cipher
    By siabanie in forum Java Theory & Questions
    Replies: 1
    Last Post: October 7th, 2011, 07:25 PM
  5. Display Image (png)
    By vimalaranjan in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 3rd, 2011, 07:44 PM