ciao a tutti...
ho fatto questo metodo che restituisce una porzione di una immagine ed effettua delle operazioni su di essa: la ruota e le cambia il colore di alcuni pixel
funziona tutto: prende la porzione e la mette su computedImage...la ruota, ma non cambia i colori dei pixel. Ho messo un System.out.println("ok"); sull'if e vengono stampati, quindi il controllo funziona...codice:public BufferedImage getFrame() { Dimension dim = getFrameSize(); int w, h; w = (int) dim.getWidth(); h = (int) dim.getHeight(); //image to return BufferedImage computedFrame = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); //get the subimage BufferedImage subImage = getFilm().getSubimage(w*frame, 0, w, h); //apply the rotation AffineTransform transform = new AffineTransform(); //apply rotation around the centre of the image transform.setToRotation(getRotation(),w/2,h/2); AffineTransformOp rot= new AffineTransformOp(transform, AffineTransformOp.TYPE_BILINEAR ); Graphics2D g = (Graphics2D) computedFrame.createGraphics(); //draw the image rotated in the graphic context g.drawImage(subImage, rot, 0, 0); //now, i replace the color WritableRaster wr = computedFrame.getRaster(); //takes eah pixels as integers int [] pixels = wr.getPixels(0, 0, w, h, (int[])null); int [] newPixels = new int[pixels.length]; for(int i=0;i<pixels.length;i++) { if (getReplacedColor().equals(new Color(pixels[i]))) { newPixels[i] = getReplacerColor().getRGB(); } else { newPixels[i] = pixels[i]; } } wr.setPixels(0, 0,w,h, newPixels); computedFrame.setData(wr); return computedFrame; }
Comunque, il raster non cambia...
Ho provato a mettere tutti i newPixels ad un colore arbitrario, ma non funziona. Ovvero, se faccio
l'ultimo byte me lo prende come alfa, e i primi tre sembra che non li prenda e mi stampa un'immagine completamente bianca...codice:for(int i=0;i<pixels.length;i++) { newPixels[i] = 0x00FF00FF; }
dove sto sbagliando?

Rispondi quotando