Java2D get image size without read image to buffer

Hi,
I need get the image size without buffering the image. Can somebody help me?
THX

I have problem with this code, can somebody help me how can I fix this problem?
String strFileName = "D:/Dokuments/10/Sturovo.tif";
String strFormat = "tif";
Iterator rs = ImageIO.getImageReadersByFormatName(strFormat);
ImageReader ir = (ImageReader) rs.next();
File srcFile = new File(strFileName);
ImageInputStream iis = ImageIO.createImageInputStream(srcFile);
ir.setInput(iis);
int nImageCount = ir.getNumImages(true);
int h = ir.getHeight(0);
int w = ir.getWidth(0);exteption:
Exception in thread "main" java.util.NoSuchElementException
at javax.imageio.spi.FilterIterator.next(ServiceRegistry.java:808)
at javax.imageio.ImageIO$ImageReaderIterator.next(ImageIO.java:502)
at javax.imageio.ImageIO$ImageReaderIterator.next(ImageIO.java:487)
at imageanalizer.ImageLoader.run(ImageLoader.java:46)
at imageanalizer.Main.main(Main.java:19)
Java Result: 1

Similar Messages

  • How to get server data without reading from the socket stream?

    My socket client checks for server messages through
                while (isRunning) { //listen for server events
                    try {
                            Object o = readObject(socket); //wait for server message
                                tellListeners(socket, o);
                    } catch (Exception e) {
                        System.err.println("ERROR SocketClient: "+e);
                        e.printStackTrace();
                    try { sleep(1000); } catch (InterruptedException ie) { /* ignore */ }
                }//next client connectionwith readObject() being
        public Object readObject(Socket socket) throws ClassNotFoundException, IOException {
            Object result = null;
    System.out.println("readObject("+socket+") ...");
            if (socket != null && socket.isConnected()) {
    //            ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
                ObjectInputStream ois = new ObjectInputStream(new DataInputStream(socket.getInputStream()));
                try {
                    result = ois.readObject();
                } finally {
    //                socket.shutdownInput(); //closing of ois also closes socket!
        //            try { ois.close(); } catch (IOException ioe) { /* ignore */ }
            return result;
        }//readObject()Why does ois.readObject() block? I get problems with this as the main while loop (above) calls readObject() as it's the only way to get server messages. But if i want to implement a synchronous call in adition to this asynchronous architecture (call listeners), the readObject() call of the synchronous method comes to late as readObject() call of the main loop got called before and therefore also gets the result of the (later) synchronous call.
    I tried fideling around with some state variables, but that's ugly and probably not thread safe. I'm looking for another solution to check messages from the server without reading data from the stream. is this possible?

    A quick fix:
    - Add a response code at the beginning of each message returned from the server indicating if the message is a synchronous response or a callback (asynch);
    - Read all messages returned from the server in one thread and copy callback messages in a calback message queue and the synch responses in an synch responses queue;
    - Modify your synchronous invocation to retrieve the response from the responses queue instead from the socket. Read the callback messages from the corresponding queue instead from the socket.
    Also take a look at my website. I'm implementing an upgraded version of this idea.
    Catalin Merfu
    High Performance Java Networking
    http://www.accendia.com

  • Getting the size of a file without reading it

    Hello we are currently implementing a file upload/download framework in our application.
    The framework will included multiple filters such as for file mime types, suffices and size of the file.
    However, for the size filter, we want to check the size without reading it. This is because reading a file which we would later find unacceptable for our application would mean that we are wasting the resources. 
    Since we are currently using an IWDResource object to implement the framework, the method
             IWDResource.getStream(false).available()                                                                                may not come in handy as it seems to read the file to find out its size.
    I need to know whether there is some other method or approach we can emply, using IWDResource object, that will not read the file to find out the size.
    Thanks alot in advance.

    But, it doesn't give me an error, it just gives me the length of the URL, and for some reason it also adds 'D:\jsdk1.4\bin' to the beginning of my URL, so instead of
    File webFile = new File(webFileURL.toString());and you would think that it would be similar code to:
    File webFile = new File("http://66.185.95.103/8989898904/miko17a.avi");but instead, i've checked the File name, and it was
    D:/jsdk1.4/bin/http://66.185.95.103/8989898904/miko17a.avi
    or similar code...
    File webFile = new File("D:/jsdk1.4/bin/http://66.185.95.103/8989898904/miko17a.avi");why does it add the bin folder of my Java SDK to the beginning??? if it didn't do that, everything would be fine...

  • How to decrease PDF file size without losing quality of images and vector lines?

    I have several ai files that I saved as PDFs. Now I'm having problem with the size of this combine files. Can some one assist me with the proper way on decreasing file size without losing quality.
    Thank you.

    I am having the same problem with a different file that's in a different format mentioned above. I'm trying to convert a ".srf" file and turn it into a ".pdf." I was successful doing this but my image, once in a .pdf was also pixilated.
    I thought if I convert my ".srf" file to a ".jpeg" first, then bring this newly created ".jpeg" into a ".pdf," I would have more luck. But unfortunately the free download I got on my computer that's supposed to convert any file to any file, CANNOT convert ".srf" files to ANYTHING!
    Does anyone have any ideas? Or any specific programs I should get?
    Thanks!

  • How to get Image size?

    Hello,
    I need help for getting Image size, when i am using JAI.
    for example:
    RenderedImage img = JAI.create("url", url);
    If you could help me than please.
    Thanks
    bye
    Jarrar.

    img.getHeight();
    img.getWidth();

  • How to get image size in bytes

    i have to get image size in bytes and accessing image from the a folder
    Thanks in advance

    If it's going to be accessed as a file on the filesystem, you can use java.io.File.length() to get the size in bytes.
    In other situations...it depends on what you're doing.

  • Is there a way to change clip size without losing image quality? Specifically from 568 x 320 to 1920 x 1080?

    Is there a way to change clip size without losing image quality? Specifically, from 568 x 320 to 1920 x 1080?

    No, especially not video files. That's way too much scaling.

  • How to get images dynamically from database without file paths in the table field

    I have a MS-Access database. I am working with ASP.NET. In the database there is product table in which I have "CodeNo" as a field which is a text field, and the product codes like "SM-R-2035". I also have another field "Image" which is also a text field and which have a file path in it corresponding to the particular product Image (e.g. Images\Products\SM-R-2035.jpg). So far every thing is ok. I have to update this site very frequently and lots of images are added each and every time. Its a tedious work to type the paths and file name every time and it also take a lot of time.
    What I am asking is : Is it possible to get images from a specific folder at runtime which is referenced by the "code no" itself and not the file path from the database. (Say at run time the "code no" is referenced from the database and the corresponding image is loaded dynamically from the specified folder). In other word I want to avoid the tedious work of typing.
    Can any one help with this issue. Any other simple suggestions are welcome.

    All you need to do is simple concatenation to obtain the path for the image file.  You didn't mention whether you are using VB.Net, C# or some other language to do your coding.
    If the code in your database is SM-R-2035, the file name is SM-R-2035.jpg and the path to the images foilder is Images\Products\SM-R-2035.jpg, Conceptually here is what you need to do:
    dim code_var
    dim path_var
    code_var = the code you obtain from your relevant field in the database
    path_var = "Images\Products\" & code_var & ".jpg"
    Now path_var is what you would call to obtain the image from your images folder.

  • Help needed : getting the size of an image

    Seems that my first post didn't work.. so i try another time.
    I'd like to get the size (width and height) of an image file, just using the path of that file.
    Does anyone knows if there is an existing class that can allow me to, or does someone knows the way i should work on it
    Thanks in advance

    In java.awt.Image there are getWidth() and getHeight()
    Klint

  • Getting the size of a jpeg image

    Hello,
    I'm looking for a way to get the size (height and width in
    pixel) of a jpeg file before actually loading the file.
    Is it possible ?
    Thanx.
    Vincent

    This is a flaw in Pages IMHO.
    As for many things the information and manipulating the properties is oblique to say the least.
    You have to do what you have done or do some calculations based on size, and known resolution.
    A way around might be to tag the image in the name with the actual pixel size.
    I work from my images marked in folders as vLoRes, LoRes, MedRes, HiRes, vHiRes and uHiRes.
    Given a basic requirement of a bare minimum 100 pixels/cm (roughly 254dpi) for commercial reproduction the images will cover (with bleed):
    vLoRes = A7
    LoRes = A6
    MedRes = A5
    HiRes = A4
    vHiRes = A3
    uHiRes = beyond A3
    But then I happen to be very systematic in the way I work. It is a useful skill I have taught in my studios. Unfortunately many designers, and users in general, are sloppy and short sighted.
    Peter

  • How to increase the image size without losing resolution in iPhoto?

    Dear All
    I have pics i took with my phone which is not an iphone, just little sony ericsson phone.
    Is there a way to increase the image size without losing resolution in iPhoto please? Or cheap 3rd party software or shareware perhaps?
    thank you very much.
    veedeekay

    iPhoto has no way to do that. You'll need an external editor for the job. Not all have the capability. I know Photoshop has.
    You can set Photoshop (or any image editor) as an external editor in iPhoto. (Preferences -> General -> Edit Photo: Choose from the Drop Down Menu.) This way, when you double click a pic to edit in iPhoto it will open automatically in Photoshop or your Image Editor, and when you save it it's sent back to iPhoto automatically. This is the only way that edits made in another application will be displayed in iPhoto.
    Regards
    TD

  • Get image map visible to user without mouseover

    If I insert an image map, the user sees a hot spot image map when the mouse is over the image map. I want the user to see where there are hot spots before they move the mouse.
    Is there a way to get this functionality without having another image overlay the image map? Perhaps I can use something other than image maps?
    Peter

    Use a graphics tool such as RoboScreen Capture to add a coloured border around the area.
    See www.grainge.org for RoboHelp and Authoring tips
    @petergrainge

  • Getting Images To Load On Web?

    Hi all,
    I have a question about how to get images to load in an applet once it is uploaded to a website. When I run the applet in JGrasp it works fine but if I try to open the applet in a web browser (via an html file on the hard drive) nothing loads. If I take the code out that sets the background image the application loads fine in the web browser.
    The image is in the same directory as the class file and html file. Is there a way I can get this method to work (loading off the hard drive and also off the website when it's uploaded) or do I have to use a jar file? I have spent some time searching for tutorials and demos but haven't been able to get the jar file to work either. I'm fairly new to programming and most of the examples I found were way over my head.
    Any help in getting this problem solved will be greatly appreciated.
    Here is a short sample program to illustrate the problem: For some reason this sample program only loads in IE and not in Firefox.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class Test extends JApplet implements ActionListener
    {     Container     mainWindow;
         public void init()
         {     ImagePanel panel = new ImagePanel(new ImageIcon("Background.jpg").getImage());
              setContentPane(panel);
              mainWindow = getContentPane();
              mainWindow.setLayout(new BorderLayout());
              JLabel label = new JLabel("TESTING");
              mainWindow.add(label, BorderLayout.CENTER);
              setSize(1000, 500);
              setVisible(true);
              mainWindow.validate();
         public void actionPerformed(ActionEvent e) { }
    class ImagePanel extends JPanel
    {     private Image img;
         public ImagePanel(String img)
         {     this(new ImageIcon(img).getImage());
         public ImagePanel(Image img)
         {     this.img = img;
              Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
              setPreferredSize(size);
              setMinimumSize(size);
              setMaximumSize(size);
              setSize(size);
              setLayout(null);
         public void paintComponent(Graphics g)
         {     g.drawImage(img, 0, 0, null);
    CODE FOR HTML FILE:
    <html><body>
    <CENTER>
         <applet code="Test.class" width="1000" height="500"></applet>
    </CENTER>=
    </body></html>

    Hello again,
    I've got one more small question. I modified the code a little bit so I could create an Image folder (package) which holds all of the images and the ImagePanel class. Since the ImagePanel and images are all in the same folder, I modified the ImagePanel constructor to take a string and then load the file with that name. It works in JGrasp and when I open it in a web browser from my computer, but when I upload it to the site it no longer works. Is there a way to get at these images inside the folder when it's online without drastically changing the method I used in the first place? I saved the original files that I can go back to so if it's not an easy fix then that's no big deal, but I thought I'd ask just in case it is something simple as it would be nice to have the files more organized. Thanks.
    Here's the updated code.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.net.*;
    public class Test extends JApplet implements ActionListener
    {     Container     mainWindow;
         URL               url;
         public void init()
              ImagePanel panel = new ImagePanel("Background.jpg");          // background image
              setContentPane(panel);
                mainWindow = getContentPane();
                mainWindow.setLayout(new BorderLayout());
              JLabel label = new JLabel("TESTING");
              mainWindow.add(label, BorderLayout.CENTER);
              setSize(1000, 500);
              setVisible(true);
              mainWindow.validate();
         public void actionPerformed(ActionEvent e) { }
    class ImagePanel extends JPanel
    {     private Image img;
         public ImagePanel(String img)
         {     this(new ImageIcon(img).getImage());
         public ImagePanel(Image img)
         {     this.img = img;
              Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
              setPreferredSize(size);
              setMinimumSize(size);
              setMaximumSize(size);
              setSize(size);
              setLayout(null);
         public void paintComponent(Graphics g)
         {     g.drawImage(img, 0, 0, null);
    }Inside "Image" folder:
    package Image;
    import java.awt.*;
    import javax.swing.*;
    public class ImagePanel extends JPanel
         public Image img;
         public ImagePanel(String imageFile)
              Image img = new ImageIcon(getClass().getResource(imageFile)).getImage();
              this.img = img;
              Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));          // set size = size of image
              setPreferredSize(size);
              setMinimumSize(size);
              setMaximumSize(size);
              setSize(size);
              setLayout(null);
         public void paintComponent(Graphics g)
              g.drawImage(img, 0, 0, null);
    }

  • I mounted my external hard drive to a pc and now I don't have edit or write permissions on my Mac (read only). How do I get them back without erasing the drive?

    Hello all, I am a photographer and have my portfolio, edited and raw images backed up on a Seagate Free Agent External Hardrive. I mounted my external hard drive to a pc recently and now I don't have edit or write permissions to it on my Mac (read only). How do I get them back without erasing the drive and loosing my valuable work?

    If you re-format it you will lose all the data on it!!!!! So make sure you have backed up the drive or moved all the data on it to another external HD or the internal HD on your iMac.
    Below is an Apple Advice letter that explains how to format an external HD, it's written for Aperture but you can use the instructions to formate any external HD.
    http://support.apple.com/kb/HT3509

  • Getting image stored in database !!

    Hey !!
    I'm really trying to solve so much problems i'm having with javafx !!
    So, like the title may suggest, i'm having problems as to get image from the database !!
    Everything seems fine but it tells me that there is "Exception while runing Application"
    here is the code !!
    @James D, i will come back bugging yu again to see how to use the stored images and display them inside the combobox and to render them ^^
    I haven't well understand how well as to use the enum struc in which yu declared the composed <Image,String> type ^^
    import java.awt.image.BufferedImage;
    import java.io.ByteArrayInputStream;
    import java.io.InputStream;
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import javafx.application.Application;
    import javafx.event.Event;
    import javafx.event.EventHandler;
    import javafx.scene.Scene;
    import javafx.scene.control.ComboBox;
    import javafx.scene.image.Image;
    import javafx.scene.image.ImageView;
    import javafx.scene.layout.StackPane;
    import javafx.stage.Stage;
    import javax.swing.JOptionPane;
    * @author Minedun6
    public class DynamicCustomComboBox extends Application {
        Connection c = connection.ConnecrDb();
       PreparedStatement pst = null;
       ResultSet rs = null;
       ComboBox box1;
       ImageView view;
        @Override
        public void start(Stage primaryStage) {
            box1 = new ComboBox();
            box1.setPrefSize(100, 25);
            box1.setOnShowing(new EventHandler() {
                @Override
                public void handle(Event t) {
                    box1.getItems().clear();
                    try {
                String sql = "select libelle_constr,img_constructeur from constructeurs where libelle_constr='Citroen';";
                pst = c.prepareStatement(sql);
                rs = pst.executeQuery();
               while(rs.next()){
                   box1.getItems().add(rs.getString("libelle_constr"));
                   InputStream input = new ByteArrayInputStream(rs.getBytes("img_constructeur"));
                   Image imge = new Image(input);
                   view.setImage(imge);
            } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e);
            StackPane root = new StackPane();
            root.getChildren().addAll(box1);
            Scene scene = new Scene(root, 300, 250);
            primaryStage.setTitle("Hello World!");
            primaryStage.setScene(scene);
            primaryStage.show();
        public static void main(String[] args) {
            launch(args);
    }

    In any real application, it's a mistake to mix your presentation (user interface) code with your persistance (database access) code.
    Why? You want maintainability, flexibility, and testability.
    Maintainability:
    Suppose you want to change the structure of your database. E.g. the database admin (which may be you, or someone else) determines that the database design you have is inefficient and needs to be changed. If your database code is scattered over the whole application, mixed in among your user interface code, tracking down what needs to be changed will be a nightmare. If all your database code is in a single class, or perhaps a set of classes in a single package, then the updates are localized and much easier to manage. Furthermore, you can build the new database access code on its own, test it out, and then when you are sure it works just switch your user interface code to use the new persistance layer instead of the old one. The same applies if you decide you're going to use a completely different technology to store the data; perhaps you want to use something like Hibernate instead of plain JDBC, or maybe you decide you want to make the data accessibile via a web service.
    Flexibility:
    What if you (or, more likely, your manager) decides they're going to change to a new user interface technology. Maybe they decide to switch to a web application (i.e. HTML-based) instead of a desktop application. You obviously need to rewrite the user interface code, but you should be able to keep all the database access code you've written. If your database access code is all jumbled up with the user interface code you're replacing, it's going to be way harder to reuse that code. If the two are separated out, you just build a new user interface in whatever new technology you're using, and access the same class(es) you used for your database access without touching them.
    Testability:
    This whole thread is actually a demo of how testability is much harder if you don't properly separate your code. You posted "getting image stored in database", thinking that was your problem. It wasn't; your problem was actually an error in the way you'd set up your JavaFX code. Because the two were completely mixed together, it was hard to know where the error was. The error you had was actually a really simple one; it would have been much easier to see if you had simpler, properly separated code; but because you didn't organize your code like that it took you days to figure out the problem. This was only a couple of dozen lines of code; imagine how this looks in a real application with hundreds or thousands of classes.
    The point is that decisions about how to access your data (standalone database, web service, or EJB?; plain JDBC, JPA, Hibernate, etc?) , and decisions about the presentation technology (desktop or web? JavaFX or Swing?, or Servlets/JSPs, JSF, Swing MVC, or any of a huge number of frameworks) are completely independent. You should be in a position to change those decisions - to redesign aspects of the application - with the least amount of effort possible. Failing to properly design things will make this much harder, or likely completely impossible.
    These are real concerns that affect every application that goes into production.
    Even if you're just making a small application, it will benefit you to set things up correctly from the outset.

Maybe you are looking for

  • Record all the data acquired by DAQ

    Hi all, I have a problem when I tried to record all the data acquired by the DAQ card. My DAQ is NI 6259, and the Labview version is 2009. Basically, what I need do is using multiple channels to get the voltages of different point, then I subtract va

  • HELP! I had a duplicate contact added to my iPhone 1390 times!!!!

    I have an iPhone 3gs (yes, I'm still living in the past), I have multiple contacts that randomly get added to my list of contacts. "Random" because it is mostly not even people I contact at ALL, by email or phone. Some of the contacts are only people

  • Error Installing 10g on Windows XP

    hello all.. Iam installing ORacle10g on WinXP. After selecting the Installation type as " Personal Edition" option, i get an error message " Thrown when the ip address of the host cannnot be determined" and it gives me 4 options.. Retry, cancel, help

  • SSIS and XML Data Files

    Hello, everyone. As a SSIS newbie, I have a simple question about load XML data files with SSIS. Currently I have multiple XML files in a specified folder (C:\XMLData) using one XSD file. Since SSIS does not support expression language for XML Source

  • Help needed with ejbFindByPrimaryKey

    Hi, is the container supposed to ALWAYS call ejbFindByPrimaryKey when I call findByPrimaryKey on the home interface? My weblogic is not doing it if I created the bean (BMP) in the same transaction, it just returns the bean and therefore I can't run t