Saving/Retrieving Images

I want to use a mySQL database to store and retrieve images. The images will first be read from a File and saved to a table, then later the image should be read from the table into a Java image object.
I'm not sure what field to use (TEXT or BLOB) and how to save the image to the database, and how to read the field from the database into an Image object.
Any suggestions?

You can save and retrieve images in MySQL as BLOB's. However, the default settings of MySQL will limit the size of your images to about 1 MB in size. This is a limitation of the communication settings, and not a table limitation. To change the setting, you need to edit the max_allowed_packet in the my.cnf configuration file.
http://www.geocities.com/shrm_phr/index.html

Similar Messages

  • Saving & populating images in apex

    hi
    I want to save & retrieve employee photoes in database using apex. can anyone help me.
    vijay

    Hi Vijay,
    Inside your workspace do you have sample application-> Run it->Go to Tab-> product-> Click Create Product-> Form shows input field with browse button-> Edit page to see the code to implement saving & populating images in apex.
    This is table based storage inside apex.
    If you want to store inside apex for your designing then go to shared component -> image-> create new image uploading-> Access from your page will be like the below.
    <img src=#APP_IMAGES#temp.jpg>
    This link also help.
    http://download.oracle.com/docs/cd/B31036_01/doc/appdev.22/b28839/up_dn_files.htm
    Thanks,
    Loga
    Edited by: Logaa on Sep 15, 2010 12:14 AM

  • How to retrieve image?

    i am working with j2me. in that i need to store and retrieve a image in the database. storing the image is working properly, but retrieving does not working. if any one knows help me...

    there is something called "blob" - datatype in oracle where u can store images. for example, in char - datatype it will take only one byte, for float - datatype it will take 32 bytes, like wise u can store images using blob datatype for storing images in oracle database. and for retreiving those images u need a front end tool to display those retrieved image like JSP. for example if u r attaching any photo for ur passport. and after that if u want to see the status any one day u can ensure that status by seeing ur photo that u have sent before. this is because they have saved ur photo using the "blob" datatype....just check it

  • Help! Saving an image to stream and recreating it on client over network

    Hi,
    I have an application that uses JDK 1.1.8. I am trying to capture the UI screens of this application over network to a client (another Java app running on a PC). The client uses JDK 1.3.0. As AWT image is not serializable, I got code that converts UI screens to int[] and persist to client socket as objectoutputstream.writeObject and read the data on client side using ObjectInputStream.readObject() api. Then I am converting the int[] to an Image. Then saving the image as JPEG file using JPEG encoder codec of JDK 1.3.0.
    I found the image in black and white even though the UI screens are in color. I have the code below. I am sure JPEG encoder part is not doing that. I am missing something when recreating an image. Could be colormodel or the way I create an image on the client side. I am testing this code on a Win XP box with both server and client running on the same machine. In real scenario, the UI runs on an embedded system with pSOS with pretty limited flash space. I am giving below my code.
    I appreciate any help or pointers.
    Thanks
    Puri
         public static String getImageDataHeader(Image img, String sImageName)
             final String HEADER = "{0} {1}x{2} {3}";
             String params[] = {sImageName,
                                String.valueOf(img.getWidth(null)),
                                String.valueOf(img.getHeight(null)),
                                System.getProperty("os.name")
             return MessageFormat.format(HEADER, params);
         public static int[] convertImageToIntArray(Image img)
             if (img == null)
                 return null;
            int imgResult[] = null;
            try
                int nImgWidth = img.getWidth(null);
                int nImgHeight = img.getHeight(null);
                if (nImgWidth < 0 || nImgHeight < 0)
                    Trace.traceError("Image is not ready");
                    return null;
                Trace.traceInfo("Image size: " + nImgWidth + "x" + nImgHeight);
                imgResult = new int[nImgWidth*nImgHeight];
                PixelGrabber grabber = new PixelGrabber(img, 0, 0, nImgWidth, nImgHeight, imgResult, 0, nImgWidth);
                grabber.grabPixels();
                ColorModel model = grabber.getColorModel();
                if (null != model)
                    Trace.traceInfo("Color model is " + model);
                    int nRMask, nGMask, nBMask, nAMask;
                    nRMask = model.getRed(0xFFFFFFFF);
                    nGMask = model.getRed(0xFFFFFFFF);
                    nBMask = model.getRed(0xFFFFFFFF);
                    nAMask = model.getRed(0xFFFFFFFF);
                    Trace.traceInfo("The Red mask: " + Integer.toHexString(nRMask) + ", Green mask: " +
                                    Integer.toHexString(nGMask) + ", Blue mask: " +
                                    Integer.toHexString(nBMask) + ", Alpha mask: " +
                                    Integer.toHexString(nAMask));
                if ((grabber.getStatus() & ImageObserver.ABORT) != 0)
                    Trace.traceError("Unable to grab pixels from the image");
                    imgResult = null;
            catch(Throwable error)
                error.printStackTrace();
            return imgResult;
         public static Image convertIntArrayToImage(Component comp, int imgData[], int nWidth, int nHeight)
             if (imgData == null || imgData.length <= 0 || nWidth <= 0 || nHeight <= 0)
                 return null;
            //ColorModel cm = new DirectColorModel(32, 0xFF0000, 0xFF00, 0xFF, 0xFF000000);
            ColorModel cm = ColorModel.getRGBdefault();
            MemoryImageSource imgSource = new MemoryImageSource(nWidth, nHeight, cm, imgData, 0, nWidth);
            //MemoryImageSource imgSource = new MemoryImageSource(nWidth, nHeight, imgData, 0, nWidth);
            Image imgDummy = Toolkit.getDefaultToolkit().createImage(imgSource);
            Image imgResult = comp.createImage(nWidth, nHeight);
            Graphics gc = imgResult.getGraphics();
            if (null != gc)
                gc.drawImage(imgDummy, 0, 0, nWidth, nHeight, null);       
                gc.dispose();
                gc = null;       
             return imgResult;
         public static boolean saveImageToStream(OutputStream out, Image img, String sImageName)
             boolean bResult = true;
             try
                 ObjectOutputStream objOut = new ObjectOutputStream(out);
                int imageData[] = convertImageToIntArray(img);
                if (null != imageData)
                    // Now that our image is ready, write it to server
                    String sHeader = getImageDataHeader(img, sImageName);
                    objOut.writeObject(sHeader);
                    objOut.writeObject(imageData);
                    imageData = null;
                 else
                     bResult = false;
                objOut.flush();                
             catch(IOException error)
                 error.printStackTrace();
                 bResult = false;
             return bResult;
         public static Image readImageFromStream(InputStream in, Component comp, StringBuffer sbImageName)
             Image imgResult = null;
             try
                 ObjectInputStream objIn = new ObjectInputStream(in);
                 Object objData;
                 objData = objIn.readObject();
                 String sImageName, sSource;
                 int nWidth, nHeight;
                 if (objData instanceof String)
                     String sData = (String) objData;
                     int nIndex = sData.indexOf(' ');
                     sImageName = sData.substring(0, nIndex);
                     sData = sData.substring(nIndex+1);
                     nIndex = sData.indexOf('x');
                     nWidth = Math.atoi(sData.substring(0, nIndex));
                     sData = sData.substring(nIndex+1);
                     nIndex = sData.indexOf(' ');
                     nHeight = Math.atoi(sData.substring(0, nIndex));
                     sSource = sData.substring(nIndex+1);
                     Trace.traceInfo("Name: " + sImageName + ", Width: " + nWidth + ", Height: " + nHeight + ", Source: " + sSource);
                     objData = objIn.readObject();
                     if (objData instanceof int[])
                         int imgData[] = (int[]) objData;
                         imgResult = convertIntArrayToImage(comp, imgData, nWidth, nHeight);
                         sbImageName.setLength(0);
                         sbImageName.append(sImageName);
            catch(Exception error)
                error.printStackTrace();
             return imgResult;
         }   

    While testing more, I found that the client side is generating color UI screens if I use JDK 1.3 JVM for running the server (i.e the side that generates the img) without changing single line of code. But if I use JDK 1.1.8 JVM for the server, the client side is generating black and white versions (aka gray toned) of UI screens. So I added code to save int array that I got from PixelGrabber to a text file with 8 ints for each line in hex format. Generated these files on server side with JVM 1.1.8 and JVM 1.3. What I found is that the 1.1.8 pixel grabber is setting R,G,B components to same value where as 1.3 version is setting them to different values thus resulting in colored UI screens. I don't know why.

  • How to see all image types when saving an image without selecting "all files"every time

    <blockquote>Locking duplicate thread.<br>
    Please continue here: [[/questions/951766]]</blockquote>
    Hallo, and thank you for reading this.
    I am a person who saves a lot of images online and renames them in different folders in different names like B - 34 or G - 56. I have been working with firefox 10 for quite some time and it had a pretty handy bug (I guess) where I could save an image and firefox would just save the image in it's original type (JPEG,PNG etc) while "save as type" was empty.
    It also always has shown all the image types in the folder where I save the images (except for GIF) and that helpes me quite a lot by saving me the trouble of selecting "all files" every time I save or going to the folder to rename every image.
    Now this seems to be lacking in the newest firefox versions and my question is if I can set firefox to always show me all the image file types when saving an image, instead of only showing JPEG's when I try to save a JPEG.
    Thank you for your time.

    I suspect this is a Windows problem. I am surmising the FilePicker uses the Operating System or Desktop facilities. Does Windows 7 offer any other file categories like ''images'' ?
    I do not normally use Windows 7, but may the option depend upon the directory being an indexed one, I ask after finding this thread ''Bring File types tab back'' [http://www.windows7taskforce.com/view/819]
    This question is a duplicate of [/questions/951764]
    Normally I would lock the duplicate question, but in this instance I will leave it open as it is unanswered and someone may give a better reply.

  • When saving an image in PS CS 6, and going back to Lightroom 5. The original image and the edited image are at the end of the line up.

    I'm using a Mac, Lightroom 5 and Photoshop CS 6. I've started having an issue with the line up in Lightroom 5 after saving an image from PS CS 6. For some reason when I save the edited image form CS 6 it's taking the edited image and the original image and putting it at the end of the line up in Lightroom. If I take the edited image and move it to the right of the original it will put both of them back in the line up where they should be. How do I fix this. I've been looking in the menu for some kind of setting  with no luck.

    Change the sort order. View->Sort

  • Trouble saving the image, save as button not working

    i'm having trouble in saving the image in PNG format, it seems that the "save as" button is not working properly, what should i do?

    Save from what program? On what system? In any case, ask in the product forum of whatever program you are referring to...
    Mylenium

  • How to retrieve image from a document

    Hi
    I am a beginner to Adobe InDesign SDK (CS4) and was needing some help. Here is the sceneario
    I have a simple InDesign document with an image in it. I am trying to retrieve the image and do some proprietory actions on it.
    I am wondering if there is an InDesign API which can retrieve image on a document. What is the return value from such an API. (e.g does the API return a pointer to the image object or maybe  location of the image on the filesystem ? ). What I am trying to do is once I can get a "handle" to the returned image, I would like to  manipulate it and save it in a proprietory format.
    Any pointers on this would be highly appreciated
    thanks!
    Sam

    Hi,
    You can get the path of the linked image file and then you can manipulate this image.
    I think ILinkUtils and ILink will certainly help.
    You can also check (for better understanding) CHM->PortingGuide->Links Archtecture.
    Thanks.

  • File name used by plug-in for saving the image file.

    I have a program that creates a web page that has an object tag with a call to a program and that program delivers a PDF file.  When my users want to save that image the name of the image is a random name.  Is there any way to make the plug-in, Adobe, use the meta tag Title or any other infromation that my program can provide, as image (file)  name to be used for saving the image. (the initial suggested name)?  I really appreciate your help.

    One option is to rename the file after it's been exported using Windows File I/O API.

  • Retrieving images for a java game

    i am currently trying to make a game whereby i have to retrieve images from a file and display it to the screen. I am able to do this using applets but the game i am implementing does not use applets - it only makes use of awt and swing components. any advice given would be gretly appreciated as i have been trying to do this for days now!

    Ive read all the tutorials and it still wont work. Ive tried both the
    ImageIcon anIcon=new ImageIcon("image.jpg");
    and the
    Image image = Toolkit.getDefaultToolkit().getImage("blah.gif" );
    I was wondering could it be something to do with XP or the java compiler im using?im using Forte for Java v3.The code complies fine but when i run it nothing appears!

  • Retrieving Images Embedded In XML (from rss using xsl)

    I am trying to comsuem and rss feed into my site but i dont seem to see an "image" element in the Item node. can someoen tell me how to retrieve Images Embedded In XML dreamwaever. i am using an xsl fragment on a pap server.
    Doh

    Hi there, I am using a jsp page that takes a xml page from the internet (user defines what page it is) it then takes the xsl feed and transforms the xml with a TransformerFactory object to get the results as an html page, the error is received when the jsp page is called
    Ian

  • Insertingand retrieving images in database using jdbc

    i am new to jsp.i have to store and retrieve image files using oracle 8i.Then i have to display it using jsp.
    my code for storing image is
    package sample;
    import oracle.jdbc.driver.*;
    import oracle.sql.*;
    import java.sql.*;
    import java.io.*;
    import java.awt.image.*;
    import java.awt.*;
    public class storephoto{
    public static void main(String[] args){
    String filename = "C:/Documents and Settings/user/Desktop/five.gif";
    Connection conn = null;
    try{
    Class.forName("oracle.jdbc.driver.OracleDriver");
    conn=DriverManager.getConnection("jdbc:oracle:thin:@10.1.4.228:1521:data","system","manager");
    conn.setAutoCommit(false);
    Statement st = conn.createStatement();
    int b= st.executeUpdate("insert into bfiles values('"+filename+"', empty_blob())");
    ResultSet rs= st.executeQuery("select * from bfiles for update");
    rs.next();
    BLOB blob=((oracle.jdbc.driver.OracleResultSet)rs).getBLOB(2);
    FileInputStream instream = new FileInputStream(filename);
    System.out.println("instream="+instream);
    OutputStream outstream = blob.getBinaryOutputStream();
    System.out.println("outstream="+outstream);
    int chunk = blob.getChunkSize();
    System.out.println("chunk="+chunk);
    byte[] buff = new byte[chunk];
    int le;
    while( (le=instream.read(buff)) !=-1)
    System.out.println(le);
    outstream.write(buff,0,le);
    System.out.println(buff);
    instream.close();
    outstream.close();
    conn.commit();
    conn.close();
    conn = null;
    System.out.println("Inserted.....");
    catch(Exception e){
    System.out.println("exception"+e.getMessage());
    e.printStackTrace();
    }//catch
    This code works fine & something gets stored in the buffer.but while rereiving nothing gets retreived.i cannot retrieve the image file
    my code for retreiving is
    package sample;
    import java.sql.*;
    import java.io.*;
    import java.awt.*;
    import oracle.sql.BLOB;
    public class retphoto
    public static void main(String a[])
    String fileName ="C:/Documents and Settings/user/Desktop/five.gif";
    try
    Driver driver = new oracle.jdbc.driver.OracleDriver();
    DriverManager.registerDriver(driver);
    Connection con = DriverManager.getConnection("jdbc:oracle:thin:@10.1.4.228:1521:data", "system", "manager");
    File file = new File("C:/Documents and Settings/user/Desktop/sa1.gif");
    FileOutputStream targetFile= new FileOutputStream(file); // define the output stream
    PreparedStatement pstmt = con.prepareStatement("select filecontent from bfiles where filename= ?");
    pstmt.setString(1, fileName);
    ResultSet rs1 = pstmt.executeQuery();
    rs1.next();
    InputStream is = rs1.getBinaryStream(1);
    System.out.println(is);
    byte[] buff = new byte[1024];
    int i = 0;
    while ((i = is.read(buff)) != -1) {
    System.out.println("hai");
    System.out.println(i);
    targetFile.write(buff, 0, i);
    System.out.println("Completed...");
    rs1.close();
    is.close();
    targetFile.close();
    pstmt.close();
    con.close();
    catch(Exception e)
    System.out.println(e);
    }

    Thanks for ur help:
    another Q:
    in my GUI i have a button called Insert. but can't update my database table unless i create textField(e.g Firstname, Surname..ect..), so that when I click Insert button in actionEvent it will bring up popup which have field name in which i am going to insert new records.
    so what iam trying to say is, how iam going to tell the actionEvent to trigger this.
    the following is my code
    public void actionPerformed(ActionEvent event)
    ExamResults exam= new ExamResults ();      
    String studentId = studentTextField.getText();
    if (event.getSource() == insert) //if insert is clicked
    Thanks

  • Retrieving images in lightroom

    I cannot seem to retrieve images from the Library mode. I refer to images that have previously been downloaded and most ranked, tweaked, etc. The message I get is that there is no picture. When I try then to retrieve from the original source, the message is that the photos have already been imported. Darned if I can find them.
    I am currently finding the TIF at the original source, re-naming it slightly and then I can import it -- only to lose it again. A real pain!
    Something I am doing is not right. Tell me.

    Check if you have a Filter applied. Then un-apply it
    Richard Earney
    http://inside-lightroom.com

  • Retrieve image from my sql database using jsp

    I want to retrieve image from my sql (blob type) & save it in given relative path in server .(using jsp and servlets)
    please give me some sample codes.

    PreparedStatement pst = null;
      ResultSet rs=null;
    pst = conn.prepareStatement("select image from imagedetails where imageid='"+imageid+"'");
    rs=pst.executeQuery();
    while(rs.next())
                                byte[] b=rs.getBytes("image");
                                FileOutputStream fos=new FileOutputStream("c://image.jpg");
                                fos.write(b);
                            } hi this the code to retrieve the image from DB and write to a file.

  • Saved an image as library and now all in iphoto images disappeared

    I was saving an image from email to iphoto, and somehow it was saved as my iphoto library. All of my photos are now gone, there were hundreds, and the one image I just saved is just there. Where are my photos??? Don't they get saved somewhere on my hard drive aside from being hosted iphoto. I have a MAC AIr and iPhoto '11.

    Rename it back.
    (110127)

Maybe you are looking for