Storing image to rms as bytes

hi, here imtrying to save image into rms and load the same from rms but i couldnt able to display the code
size of byte im getting is 1
import javax.microedition.rms.*;
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;
import java.io.*;
public class RMSImage extends MIDlet
{Form frm=null;
  private Display display;
RecordStore rs;
public RMSImage(){
                    rs=null;
                    //      InputStream is=null;
                    display = Display.getDisplay(this);
frm = new Form("Imageshow");
public void startApp(){
try{
          rs=RecordStore.openRecordStore("imagefile",true);
          System.out.println("record store created");
     catch(RecordStoreException r){r.printStackTrace();}
save();
     display.setCurrent(frm);
public void save(){
// System.out.println(imgdata);
try{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
byte data[]= null;
          try{
                    System.out.println("hi");
               DataInputStream dis = new DataInputStream(this.getClass().getResourceAsStream("/Duke.png"));
     System.out.println("check for image length");
     /* for(int j=0;j<3524;j++){ System.out.println("loop entering");data[j] = dis.readByte();System.out.println(data.length);
          System.out.println("datalength"+data.length);
          for (int i = 0; i < data.length; i++)
          dos.writeByte(dis.readByte());
          catch(Exception e){System.out.println(e);}
//System.out.println(imgdata);
int x=baos.toByteArray().length;
int r=rs.addRecord(baos.toByteArray(),0,baos.toByteArray().length);
System.out.println("length is"+x);
load(r);
catch(RecordStoreNotFoundException rsnfe){}
catch(RecordStoreException rse){}
catch(Exception ioe){}
System.out.println("sucess");
public void load(int i){
try{
byte data[]=rs.getRecord(i);
System.out.println(data.length);
Image.createImage(data,0,data.length);
}catch(RecordStoreException e){}
public void pauseApp(){}
public void destroyApp(boolean flag){
//System.out.println(save());
}

i kept that in for loop
even then i cudnt get the image n length same as i mentioned in the loop
response------>
Project "saveimage" loaded
Project settings saved
Building "saveimage"
Build complete
Running with storage root DefaultColorPhone
record store created
hi
check for image length
java.io.EOFException
length is2869
2869
sucess
Execution completed.
955248 bytecodes executed
28 thread switches
742 classes in the system (including system classes)
3980 dynamic objects allocated (134324 bytes)
2 garbage collections (90936 bytes collected)
But actual length is 3524 but length displayed is another
more over if i need multiple images to store what shal i do then
Edited by: lakshmi on Oct 25, 2007 2:43 AM

Similar Messages

  • Help Storing Images in rms

    Hola, Did someone get to stored sussecfully images in teh rms? I capture an image using MMAPI : snapshot() and i get a byte[] tyhat is waht I store in teh rms, but when open teh application again I get a error, I guess for the size of the picl, but I cvant choose the resoultion.l Actually teh pics are like 40 K and my applicatio is suppose to handle the capture and storage of 2 pics. OS i create a recolrd store recordPic= new byte[80000].
    Any ideas?

    You could also check whether this 10K for each picture is still working okay, by checking whether it is possible to save and reload a thumbnail of that picture.
    You've already read the article at http://developers.sun.com/techtopics/mobility/midp/articles/picture/.
    But it has a private method that can be used for testing a thumbnail and use that for saving in the rms. When you can read that image back again, then there's nothing wroing with how're you constructing the image. Then it's related to the image size.
    See this method (copied from the article) and use it for creating a thumbnail:
      private Image createThumbnail(Image image) {
      int sourceWidth = image.getWidth();
      int sourceHeight = image.getHeight();
      int thumbWidth = 64;
      int thumbHeight = -1;
      if (thumbHeight == -1)
        thumbHeight = thumbWidth * sourceHeight / sourceWidth;
      Image thumb = Image.createImage(thumbWidth, thumbHeight);
      Graphics g = thumb.getGraphics();
      for (int y = 0; y < thumbHeight; y++) {
        for (int x = 0; x < thumbWidth; x++) {
          g.setClip(x, y, 1, 1);
          int dx = x * sourceWidth / thumbWidth;
          int dy = y * sourceHeight / thumbHeight;
          g.drawImage(image, x - dx, y - dy,
              Graphics.LEFT | Graphics.TOP);
      Image immutableThumb = Image.createImage(thumb);
      return immutableThumb;
    }

  • Storing image binary vs. storing URL

    hi experts,
    What are the benefits of storing the binary data of an image or an audio file in the database? Would it be much faster if I store the URL string to the file instead?
    Thanks.

    the sources of the jre classes are in a (about) 20-meg file called src.jar.
    Storing "src.jar" takes 7 bytes (or 14, if you use 16bit unicde).
    Storing the contents of "src.jar" takes 20,000,000 bytes.
    Well, what do you think? Is it faster to save the a name (~ URL) or the entire file?

  • Storing images to persistent storage

    Hi all
    Does anyone know a good tutorial for storing images to persistent storage?
    I am comfortable in the process of storing items such as int and string etc.
    writeUTF ()
    readUTF()
    etc...But i cannot see how to store an image? and the inverse how to load the image back up.
    Mainly my lack of knowledge hinges on the fact that I do not know how to convert an Image to a byte array and make an image from a byte array?
    Then using this byte array what methods I uses from the DataOutputStream and DataInputStream for population?
    If anyone knows or can help would be very grateful?
    jimbobegg

    For anyone concerned heres a solution I used in its own class:
    public static void convertImageAndStore( Image photo, DataOutputStream daos )
         int imageWidth, imageHeight;
         imageWidth = photo.getWidth();
         imageHeight = photo.getHeight();
         int[] imgRgbData = new int[ imageWidth * imageHeight ];
         try
              photo.getRGB(imgRgbData, 0, imageWidth, 0, 0, imageWidth, imageHeight );
              //Start to write the different parts to the
              //DataOutputStream
              daos.writeInt( imageWidth );
                    daos.writeInt( imageHeight );
                    daos.writeInt( imgRgbData.length );
                    //Serialize image and store
                    //Serialize the image raw data
                    for (int i=0; i<imgRgbData.length; i++)
                        daos.writeInt(imgRgbData);
         catch( Exception exc )
              System.err.println( "Exception thrown by Utility::convertImageAndStore()");

  • Displaying server stored images in an air application

    Usually when I go about displaying server stored images in a regular flex application I go about it the following way:-
    - Create a mysql database table on a server which contains image names
    - Create a php file which generates all of the image namesfrom the table as xml and upload this file to the server
    - Create a new flex application/project
    - In the application make a http service which points to my php/xml file and turns this data into an array collection
    - Set the array collection to the dataprovider of a tilelist component so that all of the images will eventually be displayed within it when they are created
    - I set the itemrenderer of the tilelist to an image component which has it's source set to something like source="{'assets/images'+ data.imagename}" with imagename being the field containing the name of the image which is stored in the mysql database table.
    - Make a folder in the app/project called assets/images which will contain all of the images
    - Upload the app to the server and once it runs all the images will be displayed in the application
    - Then any images that are uploaded to the server can also be displayed as long as their names are added to the mysql database
    My question is though how do you get server stored images to display within an Air Application? My air app will be used on multiple machines but I want the images in it to be dynamic i.e. stored on a server and can be changed. How can this be done?

    I'm struggling to figure out how to access the image files when the assets/images folder will be on a server and the app itself will be on the user's desktop whereas usually in the case of a regular flex app this wouldn't mater as both the app and the image files would be on the server together. Is what I'm trying to do possible i.e. displaying images on a desktop air app straight from a server?

  • How to read the stored images

    hi
    i have images in my table img,
    i want to know how toretreive that stored image

    i have images in my table img
    > i want to know how toretreive that stored image
    How to retrieve it depends on how it is stored? What is the data type? Is it perhaps a blob (large object in binary format)? If so check out the package dbms_lob and read Application Developer's Guide - Large Objects. If not connect to your database using sql plus to publish the data type for the image column from the command "describe img".

  • Drag and Drop image to desktop == Zero Byte File

    Drag and Drop image to desktop == Zero Byte File
    == This happened ==
    Every time Firefox opened
    == FireFox 3.6 OR Windows 7 64

    i have the same problem and Sun doesn't seem to have an answer to this question. The DnD works in Mac OS, but not on Window 2000/XP.

  • How do i convert an image object to a byte array ?

    Hi
    how do i convert an image object into a byte array
    early reply apperciated

    Oh sorry my method and the other method need to have the pixels from the Image passed to them which you get my using pixelgrabber:
    //create width and height variables from image
              int w = img.getWidth(this);
              int h = img.getHeight(this);
              //retrive picture from image
              int[] pix = new int[w * h];
              PixelGrabber pg = new PixelGrabber(img, 0, 0, w, h, pix, 0, w);
              try{ pg.grabPixels();
              } catch (InterruptedException ioe) {
                   System.err.println("Interrupted");
              if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
              System.err.println("image fetch aborted or errored");
              }

  • Blob Problem (storing Images)

    AOA!
    I am working as a developer in a companey. we made a database for HRMS. In this database there is a table EMPLOYEE with a column PICTURE of type BLOB. We were using oracle 8i initially but when we migrate to oracle 9i, we are facing a problem in image storing. The situation is, database showing ur previously stored images (those have stored in oracle 8i) but when we save a new image in that table or any other table it seams to be saved but cannot retrived. I mean when we issue a query
    SELECT EMP_ID FROM EMPLOYEE WHERE PICTURE IS NOT NULL;
    It shows the new inserted records too (thats shows us that picture has been inserted) but when we issue query from a forms6i application it didnt show any image. In case of report, when we try to query a record which newly inserted with image, it says some thing like REPORT IS UNABLE TO SHOW IMAGE FORMATE etc.
    The situation is for all table and all schema which is indicating us may be it is some thing due to oracle 9i headen technique or due to miss managment by us. we dont have DBA in our companey.
    Please help us in this regard. We will be thankfull to you.
    Usman Rana
    Dont reply to above mantioned email my actual email account is [email protected]

    I think that both your SQL is wrong and your intended use is wrong. According to the SQL reference, the following seems to be a simplified definition that seems to match what you're trying to do. UPDATE &lt;table&gt; SET &lt;column&gt; = &lt;expr&gt;. So PROPERTIES should be a &lt;table&gt; of some kind and X should be a &lt;column&gt; of that table. This changes your PreparedStatement to *"UPDATE PROPERTIES SET X = ? WHERE NAME = ?"* Then you can do ps.setBlob(1, b) and ps.setString(2, ...). Because your statement is DML you must do ps.executeUpdate(). So your code might look something like this.
    Blob b = ...;
    String x = ...;
    ps = c.prepareStatement("UPDATE PROPERTIES SET X = ? WHERE NAME = ?");
    ps.setBlob(1, b);
    ps.setString(2, x);
    int i = ps.executeUpdate();
    The executeUpdate() returns the row count (i.e. number of rows) of your DML statement. Try that and see if it helps.

  • Which is better datatype for storing Images in 11gr2 Database ?

    Can anyone tell me which datatype should be maintained for storing images in database in terms of
    1. Space
    2. Speed.
    And, Is there another way for storing images instead of database ?
    Thanks/Regards in advacne.

    982164 wrote:
    Which one have better speed, database system or file system ?Database is better all around. It is not just a question of speed. It is a question of storage, security, flexibility, scalability, robustness and so on.
    If you use ASM and raw devices from a storage array or SAN, how do you get o/s files onto that? (requires a file system on the SAN/array LUNs)
    If it is inside the database, database security, concurrency and consistency apply to the image. Outside the database? How do you control who has access? Prevent someone with slippery fingers from accidentally deleting/renaming/moving images files? How do you backup up the image data with the image attribute data in the database?
    Having all this inside the database, part of the database, managed by the database, provides you with more flexibility, robustness, and security. After all a RDBMS is a data management system - it is designed for managing data. And that includes managing binary data.
    As for speed. Reading a 24MB image is reading 24MB worth of data. Whether that data is read by process A from disk1, or process B from disk2 - the amount of data is the same. So if you want faster I/O, then use faster disks. If disk1 is faster, process A will perform better reading the image than process B. If disk2 is faster, the roles are reversed.
    So I/O speed is not a direct function of process A or process B. It is a direct function of the I/O storage and fabric layer. Yes, a process's method of I/O can make a difference (e.g. using block reads not aligned with the physical blocks on disk). But this is more a configuration issue than process doing badly designed I/O calls.
    So the speed question is a bit loaded as it has more to do with the architecture and design of the I/O system - and less to do with the process doing that I/O. You can have a highly optimised I/O process doing poorly using an old and slow I/O layer, and poorly written I/O process doing pretty well on a SSD I/O layer.
    Databases like Oracle is designed for dealing with data - and thus effectively dealing with I/O. Lots of it. For lots of data. So I/O process design is not a consideration. The database processes will use the I/O layer as optimally as possible and as configured.

  • Storing Images In Oracle 9.2 Using Forms 6i

    When my database was 8.1.7, storing Images in the database in BLOB field worked fine through Form 6i. But when the database was upgraded to 9.2 then the images are not loaded in the database through Forms 6i.
    Kindly help
    Thanks

    Hi,
    I wanted to do the same thing and faced the same problem. I'm working on Forms 6i and Oracle 9i as backend.
    When an Image item is created on forms, it's datatype is set to Long Raw. You can see this by changing the type of the image item to text item. You'll see that the datatype is Long Raw. The idea of inserting the image would work perfectly if you set the datatype of the column to Long Raw in the backend.
    For using BLOB... I searched alot but all in vain. No answer as to how to handle BLOB in Forms 6i.
    Do let me know if you get a way out.

  • Folder for stored images (Portalheader)

    Hello experts,
    could anyone let me know where I can find all the uploaded images for the Portalheader(Masthead). Where can I find the folder who is ressponsible for the administration of the images/background images??
    Thank you
    Regards
    Marco

    Hi Marco,
    You can find those uploaded image files in KM. KM is like your file server but is within the Portal that you can use to manage your files/content/data. Files, content or data exist in KM can be index and search via the Portal TREX (Search Engine).
    SAP NetWeaver Training Overview - SAP Knowledge Management (KM)
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/06fac090-0201-0010-af9c-b67d14558014
    1) Storing images in Portal
    Storing images in Portal
    2) Simple static web pages and images? Store/refernence in KM?
    /thread/378997 [original link is broken]
    3) Upload Image to KM Repository
    /thread/26834 [original link is broken]
    4) showing image located in km folder
    showing image located in km folder
    Hope that helps.
    Ray

  • Storing images in database

    want to store images in database for security. I c an't remember the steps to take advantae of the security feature in the DAD section of the em tool

    I suggest that you convert the Images to jpg (or png or another format that is understood by a browser). Depending on the creation/read ration (normaly you create an image that is read several times), I suggest doing the convertion before storing it in the database
    // BufferedImage bi is created before...
    // out is your OutputStream to the Blob-field
    com.sun.image.codec.jpeg.JPEGImageEncoder encoder = com.sun.image.codec.jpeg.JPEGCodec.createJPEGEncoder(out) ;
    // get the EncodingParameters
    com.sun.image.codec.jpeg.JPEGEncodeParam jep = encoder.getDefaultJPEGEncodeParam(bi) ;
    jep.setQuality(compress,true) ;
    encoder.setJPEGEncodeParam(jep) ;
    encoder.encode(bi) ;
    // System.out.println("Fertig codiert") ;
    // flush the OutputStream and close it
    out.flush() ;
    out.close() ;you should have an unique identifier for each image, that is kept in the key column(s) of your image table.
    To retrieve the image write a servlet, to which you pass this unique key as a parameter (or several if it is a multi column key) . This servlet should than access the database, select the row, open the Blob field and read it and write the bytes to an OutputStream you get from the response argument of doGet or doPost.
    If you expect large images, you can stream the result, i.e. not read it in fully before writing it to the output stream but rather write each chunk you read to the output stream immediately.

  • Storing images in e72 gallery

    Wats app images are all storing in my e72 gallery.let me know how to deactivate this function

    I suggest that you convert the Images to jpg (or png or another format that is understood by a browser). Depending on the creation/read ration (normaly you create an image that is read several times), I suggest doing the convertion before storing it in the database
    // BufferedImage bi is created before...
    // out is your OutputStream to the Blob-field
    com.sun.image.codec.jpeg.JPEGImageEncoder encoder = com.sun.image.codec.jpeg.JPEGCodec.createJPEGEncoder(out) ;
    // get the EncodingParameters
    com.sun.image.codec.jpeg.JPEGEncodeParam jep = encoder.getDefaultJPEGEncodeParam(bi) ;
    jep.setQuality(compress,true) ;
    encoder.setJPEGEncodeParam(jep) ;
    encoder.encode(bi) ;
    // System.out.println("Fertig codiert") ;
    // flush the OutputStream and close it
    out.flush() ;
    out.close() ;you should have an unique identifier for each image, that is kept in the key column(s) of your image table.
    To retrieve the image write a servlet, to which you pass this unique key as a parameter (or several if it is a multi column key) . This servlet should than access the database, select the row, open the Blob field and read it and write the bytes to an OutputStream you get from the response argument of doGet or doPost.
    If you expect large images, you can stream the result, i.e. not read it in fully before writing it to the output stream but rather write each chunk you read to the output stream immediately.

  • Image resizing & conerting to byte[]

    I'm working on a servlet. I have an image stored in a database
    (jpg or gif), and i need to resize it before sending to browser.
    I know how to create an Image from a byte array, and resize it,
    but how can i create again a gif/jpg file from the Image object
    and transform it again to a byte array to send to client?
    Thanks!!

    Hm...that was only half the answer...
    For jpg encoders, there is one in rt.jar that works, but it requires some manual labor...and starting up the awt event thread which is sort of costly.
    Here's an example of how to encode a file to jpg.
    (You must include rt.jar in the classpath for it to compile and run)
    import com.sun.image.codec.jpeg.*;
    import java.io.*;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.image.*;
    public class Test extends JFrame
         public Test()
              super("JPG encoder");
              getContentPane().setLayout(new GridLayout(2,1));
              ImageIcon theIcon = new ImageIcon("image.gif");
              int w = theIcon.getIconWidth();
              int h = theIcon.getIconHeight();
              getContentPane().add(new JLabel(theIcon));
              setVisible(true);
              BufferedImage theImage = (BufferedImage)createImage(w, h);
              theImage.createGraphics().drawImage(theIcon.getImage(), 0, 0, Color.black,null);
              setLocation(300,300);
              try
                   FileOutputStream theStream = new FileOutputStream("image.jpg");
                   JPEGImageEncoder theEncoder = JPEGCodec.createJPEGEncoder(theStream);
                   theEncoder.encode(theImage);
                   ImageIcon theNewIcon = new ImageIcon("image.jpg");
                   getContentPane().add(new JLabel(theNewIcon));
                   pack();
              catch (Exception e)
              {e.printStackTrace();}
         public static void main(String[] args)
              new Test();
    }You can easily change that FileOutputStream to a ByteArrayOutputStream and then just extract the bytes...

Maybe you are looking for

  • In Safari I cannot login to one of my yahoo accounts...

    Hi everyone, I just got safari and love it but am having 1 problem. I have 2 yahoo accounts one personal and one through small business. For some reason I can get into the personal one but not the small business. On other browsers I can get in to bot

  • How many hdd's can I install in Quicksilver

    Have the SIIG Serial ATA 4 Channel PCI-M card running one 250GB HDD at the present with 1 running off the original system bus. How many can I add total to this system? Owners manual states I can run only 2 total in this machine. Is it true that now I

  • Function Keys not working properly after recent update today.

    Sat C855 - today I downloaded the 2 recent updates & now my function keys aren't working properly. Anyone one else have that problem? What can I do?

  • How to set default size for .chm window?

    I know there is an answer at grainge.org, but it seems to be referring only to a .chm using skins, which I am not. Anybody know how to make the default size of the .chm larger? thanks, Leisa

  • Newest Version of Lightroom is Slooooooooooooooow

    Anybody else notice the current version of lightroom is much slower than previous version? I've looked for the option to Optimize Catalog but it seems to have been removed from the program? Anyone else notice this. I'm thinking about reinvestigating