Trouble writing pixel array back to gif file

Hi everyone. I am in the middle of constructing a steganography api for a final year group project. I have taken out the pixels into an array from a gif file. I am having trouble writing it back to a gif file. Here is my code:
import javaSteg.stegoLibrary.*;
import java.awt.*;
import java.awt.image.*;
import java.io.*;
import Acme.*;
import Acme.JPM.Encoders.*;
public class Gif extends Canvas{
     public void encodeGif(byte[] imageData){
          //create toolkit obarrayPointerect
          Toolkit t = Toolkit.getDefaultToolkit();
          MediaTracker tracker = new MediaTracker(this);
          //decode specified Gif cover
          Image img = t.createImage(imageData);      
          tracker.addImage(img,0);
          try{
               tracker.waitForAll();
          catch(InterruptedException e){
          System.out.println("Tracker interrupted.");
          //retrive picture from image
          int[] pix = new int[img.getWidth(this) * img.getHeight(this)];
          PixelGrabber pg = new PixelGrabber(img, 0, 0, img.getWidth(this), img.getHeight(this), pix, 0, img.getWidth(this));
          try{ pg.grabPixels();
          } catch (InterruptedException ioe) {
               System.err.println("Interrupted");
          if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
          System.err.println("image fetch aborted or errored");
          return;
          //put into byte array
          byte[] pixels = new byte[img.getWidth(this) * img.getHeight(this)];     
          for(int arrayPointer=0;arrayPointer<pix.length;arrayPointer++){
               pixels[arrayPointer] = new Integer(pix[arrayPointer]).byteValue();
          //edit pixels not implemented yet
//assign edited pixels to an image
          img = t.createImage(pixels);
          // Now encode the image using ACME free GIF encoder (www.acme.com)
          try{
               FileOutputStream fos = new FileOutputStream("D:\\result.gif");
               GifEncoder encoder = new GifEncoder(img, fos);
               encoder.encode();
               fos.close();
          }catch(IOException e) {
          System.out.println("FATAL IOException "+e);
From this i get a single pixel in my output gif file. Is there a way of swapping out the edited pixels with the origonal pixels in the image file? or an alternative way to write back the complete file.
Thanks a lot
MickyT

ive managed to solve it. For those who come across this thread and want to know the solution i needed to use MemoryImageSource with the pixels inorder to pass them to the createImage method :o)

Similar Messages

  • Only writing Integer pixel array to a .txt file,or showing in Frame

    Sir,
    I want to write integer values (range:0 to 255) to a .txt file .Actually after manipulating a .jpeg/.gif image I have gotten a 2D pixel array and a 1D pixel array that can be easily shown in console but I want to write this pixel array into a .txt file. Using of writeInt() is not working. Actually after using this faction the created file contain information which is non-alphanumeric /alphanumeric characters......
    following is error free the code: Plz. See only and only into the �class TestImage�and plz look after line marked by //�my_problem_to_be_resolved.�It is just few lines of code .I promise you will not be bothered.Plz��..
    import java.awt.*;
    import java.io.File;
    import java.io.FileWriter;
    import java.awt.image.*;
    import java.io.*;
    import java.util.*;
    import javax.imageio.*;
    import javax.imageio.stream.*;
    import java.awt.image.Raster;
    import java.awt.image.WritableRaster;
    class Image {
    protected int width,height;
    // 'samples' stores the image pixel values.
    protected int[][] samples;
    // Constructor: Reads the image from the
    // specified file name.
    public Image(String filename)
    throws Exception { read(filename); }
    // Returns the pixel width of the image.
    public int getWidth() { return width; }
    // Returns the pixel height of the image.
    public int getHeight() { return height; }
    // Reads the image from the specified file
    // name into the 'samples' array. Throws an
    // exception if the image is stored in an
    // unsupported file format (currently only
    // .GIF, .JPG, and .PNG are supported by Sun).
    public void read(String filename)
    throws Exception {
    // Extract the file name suffix.
    String ext = filename.substring
    (filename.indexOf('.')+1);
    // Create a file object for the file name.
    File fileImage = new File(filename);
    // Get a list of ImageReaders that claim
    // to be able to decode this image file
    // based on the file name suffix.
    Iterator imageReaders = ImageIO.
    getImageReadersBySuffix(ext);
    ImageReader imageReader;
    // Grab the first ImageReader in the list.
    if (imageReaders.hasNext())
    imageReader = (ImageReader)
    imageReaders.next();
    // If we get here we cannot decode the image.
    else throw new IIOException
    ("Unsupported image format");
    // Create a file input stream object to
    // read the image date.
    FileImageInputStream imageInputStream =
    new FileImageInputStream(fileImage);
    // Tell the ImageReader object to read data
    // from our file input stream object.
    imageReader.setInput(imageInputStream);
    // Get the width and height of the image.
    width = imageReader.getWidth(0);
    height = imageReader.getHeight(0);
    // Read the image from the file input stream,
    // and close the input stream when done.
    BufferedImage bufImage =
    imageReader.read(0);
    imageInputStream.close();
    // Get a raster object so we can extract the
    // pixel data from the BufferedImage.
    WritableRaster wRaster =
    bufImage.getRaster();
    // Create our 'samples' 2d-array.
    samples = new int[height][width];
    // Extract the image data into our 'samples'
    // array.
    for (int row = 0; row < height; row++)
    for (int col = 0; col < width; col++)
    samples[row][col] =
    wRaster.getSample(col,row,0);
    // Write the image stored in the 'samples'
    // array to the specified file. The file name
    // suffix should be a supported image file
    // format (currently either .JPG or .PNG).
    public void write(String filename)
    throws Exception {
    // Extract the file name suffix.
    String ext = filename.substring
    (filename.indexOf('.')+1);
    // Create a file object for the file name.
    File fileImage = new File(filename);
    // Get a list of ImageWriters that claim to
    // be able to encode images in the specified
    // image file format based on the file name
    // suffix.
    Iterator imageWriters = ImageIO.
    getImageWritersBySuffix(ext);
    ImageWriter imageWriter;
    // Grab the first ImageWriter in the list.
    if (imageWriters.hasNext())
    imageWriter = (ImageWriter)
    imageWriters.next();
    // If we get here we cannot encode the image.
    else throw new IIOException
    ("Unsupported image format");
    // Create a file output stream object to
    // write the image data.
    FileImageOutputStream imageOutputStream
    = new FileImageOutputStream
    (fileImage);
    // Tell the ImageWriter to use our file
    // output stream object.
    imageWriter.setOutput
    (imageOutputStream);
    // The ImageWriter.write() method expects a
    // BufferedImage. Convert our 'samples' array
    // into a BufferedImage.
    BufferedImage bufImage =
    createBufferedImage();
    // Encode the image to the output file.
    imageWriter.write(bufImage);
    imageOutputStream.close();
    // Draws the image stored in the 'samples'
    // array on the specified graphics context.
    public void draw(Graphics gc,int x,int y){
    BufferedImage bufImage =
    createBufferedImage();
    gc.drawImage(bufImage,x,y,null);
    // Converts the 'samples' array into a
    // BufferedImage object. Students do not have
    // to understand how this works.
    private BufferedImage
    createBufferedImage() {
    // Create a monochrome BufferedImage object.
    BufferedImage bufImage = new
    BufferedImage(width,height,
    BufferedImage.TYPE_BYTE_GRAY);
    // Create a WriteableRaster object so we can
    // put sample data into the BufferedImage
    // object's raster.
    WritableRaster wRaster =
    bufImage.getRaster();
    // Copy the 'samples' data into the
    // BufferedImage object's raster.
    for (int row = 0; row < height; row++)
    for (int col = 0; col < width; col++)
    wRaster.setSample
    (col,row,0,samples[row][col]);
    // Return the newly created BufferedImage.
    return bufImage;
    } // End of Class Image
    class TestImage {
    public static void main(String args[])
    throws Exception {
    // Create a frame to display the image.
    Frame frame = new Frame("Test Image");
    frame.setSize(1024,768);
    frame.setVisible(true);
    Graphics gc = frame.getGraphics();
    try {
    // Read the image from the file.
    Image img = new Image("C:/lilies.jpg");
    int height=img.getHeight();
    int width =img.getWidth();
    //�my_problem_to_be_resolved.�
         File image_object_arry=new File("C:/Image_array.txt");
         FileOutputStream image_object_arry_stream= new FileOutputStream(image_object_arry);
         DataOutputStream int_image_object_arry_stream=new DataOutputStream(image_object_arry_stream);
    //Conversion of two dimensional pixel arrry into one dimensional array
    int intPixels1[] = new int [height * width];
    int k = 0;
    for(int i = 0; i <= width; i++) {
    for(int j = 0; j <= height; j++) {
    intPixels1[k] = img.samples[i][j];
    int_image_object_arry_stream.writeInt((int) intPixels1[k]);
    // System.out.println(intPixels1[k]);
    k = k+1;
    import java.awt.*;
    import java.io.File;
    import java.io.FileWriter;
    import java.awt.image.*;
    import java.io.*;
    import java.util.*;
    import javax.imageio.*;
    import javax.imageio.stream.*;
    import java.awt.image.Raster;
    import java.awt.image.WritableRaster;
    class Image {
    protected int width,height;
    // 'samples' stores the image pixel values.
    protected int[][] samples;
    // Constructor: Reads the image from the
    // specified file name.
    public Image(String filename)
    throws Exception { read(filename); }
    // Returns the pixel width of the image.
    public int getWidth() { return width; }
    // Returns the pixel height of the image.
    public int getHeight() { return height; }
    // Reads the image from the specified file
    // name into the 'samples' array. Throws an
    // exception if the image is stored in an
    // unsupported file format (currently only
    // .GIF, .JPG, and .PNG are supported by Sun).
    public void read(String filename)
    throws Exception {
    // Extract the file name suffix.
    String ext = filename.substring
    (filename.indexOf('.')+1);
    // Create a file object for the file name.
    File fileImage = new File(filename);
    // Get a list of ImageReaders that claim
    // to be able to decode this image file
    // based on the file name suffix.
    Iterator imageReaders = ImageIO.
    getImageReadersBySuffix(ext);
    ImageReader imageReader;
    // Grab the first ImageReader in the list.
    if (imageReaders.hasNext())
    imageReader = (ImageReader)
    imageReaders.next();
    // If we get here we cannot decode the image.
    else throw new IIOException
    ("Unsupported image format");
    // Create a file input stream object to
    // read the image date.
    FileImageInputStream imageInputStream =
    new FileImageInputStream(fileImage);
    // Tell the ImageReader object to read data
    // from our file input stream object.
    imageReader.setInput(imageInputStream);
    // Get the width and height of the image.
    width = imageReader.getWidth(0);
    height = imageReader.getHeight(0);
    // Read the image from the file input stream,
    // and close the input stream when done.
    BufferedImage bufImage =
    imageReader.read(0);
    imageInputStream.close();
    // Get a raster object so we can extract the
    // pixel data from the BufferedImage.
    WritableRaster wRaster =
    bufImage.getRaster();
    // Create our 'samples' 2d-array.
    samples = new int[height][width];
    // Extract the image data into our 'samples'
    // array.
    for (int row = 0; row < height; row++)
    for (int col = 0; col < width; col++)
    samples[row][col] =
    wRaster.getSample(col,row,0);
    // Write the image stored in the 'samples'
    // array to the specified file. The file name
    // suffix should be a supported image file
    // format (currently either .JPG or .PNG).
    public void write(String filename)
    throws Exception {
    // Extract the file name suffix.
    String ext = filename.substring
    (filename.indexOf('.')+1);
    // Create a file object for the file name.
    File fileImage = new File(filename);
    // Get a list of ImageWriters that claim to
    // be able to encode images in the specified
    // image file format based on the file name
    // suffix.
    Iterator imageWriters = ImageIO.
    getImageWritersBySuffix(ext);
    ImageWriter imageWriter;
    // Grab the first ImageWriter in the list.
    if (imageWriters.hasNext())
    imageWriter = (ImageWriter)
    imageWriters.next();
    // If we get here we cannot encode the image.
    else throw new IIOException
    ("Unsupported image format");
    // Create a file output stream object to
    // write the image data.
    FileImageOutputStream imageOutputStream
    = new FileImageOutputStream
    (fileImage);
    // Tell the ImageWriter to use our file
    // output stream object.
    imageWriter.setOutput
    (imageOutputStream);
    // The ImageWriter.write() method expects a
    // BufferedImage. Convert our 'samples' array
    // into a BufferedImage.
    BufferedImage bufImage =
    createBufferedImage();
    // Encode the image to the output file.
    imageWriter.write(bufImage);
    imageOutputStream.close();
    // Draws the image stored in the 'samples'
    // array on the specified graphics context.
    public void draw(Graphics gc,int x,int y){
    BufferedImage bufImage =
    createBufferedImage();
    gc.drawImage(bufImage,x,y,null);
    // Converts the 'samples' array into a
    // BufferedImage object. Students do not have
    // to understand how this works.
    private BufferedImage
    createBufferedImage() {
    // Create a monochrome BufferedImage object.
    BufferedImage bufImage = new
    BufferedImage(width,height,
    BufferedImage.TYPE_BYTE_GRAY);
    // Create a WriteableRaster object so we can
    // put sample data into the BufferedImage
    // object's raster.
    WritableRaster wRaster =
    bufImage.getRaster();
    // Copy the 'samples' data into the
    // BufferedImage object's raster.
    for (int row = 0; row < height; row++)
    for (int col = 0; col < width; col++)
    wRaster.setSample
    (col,row,0,samples[row][col]);
    // Return the newly created BufferedImage.
    return bufImage;
    } // End of Class Image
    /*class TestImage {
    public static void main(String args[])
    throws Exception {
    // Create a frame to display the image.
    Frame frame = new Frame("Test Image");
    frame.setSize(1024,768);
    frame.setVisible(true);
    Graphics gc = frame.getGraphics();
    try {
    // Read the image from the file.
    Image img = new Image("C:/srk.jpg");
    // Display the image.
    img.draw(gc,10,40);
    // Flip the image upside down
    //img.flipX();
    // Display the flipped image.
    img.draw(gc,20+img.getWidth(),40);
    // Write the new image to a file
    img.write("HorseNew.jpg");
    } catch (Exception e) {
    System.out.println
    ("Exception in main() "+e.toString());
    class TestImage {
    public static void main(String args[])
    throws Exception {
    // Create a frame to display the image.
    Frame frame = new Frame("Test Image");
    frame.setSize(1024,768);
    frame.setVisible(true);
    Graphics gc = frame.getGraphics();
    try {
    // Read the image from the file.
    Image img = new Image("C:/lilies.jpg");
    int height=img.getHeight();
    int width =img.getWidth();
    File image_object_arry=new File("C:/Image_array.txt");
    FileOutputStream image_object_arry_stream=new FileOutputStream(image_object_arry);
         DataOutputStream int_image_object_arry_stream=new DataOutputStream(image_object_arry_stream);
    //Conversion of two dimensional pixel arrry into one dimensional array
    int intPixels1[] = new int [height * width];
    int k = 0;
    for(int i = 0; i <= width; i++) {
    for(int j = 0; j <= height; j++) {
    intPixels1[k] = img.samples[i][j];
    int_image_object_arry_stream.writeInt((int) intPixels1[k]);
    // System.out.println(intPixels1[k]);
    k = k+1;
    catch (Exception e) {
    System.out.println("Exception in main() "+e.toString());
    catch (Exception e) {
    System.out.println("Exception in main() "+e.toString());
    }

    My Friend, you need to put your code within CODE tags
    And I suspect if anyone would go through your code this way.
    Assuming your problem is to write pixel values to a file you may use this,
          try{
            // Create file
            FileWriter fstream = new FileWriter("out.txt");
            BufferedWriter out = new BufferedWriter(fstream);
            for(int i =0; pixels.length() ; i++)
              out.write(pixels[i]+"\t");
           //Close the output stream
           out.close();
           }catch (Exception e){//Catch exception if any
          System.err.println("Error: " + e.getMessage());
        }

  • How to find out image size (in pixels) of jpg and gif files

    this seems to work, though i doubt that it would very time:
                   Image img = Toolkit.getDefaultToolkit().getImage("car.jpg");
                   int w = img.getWidth(null);
                   int h = img.getHeight(null);
                   while(w <= 0 || h <= 0)
                      try{Thread.sleep(10);}catch(InterruptedException ix){}
                      w = img.getWidth(null);
                      h = img.getHeight(null);
                   JOptionPane.showMessageDialog
                      null,
                      filenames[i] + ": " + w + "x" + h,
                      "ImgSize",
                      JOptionPane.INFORMATION_MESSAGE
                   );please suggest a better solution.
    thanks

    >
    We've a requirement that we need to find out the size of a java object at run time, is there a direct java API to get the size of a composite object in memory?
    Here is my requirement: We are adding string objects (which is an xml string of considerable size) into a List. After reaching certain size limit (lets say 5MB) of the list i need to put this data into DB as a CLOB. So every time I add a string object to the list, I need to see if the total size of the list exceeds the limit and if yes, flush the results into DB.
    I am not sure if java has a direct API for this, if not what is the beast way to do it, it s critical requirement for us.
    It would be really great if someone could help us out.
    >
    Could you explain your actual requirement a little more fully.
    1. Is each individual string a separate XML string? Or is it just a fragment? Why would you just concatenate them together into a CLOB? That won't produce valid XML and it won't let you easily separate the pieces again later. So provide a simple example showing some strings and how you need to manipulate them.
    2. Are you using these xml strings in Java at all? Or are you just loading them into the database?
    For example if you are just loading them into the database you don't need to create a list. Just create a CLOB in Java and append each string to the CLOB. Before you append each one you can check to see if the new string will put you over your length limit. If it will then you write the CLOB to the database, empty the CLOB and start appending again to the new clob instance.
    If you explain what you are really trying to do we might be able to suggest some better ways to do it.

  • Trouble writing large Quicktime file to DVD

    I'm having trouble writing a large (2.4G) Quicktime mov. file to DVD. If I burn it as a video it comes out fine, but when I try to write it as a file the end product is jerky and staggered and can't be easily transferred to another computer. I'm wondering if it has anything to do with the size of the file and if there is another way of transferring this file uncompressed, short of carrying my hard drive across town.

    The trouble is caused by the speed (data rate) that can be achieved when playing from DVD media via QuickTime Player.
    If you burn the DVD as a "data file" you should then copy it (temporarily) to the HD of the viewing machine. Drag the file from the DVD to the Desktop on the viewing machine and then open it with a double click.
    When you "burn" it as DVD media you are actually converting the file to MPEG-2 format and the DVD Player can handle these lower data rates.
    Does this make sense to you?

  • Trouble Writing Large Files to Time Capsule - Windows 7

    Hi
    I'm having some trouble with my Time Capsule. I can access it and read files from it fine. However, I have trouble writing files to it. Small files ( say multiple word docs) write fine. However, with medium size files (say 120 mb) it crashes. I have noticed that no matter how large the file is, it writes up to 10% of the file very quickly but then crashes. It fails with the error message that 'the network location specified is no longer available'. Sometimes, when it crashes, it essentially crashes my Time Capsule network. I.E I am still connected to the internet but I can access the Time Capsule.
    I used to be able to write files (when I was using Vista) no problem. I still have 250gb left.
    What can I do to fix this?
    For details:
    500gb Time Capsule
    Windows 7 64bit Home Premium

    anyone know how to help?

  • GIF file shows up fuzzy and pixelated on Dreamweaver

    I am trying to load a GIF file in Dreamweaver. I am saving it on Photoshop as an Unnamed GIF file with no dither, no transparency, and 128 colors. When I load the file onto Dreamweaver, it shows up fuzzy and pixelated. I know I am not stretching the image in dreamweaver, and I have saved the file as a PNG also and I get the same result. I think I am saving the file the wrong way but I am not sure what to do. I have an example of what the logo looks like on Dreamweaver.  Any suggestions?

    Image attachments tend to get lost in the Adobe queue forever.  Best to show us a URL to your page and image so we can look at the properties.  Or use the camera icon to insert your web image directly into your message.
    Dreamweaver rendering isn't what counts.  It's how your image looks in the major browsers.
    Did you convert CMYK to RGB?  Browsers don't support CMYK. Possibly gif isn't the right file type for your image.  Did you try saving for web as an optimized jpg?
    Nancy O.
    Alt-Web Design & Publishing
    Web | Graphics | Print | Media  Specialists
    www.alt-web.com/
    www.twitter.com/altweb

  • Writing multiple arrays to a single xml file at seperate times without overwriting the previous file?

    Hi my name is Dustin,
    I am new to labview and teststand... I am trying to right multiple arrays of data to a single xml file. I can do this with a cluster but I have to create a variable for each of those arrays (21 arrays) and I was hoping to use the same variable for each array. Meaning I obtain my array of data write it to an xml file then replace that array in that variable with a new array and then call up my VI that writes that array to an xml file and write it to the same xml file underneath the first array without overwriting it. Attached is my VI I created to write an array to an xml file. Again I am wondering if there is a way to write multiple arrays to a single xml file at different times without overwriting the previous xml file.
    Thanks
    Solved!
    Go to Solution.
    Attachments:
    Write_to_XML_File.vi ‏11 KB

    Hi dlovell,
    Check the attached example. I think it may help you.
    Regards,
    Nitz
    (Give Kudos to Good Answers, Mark it as a Solution if your problem is Solved) 
    Attachments:
    Write to XML.vi ‏17 KB

  • Camera Raw Policy of Writing Back into Input Files

    This came up in another thread, and I think it deserves its own discussion.  I'd hope that we can influence the Camera Raw team's future direction.  I welcome your input and opinions.
    Given:  Under some conditions Camera Raw writes data back into (overwrites) its input files.
    Assuming you use Camera Raw to open your out-of-camera original files as many of us do, Adobe seems to be all over the road on whether to keep its hands off them or overwrite them...
    Camera Raw will not touch a proprietary raw file, such as a Canon .CR2 or Nikon .NEF.  There's a whole process for remembering settings in a separate database or sidecar XMP files.  So far so good.
    If you open a JPEG, TIFF, or DNG through Camera Raw, data WILL automatically be written back into it to tell another run of Camera Raw in the future what settings you used - without the software ever having warned you it will do so.
    Some functions EXPLICITLY rewrite input files.  You can ask the software to write new thumbnails back into DNG files, for example.   This is fine - the user has instructed the software to overwrite the file, and the user is in charge, after all.
    Overwriting/rewriting an input file without being instructed to do so is NON-INTUITIVE BEHAVIOR for an application. No one would expect an input file to be overwritten.
    We do see that it causes people confusion.  I'm sure there are people right now reading this in disbelief.  I recommend you go test it for yourself (on a copy of one of your original files).
    The original file being overwritten is one of the reasons why I don't configure Photoshop to open my out-of-camera JPEGs through Camera Raw.
    Adobe's [mis]handling of input files on the surface seems to be derived from the history of DNG - where no camera actually writes the DNG file directly but it has been generated as an intermediate format through the DNG Converter, and as such can be handled with less "care" than an original camera file.
    It seems to me that Camera Raw should NEVER write back into an INPUT file it is opening without a) letting the user know or b) being directed to do so.
    Adobe:
    Please give those of us who don't want our input files overwritten an option for using the database/XMP sidecar instead in EVERY case.
    Thanks.
    -Noel

    Noel wrote: >>  If you open a JPEG, TIFF, or DNG through Camera Raw, data WILL automatically be written back into it to tell another run of Camera Raw in the future what settings you used - without the software ever having warned you it will do so.<<
    It depends.
    As far as I can tell:
    When a JPG or TIF file is Locked,
    Camera Raw > Done results in a Write Permission Error.
    When a DNG file is Locked,
    Camera Raw > Done - writes a separate xmp sidecar file.
    The JPG / TIF handling seems to me inconsistent. With a locked file I'd prefer to have a sidecar xmp created as well. Some of my JPG / TIF files are originals for me.
    Peter
    Windows Vista, CS4 w/ACR 5.7

  • Troubles writing a string of numbers in binary mode to a file.

    Hi,
    I have a string stringRW = "1234567890". I want to write this numbers to a binary file. For that, I am doing this:
    fileDestiny = new File(arquivo);
    o = new FileOutputStream(fileDestiny);
    out = new BufferedOutputStream(o);
            int i = 0;
            int x;
            while ((x = stringRW.codePointAt(i)) != -1) {
                try {
                    out.write(x); // Copia o arquivo.
                    System.out.println("byte = "  +x);+
    +            } catch (IOException ex) {+
    +                Logger.getLogger(ArquivoEscreverBin.class.getName()).log(Level.SEVERE, null, ex);+
    +            }+
    +            i++;
    out.close();Actualy, I am getting some Exception:
    Exception in thread "Thread-3" java.lang.StringIndexOutOfBoundsException: String index out of range: 11
            at java.lang.String.codePointAt(String.java:715)
            at jserialrwxn.ArquivoEscreverBin.write(ArquivoEscreverBin.java:46)
            at jserialrwxn.NewSerialX.setDados(NewSerialX.java:890)
            at jserialrwxn.SerialComRW.serialEvent(SerialComRW.java:276)
            at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732)
            at gnu.io.RXTXPort.eventLoop(Native Method)
            at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575)But the problem in fact, is that the generated file is not a binary file. For check if the generated file is or not binary, I do open it in Notepad. When I do open the generated file with Notepad I can read it normaly and see the numbers 1234567890.
    Some one have some guess on how I need to proceed?
    Edited by: cstrieder on Aug 5, 2009 1:15 PM

    cstrieder wrote:
    Hi,
    I have a string stringRW = "1234567890". I want to write this numbers to a binary file. For that, I am doing this:Are you saying that you want to write the individual characters of your string to a file? Or are you saying that you want to write the integer values from your string to a file? I.e., do you want to write the number "1" as a character or do you want to write the value 1 to a file?
    >
    fileDestiny = new File(arquivo);
    o = new FileOutputStream(fileDestiny);
    out = new BufferedOutputStream(o);
            int i = 0;
    int x;
    while ((x = stringRW.codePointAt(i)) != -1) {
    try {
    out.write(x); // Copia o arquivo.
    System.out.println("byte = "  +x);+
    +            } catch (IOException ex) {+
    +                Logger.getLogger(ArquivoEscreverBin.class.getName()).log(Level.SEVERE, null, ex);+
    +            }+
    +            i++;
    out.close();Actualy, I am getting some Exception:
    Exception in thread "Thread-3" java.lang.StringIndexOutOfBoundsException: String index out of range: 11
    at java.lang.String.codePointAt(String.java:715)
    at jserialrwxn.ArquivoEscreverBin.write(ArquivoEscreverBin.java:46)
    at jserialrwxn.NewSerialX.setDados(NewSerialX.java:890)
    at jserialrwxn.SerialComRW.serialEvent(SerialComRW.java:276)
    at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732)
    at gnu.io.RXTXPort.eventLoop(Native Method)
    at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575)
    Your exception is telling you exactly what the problem is. Your index is beyond the length of your string. Instead of using a while loop to iterate over the String, try using a for-loop instead. i.e.
    for(int i = 0; i < myString.length(); i++) {
      // blah blah blah
    But the problem in fact, is that the generated file is not a binary file.Every file is a binary file. What you're doing is writing the character value to the file. Instead of that, you may want to try parsing your character value into an integer and then writing that value.
    For check if the generated file is or not binary, I do open it in Notepad.That's not an appropriate method for determining the byte values written to your file(s). Use a hex editor instead.
    When I do open the generated file with Notepad I can read it normaly and see the numbers 1234567890.Again, that's because you're writing the character values, not the integer values.

  • Saving an integer array into a .txt file

    hii, im only a beginner in java, so this is the only code i've learned so far for saving array elements into a file
         public static void saveNames(String [] name) throws IOException
                   FileWriter file = new FileWriter("Example\\names.txt");
                   BufferedWriter out = new BufferedWriter(file);
                   int i = 0;
                   while (i < name.length)
                             if (name[i] != null)
                                  out.write(name);
                                  out.newLine();
                                  i++;
                   out.flush();
                   out.close();
    However, this is only used for string arrays; and i can't call the same method for an integer array (because it's not compatible with null)
    I don't really understand this code either... since my teacher actually just gave us the code to use, and didn't really explain how it works
    I have the same problem for my reading a file code as well --> it's only compatible with string
         public static String [] readNames (String [] name) throws IOException
              int x = 0;
              int counter = 0;
              String temp = "asdf";
              name = new String [100];
              FileReader file = new FileReader("Example\\names.txt");
              BufferedReader in = new BufferedReader(file);
              int i = 0;
              while (i < array.length && temp != null)                    // while the end of file is not reached
                   temp = in.readLine();
                   if (temp != null)
                        name[i] = temp;                    // saves temp into the array
                   else
                        name[i] = "";
                   i++;
              in.close();                                   // close the file
              return name;
    Could someone suggest a way to save elements from an integer array to a file, and read integer elements of that file?
    Or if it's possible, replace null with a similar variable (function?), that is suitable for the integer array (i can't use temp != 0 because some of my elements might be 0)
    Thanks so much!!!!!

    because it's not compatible with nullI think it should be okay to just remove the null condition check since there are no null elements in a primitive array when writing.
    Use Integer.parseInt() [http://java.sun.com/javase/6/docs/api/java/lang/Integer.html] to convert the String into an Integer when you read it back and use Integer.toString() to be able to write it as a String.

  • Edited gif file will work in a viewer, but not in email client

    An animated gif file received in my email client, after editing will not work in the same email client, but is working properly in a browser. Further, the background in the altered gif is black in the email client instead of the non-pixelated file that was "saved for web."
    I had received thsi working gif file and made changes to send the altered animation back, wherin I encountered this quirky littel issue.
    Anyone had this problem or have answers to what's going on here?

    Hi Ozkarleo,
    Please post more information to make your question clear. What’s the type of project you are using? Universal app? Windows phone silverlight app?
    The Sqlite libraries in runtime project are different with those in WinForm. But you have not mentioned what libraries you are using in runtime, so I assume you are using this common ones.
    Sqlite for windows 8.1
    https://visualstudiogallery.msdn.microsoft.com/1d04f82f-2fe9-4727-a2f9-a2db127ddc9a.
    Sqlite for windows phone 8.1
    https://visualstudiogallery.msdn.microsoft.com/5d97faf6-39e3-4048-a0bc-adde2af75d1b.
    One thing important you need note is that we have no access to the entire file system in runtime app, copy the file to local storage then use it.
    A good sample you can get started with it. Get it form MSDN code gallery.
    https://code.msdn.microsoft.com/windowsapps/Using-SQLite-in-a-Windows-c16aea77 .
    If you cannot make it working, please post more information about your scenario.
    Regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate
    the survey.

  • ImageIO.write not working for GIF files

    Hi, I downloaded the JAI Image IO tools which contains a class called
    com/sun/media/imageioimpl/plugins/gif/GIFImageWriter
    I am able to save png files using just the ImageIO apis and without the JAI.
    But for GIF images, I read in the forum that the JAI has a writer. Though
    the JAI documentation doesn't explicitly mention support for GIF writing,
    seeing this class in jai_imageio.jar, I thought I could write the GIF files.

    I had to create a BufferedImage with IndexColorModel
    to be able to save it as a GIF file.
    Then it worked. However, I still seem to have a
    problem with the saved image. I opened
    a GIF file and saved it back and I see that the color
    pallette has completely changed.As you know GIF format supports only up to 256 colors. That's why any good GIF encoder should contain a Java Color Quantizer to reduce the number on unique colors. The best solution I've found is the Gif4J PRO (http://www.gif4j.com/java-gif-imaging-gif4j-pro-library.htm). This library very fast and powerful and contains the fastest, most intelligent and qualitative Java color quantizer (http://www.gif4j.com/java-color-quantizer.htm).
    Regards

  • GIF file import

    A have a problem correctly interpreting GIF file characters from an instrument. Any ideas on correctly interpreting a GIF file from an instrument. I'm stuck with the format, its what the instrument supports.
    It appears that MS Windows platform, labview text control interpretation of GIF characters, like \s, \0, \FF, is different from the Agilent E4404B Spec An. I have no problem fetching the file, but characters are being changed (interpreted) whenever I use a labview text box (i.e. an ascii string control, I really need a character control, or some work around).
    Attached is a good GIF from the instrument and the bad imported GIF.
    Solved!
    Go to Solution.
    Attachments:
    bad.GIF ‏16 KB
    00191RMT.GIF ‏16 KB

    Unless I am missing something here, the issue is not with the GIF files per se.  What is happening is that somewhere along the lines the file is being interpreted as text and the nulls (x00) are being replaced with spaces (x20).  You can recreate this by taking the good GIF file, changing the extension to .txt, opening in Notepad, saving, then renaming back to GIF.  You will see that it is no longer a valid GIF and if you examine the file in LV or a hex editor you will see all of the spaces.
    LV does not do this, it may cause trouble if you read a binary file as txt with the convert EOL option selected, but that is about it.  Something happens to the file along the way from the instrument to LV.  That is why I am curious to know how he fetches the file from the analyzer and gets it into LV.

  • Animated .gif files

    I have been using an older version of Photoshop Elements for a long time but just got a new MacPro and decided it's time to upgrade my PSE.  But maybe not....I downloaded the Photoshop Elements Trial version to check out if it's really worth upgrading or not and I think I'm in trouble. I have a ton of animated .gif files and they do not appear to open in the familiar "layers".  i read through some of these discussion threads and I think you're saying that if I use the current version of Photoshop Elements I will not be able to edit my old .gif files.  I did try making new layered files and save them for the web with animation and that seemed to work.  But if I'm going to lose the ability to edit my old .gif files I'm not sure I want to upgrade.
    Can someone clarify this for me please.  Maybe it's just a matter of switching from Elements to CS4, but I thought from the descriptions of the programs as provided in the Products section that I fit more with the Elements program.....maybe not???? 
    And this does not even consider that I haven't tried to load my older version on the new intel machine yet, it may not even run if I try that.
    I do, for about 20% of my computing time use "that other" platform, but I don't like it, I much prefer my wonderful Mac machines.
    thanks for your help
    Leigh

    Thank you for your offer, I do appreciae it.  But I think the better question to ask at this point is :  What is the last version of Photoshop Elements that supports editing animated gif files.  This is too important to me to lose this ability and after checking further I see CS4 is out of my price and needed features range. I would rather hang on to my old laptop to manipulate photos than lose the ability to edit my .gif files.
    Can anybody help with this question?

  • Switching back to delete file from PC?

    I recently selected a few files that I wanted to remove from iTunes, but didn't want to delete from my hard drive.
    Now I want to switch back and delete files from my hard drive, but when I select a track and click 'delete' it doesn't give me the choice of deleting from iTunes or from hard drive.
    How do I get the option to delete from my hard drive back?

    Kappy wrote:
    Language barrier, it would seem?
    thank you guys (= Kappy , Hawaiian_Starman ) for welcoming me with my first post !!!!!!!!!
    ..... and i was writing fast after installing safari 3 without paying good attention while typing as if i was chatting .... i excuse , next time i'll do.
    Message was edited by: ahmad seleem
    Message was edited by: ahmad seleem

Maybe you are looking for