Reading an image in byte form

hii guys
i m trying to read an image and convert it to byte array and later to do some change in that byte array and later recreate a new image.
For that i m using FileInputStream and FileOutputStream and its read and write methods
but now i dont know how to append that byte and recreate that image.
actually i want to do that , convert the image in byte array form and replacing some bytes of the image by my text msg bytes and recreate a new image.
how an i do that.
plz help me.
its urgent.

import java.io.*;
class image
public static void main(String[] arg) throws IOException
String msg;
int len,i;
FileInputStream fin;
FileOutputStream fout;
try
try
fin=new FileInputStream("01.jpg");
catch( Exception e)
System.out.println("Input image not found");
return;
try
fout=new FileOutputStream("001.jpg");
catch( Exception e)
System.out.println("output image cannt be created");
return;
catch(Exception e)
System.out.println("output image cannt be created");
return;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the secret msg :: ");
msg=br.readLine();
byte[] msg1=msg.getBytes();
len=msg1.length;
System.out.println(len);
for(i=0;i<len;i++)
System.out.println(msg1);
try
do
byte by=(byte)fin.read();
//System.out.print(" "+by);
if(fin.available()>0)
fout.write(by);
}while(fin.available()>0);
catch(Exception e)
System.out.println("File error");
fin.close();
fout.close();
till now i only imputed the sg , change it into byte form .
now i want to replace the msg bytes into the image byte as :- 1 image byte ,1 msg byte, 1 image byte , 1 msg byte........ so on
until the msg bytes are not finished.

