Visualizzazione dei risultati da 1 a 2 su 2

Discussione: Errore in compilazione

  1. #1

    Errore in compilazione

    Ho aperto un topic questo pomeriggio ma dato che non ho rispettato le regole chiedendo di potermi scrivere una funzione main mi è stato giustamente chiuso, chiedo scusa anzi per la mia poca attenzione al regolamento, vorrei allora provare a riformulare un dubbio che avevo già scritto lì e che credo non vada contro a nessuna regola... Devo scrivere una funzione main che utilizzi questi 4 sorgenti sotto descritti, ma prima ancora di scriverla mi trovo davanti ad una spaventosa constatazione: messo agli atti che i sorgenti sono INDUBBIAMENTE corretti, in quanto reperiti da un libro di testo abbastanza autorevole, bisogna purtroppo constatare che non si riesce a compilarli. Alcune loro funzioni sono protected dal package scritto dal manuale, che ho pensato bene di eliminare, rendendo pubbliche le funzioni; questo mi è servito per compilare due sorgenti, ma già al terzo riscontro di nuovo degli errori. Vi scrivo i sorgenti.

    Sono in tutto quattro file: StandardGreyOp.java, BinaryMorphologicalOp.java, BinaryDilateOp.java, BinaryErodeOp.java.

    BinaryDilateOp e BinaryErodeOp estendono BinaryMorphologicalOp, che a sua volta estende StandardGreyOp.

    StandardGreyOp
    codice:
    package com.pearsoneduc.ip.op;
    
    
    
    import java.awt.RenderingHints;
    import java.awt.geom.*;
    import java.awt.image.*;
    
    
    
    /**
     * Implements a BufferedImageOp for standard operations on 8-bit
     * greyscale images.  Subclasses should override the
     * {@link #filter(BufferedImage, RenderingHints) filter()} method
     * to carry out processing.
     *
     * @author Nick Efford
     * @version 1.1 [1999/07/23]
     */
    
    public class StandardGreyOp implements BufferedImageOp {
    
    
      /**
       * Performs an operation on an image.  Here, the operation is a
       * simple copy of source to destination.  Subclasses must override
       * this method to produce more interesting behaviour.
       * @param src source image
       * @param dest destination image, or null
       * @return destination image.
       */
    
      public BufferedImage filter(BufferedImage src, BufferedImage dest) {
        checkImage(src);
        if (dest == null)
          dest = createCompatibleDestImage(src, null);
        WritableRaster raster = dest.getRaster();
        src.copyData(raster);
        return dest;
      }
    
    
      /**
       * Creates a zeroed destination image with the same dimensions
       * and number of bands as the source image.
       * @param src source image
       * @param destModel ColorModel of the destination image
       *  (if null, ColorModel of the source image will be used)
       */
    
      public BufferedImage createCompatibleDestImage(BufferedImage src,
       ColorModel destModel) {
        if (destModel == null)
          destModel = src.getColorModel();
        int width = src.getWidth();
        int height = src.getHeight();
        BufferedImage image = new BufferedImage(destModel,
         destModel.createCompatibleWritableRaster(width, height),
         destModel.isAlphaPremultiplied(), null);
        return image;
      }
    
    
      /**
       * Determines bounding box of the destination image.  Here, it is
       * assumed that this is identical to that of the source image.
       * @param src source image
       * @return bounding box of the destination image.
       */
    
      public Rectangle2D getBounds2D(BufferedImage src) {
        return src.getRaster().getBounds();
      }
    
    
      /**
       * Given a point in the source image, determines the corresponding
       * point in the destination image.  Here, it is assumed that this
       * will be the same as the point in the source image.
       * @param srcPoint a point from the source image
       * @param destPoint a point in the destination image, or null
       * @return point in the destination image.
       */
    
      public Point2D getPoint2D(Point2D srcPoint, Point2D destPoint) {
        if (destPoint == null)
          destPoint = new Point2D.Float();
        destPoint.setLocation(srcPoint.getX(), srcPoint.getY());
        return destPoint;
      }
    
    
      /**
       * @return rendering hints for this operation.
       */
    
      public RenderingHints getRenderingHints() {
        return null;
      }
    
    
      /**
       * Tests that source image is suitable for processing.
       * @param src source image
       * @exception ImagingOpException if the source image is not an
       *  8-bit greyscale image.
       */
    
      public void checkImage(BufferedImage src) {
        if (src.getType() != BufferedImage.TYPE_BYTE_GRAY)
          throw new ImagingOpException("operation requires an 8-bit grey image");
      }
    
    
    }
    BinaryMorphologicalOp
    codice:
    package com.pearsoneduc.ip.op;
    
    
    
    import java.awt.image.*;
    
    
    
    /**
     * Adapts StandardGreyOp for binary morphological operations.
     * The method checkImage() is overridden to check that the source
     * image is either a true binary image or a greyscale image with
     * no more than two grey levels.
     *
     * @author Nick Efford
     * @version 1.0 [1999/08/30]
     */
    
    public class BinaryMorphologicalOp extends StandardGreyOp {
    
    
      /////////////////////////// INSTANCE VARIABLES ///////////////////////////
    
    
      /** Non-zero value assigned to pixels in the output image. */
      protected int nonZeroValue;
    
    
      //////////////////////////////// METHODS /////////////////////////////////
    
    
      /**
       * Checks that the image to be processed is of the correct type -
       * either a true binary image or a two-level 8-bit greyscale image
       * with 0 as one of the values.
       * @param image image to be processed
       * @exception ImagingOpException if the image is not of the correct type.
       */
    
      public void checkImage(BufferedImage image) {
        if (image.getType() == BufferedImage.TYPE_BYTE_BINARY)
          nonZeroValue = 1;
        else if (image.getType() == BufferedImage.TYPE_BYTE_GRAY) {
          nonZeroValue = 255;
          Raster raster = image.getRaster();
          int[] hist = new int[256];
          for (int y = 0; y < image.getHeight(); ++y)
            for (int x = 0; x < image.getWidth(); ++x)
              ++hist[raster.getSample(x, y, 0)];
          int n = 0;
          for (int i = 1; i < 256; ++i)
            if (hist[i] > 0) {
              ++n;
              if (n > 1)
                throw new ImagingOpException(
                 "image must be binary, or grey with <= one non-zero value");
            }
        }
        else
          throw new ImagingOpException("invalid image type");
      }
    
    
    }


    BinaryDilateOp
    codice:
    package com.pearsoneduc.ip.op;
    
    
    
    import java.awt.Point;
    import java.awt.image.*;
    
    
    
    /**
     * Performs the morphological operation of dilation on a binary image.
     * 'Binary image' is taken here to mean a greyscale image with just
     * two values, one of which is zero.
     *
     * @author Nick Efford
     * @version 1.0 [1999/08/30]
     */
    
    public class BinaryDilateOp extends BinaryMorphologicalOp {
    
    
      /////////////////////////// INSTANCE VARIABLES ///////////////////////////
    
    
      /** Structuring element used to perform the dilation. */
      private BinaryStructElement structElement;
    
    
      //////////////////////////////// METHODS /////////////////////////////////
    
    
      /**
       * Creates a BinaryDilateOp that uses the specified structuring element.
       * @param element structuring element
       */
    
      public BinaryDilateOp(BinaryStructElement element) {
        structElement = element;
      }
    
    
      /**
       * Performs morphological dilation of a binary image.
       * @param src source image
       * @param dest destination image, or null
       * @return dilated image.
       */
    
      public BufferedImage filter(BufferedImage src, BufferedImage dest) {
    
        checkImage(src);
        if (dest == null)
          dest = createCompatibleDestImage(src, null);
    
        int w = src.getWidth();
        int h = src.getHeight();
        Raster srcRaster = src.getRaster();
        WritableRaster destRaster = dest.getRaster();
    
        // Determine range of pixels for which operation can be performed
    
        Point origin = structElement.getOrigin(null);
        int xmin = Math.max(origin.x, 0);
        int ymin = Math.max(origin.y, 0);
        int xmax = origin.x + w - structElement.getWidth();
        int ymax = origin.y + h - structElement.getHeight();
        xmax = Math.min(w-1, xmax);
        ymax = Math.min(h-1, ymax);
    
        // Intersect structuring element with source image
    
        for (int y = ymin; y <= ymax; ++y)
          for (int x = xmin; x <= xmax; ++x)
            if (structElement.hits(srcRaster, x, y))
              destRaster.setSample(x, y, 0, nonZeroValue);
    
        return dest;
    
      }
    
    
    }

    BinaryErodeOp
    codice:
    package com.pearsoneduc.ip.op;
    
    
    
    import java.awt.Point;
    import java.awt.image.*;
    
    
    
    /**
     * Performs the morphological operation of erosion on a binary image.
     * 'Binary image' is taken here to mean a greyscale image with just
     * two values, one of which is zero.
     *
     * @author Nick Efford
     * @version 1.0 [1999/08/30]
     */
    
    public class BinaryErodeOp extends BinaryMorphologicalOp {
    
    
      /////////////////////////// INSTANCE VARIABLES ///////////////////////////
    
    
      /** Structuring element used to perform the erosion. */
      private BinaryStructElement structElement;
    
    
      //////////////////////////////// METHODS /////////////////////////////////
    
    
      /**
       * Creates a BinaryErodeOp that uses the specified structuring element.
       * @param element structuring element
       */
    
      public BinaryErodeOp(BinaryStructElement element) {
        structElement = element;
      }
    
    
      /**
       * Performs morphological erosion of a binary image.
       * @param src source image
       * @param dest destination image, or null
       * @return eroded image.
       */
    
      public BufferedImage filter(BufferedImage src, BufferedImage dest) {
    
        checkImage(src);
        if (dest == null)
          dest = createCompatibleDestImage(src, null);
    
        int w = src.getWidth();
        int h = src.getHeight();
        Raster srcRaster = src.getRaster();
        WritableRaster destRaster = dest.getRaster();
    
        // Determine range of pixels for which operation can be performed
    
        Point origin = structElement.getOrigin(null);
        int xmin = Math.max(origin.x, 0);
        int ymin = Math.max(origin.y, 0);
        int xmax = origin.x + w - structElement.getWidth();
        int ymax = origin.y + h - structElement.getHeight();
        xmax = Math.min(w-1, xmax);
        ymax = Math.min(h-1, ymax);
    
        // Fit structuring element into source image
    
        for (int y = ymin; y <= ymax; ++y)
          for (int x = xmin; x <= xmax; ++x)
            if (structElement.fits(srcRaster, x, y))
              destRaster.setSample(x, y, 0, nonZeroValue);
    
        return dest;
    
      }
    
    
    }
    Quindi, in sostanza, qualcuno di voi saprebbe aiutarmi a capire perchè non riesco a compilarli?
    Togliendo il package il primo sorgente, StandardGreyOp.java, ed il secondo sorgente, BinaryMorphologicalOp, sono compilabili, e fin quì ok. Il terzo ed il quarto sorgente, che dovrebbero essere indipendenti l'uno dall'altro però mi danno questo errore:



    Eppure più lo guardo e meno capisco cos'è che non va... Voi che ne pensate?

  2. #2
    Utente di HTML.it L'avatar di Alex'87
    Registrato dal
    Aug 2001
    residenza
    Verona
    Messaggi
    5,802

    Re: Errore in compilazione

    Originariamente inviato da Gil1688


    Eppure più lo guardo e meno capisco cos'è che non va... Voi che ne pensate?
    Le classi sono nel package com.pearsoneduc.ip.op ma nel filesystem non sembra che tu abbia ricreato questa struttura (hai messo tutto nella cartella abc). Riguardati come funzionano i package
    SpringSource Certified Spring Professional | Pivotal Certified Enterprise Integration Specialist
    Di questo libro e degli altri (blog personale di recensioni libri) | ​NO M.P. TECNICI

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.