Similar Messages

  • Get Image's bytes

    Hi people,
    I'm trying to get the bytes from an image. I know the complete path to that image, and I know the image's name also, so I pass the image's whole name as a String to a method wich will read the bytes. When I try to read the image's bytes I get the following meassures: width = -1, height = 0.
    This is the code I use:
      int err = imageReturn(path + "/" + img);
      byte[] b2bytes = b2.toByteArray();
    public int imageReturn(String imagePath){
        //path is c:\javi\image.jpg
        try{
            int w,h;
            Image img = null;
            img = Toolkit.getDefaultToolkit().getImage(imagePath);
            w = img.getWidth(null);
            h = img.getHeight(null);
    System.out.println("image size: " + w + "x" + h); //--> print's -1x0!!!
            BufferedImage finalImage = new BufferedImage(w, h, 
                                                BufferedImage.TYPE_INT_RGB);
            finalImage.createGraphics().drawImage(img, 0, 0, null);
            b2 = new ByteArrayOutputStream(); //global
            JPEGImageEncoder encoder=JPEGCodec.createJPEGEncoder(b2);
            JPEGEncodeParam param=encoder.getDefaultJPEGEncodeParam
                                                               (finalImage);
            param.setQuality(1.0f, false);
            encoder.setJPEGEncodeParam(param);
            encoder.encode(finalImage);
            b2.close();
            return(0);
        }catch(Exception e){
            System.out.println(e.toString());
            return(-1);
    }//imageReturnAs you see, the goal is to get a byte[] with the image information. I don't know if there's any other way (simpler one) to solve it. Any help will be appreciated.
    Thanks all,
    Javi

    The problem really is withe the Image class, which was never intended for this sort of thing. If you use the ImageIO classes, you can get BufferedImages direct from jpg files, and then you have access to the underlying buffers:
    import java.io.*;
    import javax.imageio.*;
    import java.awt.image.*;
    public class FileOperations
        public static BufferedImage readImageFromFile(File file) throws IOException
            return ImageIO.read(file);
        public static void writeImageToFile(File file,BufferedImage bufferedImage) throws IOException
            ImageIO.write(bufferedImage,"JPG",file);
    }

  • I'VE CREATED A FORM WITH IMAGES. WHEN I OPEN THE FILE IN ACROBAT READER, THE IMAGES ARE BALCK BOXES!

    I'VE CREATED A FORM WITH IMAGES. WHEN I OPEN THE FILE IN ACROBAT READER THE IMAGES ARE BLACK BOXES.
    THE FORM HAs (extend features to acrobat reader). THE FORM WAS DISTRIBUTED.
    NON OF MY EMPOYEES CAN SEE THE IMAGES. WHAT'S WRONG? CAN YOU HELP?

    However, the view large images is an issue for a form that is being distributed. Either a note needs to be added to the PDF to tell how to enable the view or the images need to be changed so that the enabling is not needed.

  • How can I read the image from database into form

    hi everyone
    if I have table like this
    create table test
    (id number(10),
    pic long raw);
    in this table record
    in form If I have block non database
    how can i read the image into non database item
    I try with this code but no good
    select pic into :photo from test where id=5;
    photo its non database item kind image
    how can i invoke image into item
    thanks alooooooot

    Hello,
    You can't select image with select query. You need to create another database block from test table which has item binds with database pic column. Now in where condition in test block's property you have to write id=5. Change test block's properties UPDATE ALLOWED, INSERT ALLOWED, DELETE ALLOWED to NO. Only Query allowed property set to YES.
    Now in your particular trigger write the code
    GO_BLOCK('test');
    Execute_Query;
    please mark if it help you or correct
    Regards,
    Danish

  • Reading an image from Database & displaying it in forms

    Hello
    My problem is that i want to add an image to my forms which is actually
    stored in the database.
    How can I do that??? I have tried using lob package , but don't know how to use it in forms. If anyone knows , how then please reply in detail.
    Thank You
    Marium

    Base a Block on the table with the Lob in it - make the lob column an image item and execute_query.
    You cannot use PL/SQL or SQL to directly pull the image in - you have to use the default query capabilities of the block

  • How to read a pdf image or Extract image from pdf form

    Hi
    I have to read an image from the pdf file. The requirement is to an image in the pdf file having some data i have to extract that data from pdf . Please help if you have some idea how to approach.
    Thanks in Advance

    Hi
    Is there any sample program for using the APIS ?
    ThanksYes, each of the websites for each of the APIs have tutorials and/or example applications.

  • Thumbnail images, mysql, byte[ ]  - need some help

    I'm using the tech tip found on sun's site for "Creating Image Thumbnails" at http://java.sun.com/developer/TechTips/1999/tt1021.html#tip1
    I've looked over the code, and now I'm trying to mesh some of the code from that example with the code for my servlet program.
    My servlet takes a jpeg image submitted from an html form on a web page (all of which I'm testing on my localhost Tomcat server) and uploads it into my mysql database into a column of type BLOB. I do not upload a reference to a FILE, rather, I upload the BYTES that make up that image.
    I wanted to make the images into a thumbnail size PRIOR to uploading them into the db.
    My code snippet for my servlet that just uploads the file without modifying its size is:
    boolean isPart = FileUpload.isMultipartContent(req);
         if(isPart)
    DiskFileUpload upload = new DiskFileUpload(); // upload a file from the local disk.
    List items = upload.parseRequest(req); // Create a list of all uploaded files.
         Iterator it = items.iterator(); // Create an iterator to iterate through the list.
              while(it.hasNext())
         FileItem item = (FileItem)it.next();
         File f = new File(item1.getName()); // Create a FileItem object to access the file.
    byte[] bytes = new byte[(int)f.length()];
         FileInputStream fs = new FileInputStream(f);
         BufferedInputStream bis = new BufferedInputStream(fs);
         bis.read(bytes);
    PreparedStatement stmt = conn.prepareStatement("UPDATE car SET Image1 = ? where Account=1");
         stmt.setBytes(1, bytes);
         int i = stmt1.executeUpdate();
    Here is the code from the Tech Tip:
    import java.awt.Image;
    import java.awt.Graphics2D;
    import java.awt.geom.AffineTransform;
    import java.awt.image.BufferedImage;
    import java.io.IOException;
    import java.io.OutputStream;
    import java.io.FileOutputStream;
    import javax.swing.ImageIcon;
    import com.sun.image.codec.jpeg.JPEGCodec;
    import com.sun.image.codec.jpeg.JPEGImageEncoder;
    class Thumbnail {
    public static void main(String[] args) {
    createThumbnail(args[0], args[
    1], Integer.parseInt(args[2]));
    * Reads an image in a file and creates
    * a thumbnail in another file.
    * @param orig The name of image file.
    * @param thumb The name of thumbnail file.
    * Will be created if necessary.
    * @param maxDim The width and height of
    * the thumbnail must
    * be maxDim pixels or less.
    public static void createThumbnail(
    String orig, String thumb, int maxDim) {
    try {
    // Get the image from a file.
    Image inImage = new ImageIcon(
    orig).getImage();
    // Determine the scale.
         double scale = (double)maxDim/(
         double)inImage.getHeight(null);
    if (inImage.getWidth(
    null) > inImage.getHeight(null)) {
    scale = (double)maxDim/(
    double)inImage.getWidth(null);
    // Determine size of new image.
    //One of them
    // should equal maxDim.
    int scaledW = (int)(
    scale*inImage.getWidth(null));
    int scaledH = (int)(
    scale*inImage.getHeight(null));
    // Create an image buffer in
    //which to paint on.
    BufferedImage outImage =
    new BufferedImage(scaledW, scaledH,
    BufferedImage.TYPE_INT_RGB);
    // Set the scale.
    AffineTransform tx =
    new AffineTransform();
    // If the image is smaller than
    //the desired image size,
    // don't bother scaling.
    if (scale < 1.0d) {
    tx.scale(scale, scale);
    // Paint image.
    Graphics2D g2d =
    outImage.createGraphics();
    g2d.drawImage(inImage, tx, null);
    g2d.dispose();
    // JPEG-encode the image
    //and write to file.
    OutputStream os =
    new FileOutputStream(thumb);
    JPEGImageEncoder encoder =
    JPEGCodec.createJPEGEncoder(os);
    encoder.encode(outImage);
    os.close();
    } catch (IOException e) {
    e.printStackTrace();
    System.exit(0);
    I will be changing the following line right off the bat:
    1 ) changing the argument passed to:
    Image inImage = new ImageIcon(bytes);
    I'm passing it my array
    bytes
    which I created in my upload servlet, it's holding the image.
    I don't want to write the newly thumbnail sized image to a JPEG stream as it is coded at the end of the program from Sun.
    Instead, I want to read the newly sized image into a
    byte[ ]
    array and then continue with my servlet program, and place the image into the db. I have a column of type BLOB waiting for it:)
    Does anyone know how to do this?

    Yes I have done this, do not have the code to hand, its in a real mess anyway, one of those things I got working and never got round to using...
    I based my code on some found here
    http://forum.java.sun.com/thread.jspa?forumID=20&threadID=505366
    Note, the above link shows how to add a watermark to an image as well.
    It does not show how to resize it (I was originally after the watermark bit) But I got it to resize by messing with the variables used to draw out the image.
    If you search the forums you will find this a common problem, but I was very impressed with the code posted in the above link, one of my favorites!

  • How to Read the Image in SQL server

    I want to read the image from SQL server using labview.In our project languages used are JAVA and Labview
    Through java we acquiring the image and write in to SQL Server.
    Through Labview I want to read the image form SQL server and i will do some image processing for my application.
    My problem when I seen the database the images shown like hex decimal value.
    I want to convert the hexadecimal value to image or any other functions is there to directly read the image from SQL server.
    Can anybody help me....

    two options:
    1. save the image data itself (as a blob)
    2. save the image in a file system and save the file name in the DB

  • IMAGE IN A FORM

    I'm trying to embed an image in a form. For example: show a persons picture with his name address etc. Can someone tell me exactly how to do this? The form will contain fields that are updateable. I tried this:
    Created a region;
    Created items A,B,C in this region
    Item A should contain a picture:
    Item A is defined as: Display as Text (escape special characters, does not save state)
    Element--
    HTML Form Element Attributes: ><img src="file:///C%7C/unzipped/Southwind/southwind_ss.gif" width="188" height="148"><td
    This kind of works, but everything seems misaligned.
    Is there a better or different way to do this?
    Thanks

    check permissions - unfortunately don't know the details, sorry!

  • How to create Edit Image in my form

    hi All,
    I have a form with header and detail, in my detail block i need to add Edit Image in my form. When i click on this i should be able to open one of my text column.
    can any one please help me how to create new images....

    Siva,
    There is a different Technology Stack associated with the Enterprise Business Suite (EBS). amitphynyl is correct with the description of how to create a button with the edit.ico assigned to it, but with the EBS, you will want to speak to your DBA to get a list of all the Icons that are available as you will have more icons with the EBS than are available with a standard install of Forms Builder 6i. I would also suggest you ask your DBA to give you a copy of all the Icons so you can add them to your Forms Builder installation so they will be available to you during design of your Form.
    I would also recommend that you review the Oracle Applications User Interface Standards for Forms-Based Products guide in the Oracle Applications Documentation web site to ensure your Custom Form conforms to Oracle guidelines.
    Hope this helps,
    Craig B-)
    If someone's response is helpful or correct, please mark it accordingly.

  • Can I enter an image into a form on Adobe Forms Central?

    Can I enter an image into a form on Adobe Forms Central?

    Yes, you can add an image to a form design using the toolbar button highlighted below:

  • Reading Data into a PDF form with cfpdfform and cfpdfformparam

    I have been trying to read data from a query into a PDF form. I have the application setup to generate a new pdf file for every record in the database table which is working perfectly, but when I try to have the application pre-populate the form fields in the pdf form they remain empty. I have included a snippet of the code that creates the PDF documents. I am using Adobe LiveCycle Designer 8.0 to create the PDF form.
    Snippet Example:
    <cfoutput query="renewals">
    <cfset new_file = "#reportnumber#.pdf" />
    <cfpdfform action = "populate" source = "beta.pdf" destination = "#new_file#">
      <cfpdfformparam name="Legal_Contact_Name" value="#LegalContactName#">
    </cfpdfform>
    <cfpdf action = "write" source = "#new_file#" destination = "#new_file#" flatten = "yes" overwrite  = "yes" />
    </cfoutput>
    All help is greatly appreciated...

    I'm just glad I might be of any help.
    First, make sure the image is embeded as a base64 encoded string in the xml structure you're working with on your form you've built in LiveCycle Designer.
    I do this by reading the image file and outputing its content as a base64 string:
    <cffile action="read" file="#expandPath('Path/to/your/image/file/BC.TIF')#" variable="imgObj" />
    <img>#toBase64(imgObj)#</img>
    Your PDF form should be bound to this 'img' field from your xml structure in LiveCycle Designer.
    This works perfectly and the image from the xml is indeed displayed in the PDF form generated with cfpdf.
    BUT, from the moment you convert the pdf form to static pdf document, the image will be gone - the dynamic text remains.
    Note:  I never further investigated why the image disapears once the pdf form is converted to 'static' pdf.  Thinking about it now, it might have been an incoding issue.  The toBase64() function in ColdFusion has an optional "Encoding" argument, may be by playing with the encoding the image might finally 'survive' the conversion to static pdf.
    Good luck.
    note: this will populate the pdf form from your xml structure in ColdFusion.
    <cfpdfform action="populate" source="/path/to/LiveCycle_generated_templateForm.pdf" xmldata="#your_xml_structure#" destination="/path/to/result.pdf" overwrite="yes" />

  • How to show image file on Form using From Builder 10G

    Hi
    Well, Gurus... i want to attach picture at runtime on my Form. The user select name of article and it automatically attach the image in my image item on Form.
    I'm using following code but it doesn't working.
    PROCEDURE GET_ARTICLE_PIC IS
    image_dir VARCHAR2(80) := 'D:\Images\';
    photo_filename VARCHAR2(80);
    BEGIN
    :System.Message_Level := '25';
    photo_filename := image_dir||:ITM_DIST_MST.ARTICLE_CODE||'.gif';
    message(photo_filename);
    message(photo_filename);
    READ_IMAGE_FILE(photo_filename, 'GIF', 'ITM_DIST_MST.ARTICLE_IMG');
    IF NOT FORM_SUCCESS THEN
    MESSAGE('This Article has not Picture.');
    END IF;
    :SYSTEM.MESSAGE_LEVEL := '0';
    END;
    Please help, its urgent

    Is it throwing any error?
    do you set correctly the ListUrl parameter? in this case it will be "PublishingImages"

  • Create image from byte[]array on server side

    Hello everyone..
    I'm developing an application which will take snapshots from a mobile device, and send it to my pc via bluetooth. I have my own midlet which uses the phone camera to take the snapshot, i want to transfer that snapshot to my pc.
    The snapshot is taken is stored in an array byte.
    The image can be created on the phone itself with no problem using : image.createImage(byte[])
    my problem is that when i send the array byte via bluetooth, and receive it on the server, i cannot create the image using the :image.createImage() code
    The connection is good since i have tested by writing the content of the array in a text file.
    Piece of midlet code:
                try{
                     stream = (StreamConnection)Connector.open(url);
                     OutputStream ggt = stream.openOutputStream();
                     ggt.write(str);
                     ggt.close();
                }catch(Exception e){
                     err1  = e.getMessage();
                }where str is my array byte containing the snapshot
    And on my server side:
    Thread th = new Thread(){
                   public void run(){
                        try{
                             while(true){
                                  byte[] b = new byte[in.read()];
                                  int x=0;
                                  System.out.println("reading");
                                  r = in.read(b,0,b.length);
                                  if (r!=0){
                                       System.out.println(r);     
                                       img = Image.createImage(b, 0, r);
                                                            //other codes
                                       i get this error message:
    Exception in thread "Thread-0" java.lang.UnsatisfiedLinkError: javax.microedition.lcdui.ImmutableImage.decodeImage([BII)V
         at javax.microedition.lcdui.ImmutableImage.decodeImage(Native Method)
         at javax.microedition.lcdui.ImmutableImage.<init>(Image.java:906)
         at javax.microedition.lcdui.Image.createImage(Image.java:367)
         at picserv2$1.run(picserv2.java:70)
    Please anyone can help me here? is this the way to create the image on the server side? thx a lot

    here is exactly how i did it :
    while(true){
                                  byte[] b = new byte[in.read()];
                                  System.out.println("reading");
                                  r = in.read(b, 0, b.length);
                                  if (r!=0){
                                       Toolkit toolkit = Toolkit.getDefaultToolkit();
                                       Image img = toolkit.createImage(b, 0, b.length);
                                       JLabel label = new JLabel(new ImageIcon(img) );
                                       BufferedImage bImage = new BufferedImage(img.getWidth(label),img.getHeight(label),BufferedImage.TYPE_INT_RGB);
                                       bImage.createGraphics().drawImage(img, 0,0,null);
                                       File xd = new File("D:/file.jpg");
                                       ImageIO.write(bImage, "jpg", xd);
                                       System.out.println("image sent");
                             }Edited by: jin_a on Mar 22, 2008 9:58 AM

  • Images, Thumbnails, byte[ ] and BLOB

    Hi guys,
    This is what I have to do:
    User selects image from disk and i'm putting it into DB (IBM DB2 8.0). That's clear. No problem.
    But I need that image as a thumbnail as well (I have to show images as thumbnails for each Item). I have a DB table IMAGE with 2 columns - IMAGE_FULL and IMAGE_THUMBNAIL.
    So I need to scale image(wich I have as byte array, or struts FormFile) and than put it into DB as Thumbnail.
    Or even if I don't have IMAGE_THUMBNAIL column, I have to get image as byte array from IMAGE_FULL column, scale it and show it in the browser.
    So, if I explained correctly and not very complicated way, can anyone give some ideas?
    Thanks in advance
    Gio

    For thumbnails, there's plenty of examples of resizing and saving images in the Java Programming forum, just do a search.
    For the database storage and retrieval... I had found some really good site with database examples, but I can't find it anymore.... but here's some code:
    // store
                   PreparedStatement pstmt = db.getConnection().prepareStatement(
                        "INSERT INTO TeeColor VALUES( ?, ? )" );
                   pstmt.setString(1, "yellow");
                   File fImage = new File("yellow.gif");
                   InputStream isImage = new FileInputStream(fImage);
                   pstmt.setBinaryStream(2, isImage, (int)fImage.length());
                   int res = pstmt.executeUpdate();
    // load
                   Statement stmt = db.getConnection().createStatement();
                   ResultSet rs = stmt.executeQuery(
                        "SELECT TCBlob FROM TeeColor WHERE TColor = 'Yellow'");
                   if(rs.next()) {
                        byte[] bytes = rs.getBytes("TCBlob");
                        JFrame f = new JFrame("test");
                        f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                        f.getContentPane().add(new JLabel(new ImageIcon(bytes)));
                        f.pack();
                        f.show();
                   }

Maybe you are looking for