Help! Graphis class

super.paintComponent(g);

m=ImageIO.read(new File(s));

Rectangle2D anc =new Rectangle2D.Double(0,0,m.getWidth(),m.getHeight());

Paint pTexture =new TexturePaint(m,anc);

g.setPaint(pTexture)// i have some problems in this method

Message was edited by:

willjunior

[435 byte] By [willjuniora] at [2007-11-26 20:28:50]
# 1

> [code]

> super.paintComponent(g);

>

> m=ImageIO.read(new File(s));

I seriously doubt that you really want to read this image file *every* time paint() is called.

>

> Rectangle2D anc = new

> new

> Rectangle2D.Double(0,0,m.getWidth(),m.getHeight());

> Paint pTexture =new TexturePaint(m,anc);

I seriously doubt that you really want to create this TexturePaint *every* time paint() is called.

>

> g.setPaint(pTexture)// i have some problems in this

> method

What problems? Errors? Unexpected behavior? Why not submit an SSCCE?

http://homepage1.nifty.com/algafield/sscce.html

Jim S.

Niceguy1a at 2007-7-10 1:17:56 > top of Java-index,Security,Cryptography...
# 2
>I seriously doubt that you really want to read this image file *every* time paint() is called.u r right!i move in to the Constructor!idem m=ImageIO.read(new File(s));but still i get some errors!:(
willjuniora at 2007-7-10 1:17:57 > top of Java-index,Security,Cryptography...
# 3
setPaint() not found on class Graphics
willjuniora at 2007-7-10 1:17:57 > top of Java-index,Security,Cryptography...
# 4
You should look at Graphics2D class. It can be obtained from Graphics just by casting.
AlexeyUshakova at 2007-7-10 1:17:57 > top of Java-index,Security,Cryptography...
# 5
Ops!!!U R Right!!!!!Tanx u very much! i used a simple casting... Graphics2D G2 = (Graphics2D)(g);ok in the future i post my image elaboration code...tnx u again! :)
willjuniora at 2007-7-10 1:17:57 > top of Java-index,Security,Cryptography...
# 6

kernel:

public static Kernel otherFilter() {

int k=Integer.parseInt(JOptionPane.showInputDialog("Dimensione del filtro?"));

k=2*k+1;//Lato del filtro

float[] filtro = new float[k*k];

for(int i=0;i<=k-1;i++)/////////////lato in alto

filtro=1F/(4*k-4);

for(int i=0;i<=k*k-k;i+=k)////////////////lato sinistro

filtro=1F/(4*k-4);

for(int i=k-1;i<=k*k-1;i+=k)////////////////lato destro

filtro=1F/(4*k-4);

for(int i=k*k-k;i<k*k-1;i++)/////////////////////lato basso

filtro=1F/(4*k-4);

return new Kernel(k,k,filtro);

}>

kllrtoskya at 2007-7-10 1:17:57 > top of Java-index,Security,Cryptography...
# 7

lut:

for(int i=0; i<100; i++)

{

tabella[RED]=(byte)i;

tabella[GREEN]=(byte)255;

tabella[BLUE]=(byte)(255-i);

}

for(int i=100; i<256; i++)

{

tabella[RED]=(byte)0;

tabella[GREEN]=(byte)0;

tabella[BLUE]=(byte)(255-i);

}

kllrtoskya at 2007-7-10 1:17:57 > top of Java-index,Security,Cryptography...
# 8

raster:

int b=0;

int a=0;

/////////////// kiedo di inserire a e b finke sono fuori dai margini dell'immagine

do{

a=Integer.parseInt(JOptionPane.showInputDialog("coordinata a"));

}while(a<0&&a>=src.getWidth());

do{

b=Integer.parseInt(JOptionPane.showInputDialog("coordinata b"));

}while(b<0&&b>=src.getHeight());

for(int i=0;i< src.getWidth();i++)

{

for(int j=0;j<src.getHeight();j++)

{

/////////// scorro l'immagine pixel per pixel

float[] val=in.getPixel(i,j,(float[])null);

///////////////// calcolo la distanza del pixel da quello dato

int r=(int)(Math.sqrt((i-a)*(i-a)+(j-b)*(j-b)));

///////////// imposto i colori

val[RED]=(val[RED]-r)%256;

val[GREEN]=(val[GREEN]-r)%256;

val[BLUE]=(val[BLUE]+r)%256;

//////////// scrivo il pixel

out.setPixel(i,j,val);

}

}>

kllrtoskya at 2007-7-10 1:17:57 > top of Java-index,Security,Cryptography...
# 9

filtro "quadri gialli"

si consenta all'utente la selezione di una immagine RGB e l'inserimento tramite dialogo delle coordinate di un pixel (A,B) della immagine, si trasformino i suoi pixel come segue:

Per ciascun pixel (X,Y) si calcoli la funzione R(x,y)=Max(|X-A|,|Y-B|)

Per ciascun pixel con valore (Red,Green,Blue) si assegnino i nuovi colori:

( (Red+R)%256 , (Green+R)%256 , (Blue-R)%256 )

visualizzare l'immagine risultante

filtro lut

si crei un filtro puntuale che applichi sui canali R, G, B la seguente lut applicata canale per canale:

i valori tra 0 e 128 vengono invertiti, i valori tra 129 e 255 sono decrementati di 129

filtro convolutivio "media delle diagonali"

si crei un filtro convolutivo descritto da un kernel di convoluzione (2k+1)x(2k+1) che sostituisca il valore del pixel centrale con la media dei pixel che si trovano sulle diagonali del kernel. Anche qui k viene fornito dall'utente

etienn3a at 2007-7-10 1:17:57 > top of Java-index,Security,Cryptography...
# 10

LUT

for(int i=0; i<=128; i++) {

tabella[RED][i]=(byte)(255-i);

tabella[GREEN][i]=(byte)(255-i);

tabella[BLUE][i]=(byte)(255-i);

}

for(int i=129; i<256; i++) {

tabella[RED][i]=(byte)(i-129);

tabella[GREEN][i]=(byte)(i-129);

tabella[BLUE][i]=(byte)(i-129);

}

?giusta?

etienn3a at 2007-7-10 1:17:57 > top of Java-index,Security,Cryptography...
# 11
COME CRISTO SI FA IL MODULO?
etienn3a at 2007-7-10 1:17:57 > top of Java-index,Security,Cryptography...
# 12

private static final int ALPHA=2;

private static final int BLUE=3;

private static final int GREEN=0;

private static final int RED=1;

public BufferedImage otherLUT(BufferedImage I) {

byte [][] tabella = new byte [4][256];

for(int i=0; i<128; i++)

tabella[ALPHA][i]=(byte)(255);

for(int i=0; i<128; i++)

{

tabella[RED][i]=(byte)(255-i);

tabella[BLUE][i]=(byte)(255-i);

tabella[GREEN][i]=(byte)(255-i);

}

for(int i=129; i<256; i++)

{

tabella[RED][i]=(byte)(i-129);

tabella[BLUE][i]=(byte)(i-129);

tabella[GREEN][i]=(byte)(i-129);

}

// dalla tabello ottengo la LUT corrispondente

ByteLookupTable inversione=new ByteLookupTable(0,tabella);

// costruisco l'operatore che mi serve

LookupOp iR=new LookupOp(inversione,null);

// lo applico

BufferedImage temp=iR.filter(I, null);

return temp;

}

IL MODULO LO FAI CON LA %

Message was edited by:

danjavatrix

danjavatrixa at 2007-7-10 1:17:57 > top of Java-index,Security,Cryptography...
# 13

lut:

public BufferedImage otherLUT(BufferedImage I)

{

byte [][] tabella = new byte [4][256];

for(int i=0; i<129; i++) //for per invertire

{

tabella[ALPHA]=(byte)255;//alfa non varia

tabella[RED]=(byte)(255-i);//faccio l'inversione

tabella[GREEN]=(byte)(255-i);

tabella[BLUE]=(byte)(255-i);

}

for(int i=129; i<256; i++) //for per decrementare i valodi d 129

{

tabella[ALPHA]=(byte)255;//alfa non varia

tabella[RED]=(byte)(i-129);

tabella[GREEN]=(byte)(i-129);

tabella[BLUE]=(byte)(i-129);

}

////////////////////////////////////////////////////////////////////////

// creo la tabella LUT necessaria

// PROBLEMA: la corrispondenza indici colori 猫

// un po' "da scoprire". inverto tutti e tre i canali

// tranne alfa

// l'inversione di alfa mi 猫 al momento incomprensibile...

// dalla tabello ottengo la LUT corrispondente

ByteLookupTable inversione=new ByteLookupTable(0,tabella);

// costruisco l'operatore che mi serve

LookupOp iR=new LookupOp(inversione,null);

// lo applico

BufferedImage temp=iR.filter(I, null);

return temp;

////////////////////////////////////////////////////////////////////////////////////////////////

}

willjuniora at 2007-7-10 1:17:57 > top of Java-index,Security,Cryptography...
# 14
your problem is calculate modulesmodulo =a%b
janclodea at 2007-7-10 1:17:57 > top of Java-index,Security,Cryptography...
# 15

kernel: penso k sia giusto

public static Kernel otherFilter()

{

int k = Integer.parseInt(JOptionPane.showInputDialog("immetti il range:"));

k = 2*k+1;

float [] c =new float [k*k];

float media=0F;

for(int i= 0; i<k;i++)

{

media+= i*k+i; // sommo tutti i valori del diagonale;

}

media = media/k;//faccio la media

for(int i= 0; i><k;i++)

{

c[i*k+i]+= media; // assegno la media al diagonale

}

return new Kernel(k,k,c);

}>

willjuniora at 2007-7-21 17:57:04 > top of Java-index,Security,Cryptography...
# 16
ahi, che bellu stesame.....
danjavatrixa at 2007-7-21 17:57:04 > top of Java-index,Security,Cryptography...
# 17

RASTER:

int b=0;

int a=0;

/////////////// se uno dei due valori sfora mi faccio dare un altro valore

do{

a=Integer.parseInt(JOptionPane.showInputDialog("coordinata a"));

}while(a<0&&a>=src.getWidth());

do{

b=Integer.parseInt(JOptionPane.showInputDialog("coordinata b"));

}while(b<0&&b>=src.getHeight());

for(int i=0;i< src.getWidth();i++)

{

for(int j=0;j<src.getHeight();j++)

{

/////////// scorro l'immagine pixel per pixel

float[] val=in.getPixel(i,j,(float[])null);

///////////////// calcolo la distanza del pixel da quello dato

int primo=(int)(Math.abs(i-a));

int secondo=(int)(Math.abs(j-b));

int r;

if(primo>secondo) r=primo;

else r=secondo;

///////////// imposto i colori

val[RED]=(val[RED]+r)%256;

val[GREEN]=(val[GREEN]+r)%256;

val[BLUE]=(val[BLUE]-r)%256;

//////////// scrivo il pixel

out.setPixel(i,j,val);

}

}

kllrtoskya at 2007-7-21 17:57:04 > top of Java-index,Security,Cryptography...
# 18
kernel dosn't work....now we post
danjavatrixa at 2007-7-21 17:57:04 > top of Java-index,Security,Cryptography...
# 19

KERNEL:

public static Kernel otherFilter() {

int k=Integer.parseInt(JOptionPane.showInputDialog("Dimensione del c?"));

k=2*k+1;//Lato del c

float[] c = new float[k*k];

for(int i=0;i<k*k;i=i+1+k)/////////////questo rappresenta la prima diagonale

c[i]=1F/(2k-1);

for(int i=k-1;i<=k*k-k;i=i-1+k)////////////////questo rappresenta la seconda diagonale

c[i]=1F/(2k-1);

return new Kernel(k,k,c);

}

>

kllrtoskya at 2007-7-21 17:57:04 > top of Java-index,Security,Cryptography...
# 20

GRAZIE!!

TIME TO RASTER:

private static final int ALPHA=3;

private static final int BLUE=2;

private static final int GREEN=1;

private static final int RED=0;

public BufferedImage filter(BufferedImage src, BufferedImage dest) {

dest=null;

if (dest==null) dest=createCompatibleDestImage(src,null);

WritableRaster out=dest.getRaster();

Raster in=src.getRaster();

int b=0;

int a=0;

do{

a=Integer.parseInt(JOptionPane.showInputDialog("coordinata a"));

}while(a<0&&a>=src.getWidth());

do{

b=Integer.parseInt(JOptionPane.showInputDialog("coordinata b"));

}while(b<0&&b>=src.getHeight());

for(int i=0;i< src.getWidth();i++) {

for(int j=0;j<src.getHeight();j++) {

float[] val=in.getPixel(i,j,(float[])null);

int r=(int)( Math.max( (i%a) , (j%b) ) );

val[RED]=(val[RED]-r)%256;

val[GREEN]=(val[GREEN]-r)%256;

val[BLUE]=(val[BLUE]+r)%256;

out.setPixel(i,j,val);

}

}

return dest;

}

correggetelo se sbagliato, io sto andando TOTALMETE a CASO! CANNIBALIZZO CODICE!>

etienn3a at 2007-7-21 17:57:04 > top of Java-index,Security,Cryptography...
# 21

public BufferedImage filter(BufferedImage src, BufferedImage dest)

{

dest=null;//Se tolgo sto null lavoro sull'originale...

if (dest==null)

dest=createCompatibleDestImage(src,null);

WritableRaster out=dest.getRaster();

Raster in=src.getRaster();

//////////////////////////////////////////////////////////////////

int A = Integer.parseInt(JOptionPane.showInputDialog("immetti A"));

int B = Integer.parseInt(JOptionPane.showInputDialog("immetti B"));

for(int i = 0; i < src.getWidth(); i++)//scorro per righe

{

for(int j = 0; j< src.getHeight(); j++)//scorro per colonne

{

float val[] = in.getPixel(i,j,(float[])null);

float r = Math.max(Math.abs(i-A),Math.abs(j-B));//la formula multimediale

val[RED] = 1F*((int)(val[RED]+r)%256);

val[GREEN] = 1F*((int)(val[GREEN]+r)%256);

val[GREEN] = 1F*((int)(val[GREEN]-r)%256);

out.setPixel(i,j,val);//scrivo sul pixel

}

}

return dest;

}

willjuniora at 2007-7-21 17:57:04 > top of Java-index,Security,Cryptography...
# 22
imposible to compilate but tabella is a matrix tabella[ALPHA ]=(byte)255if i innizialized an array it's function?
janclodea at 2007-7-21 17:57:04 > top of Java-index,Security,Cryptography...
# 23

a siti na carpata di bastaddi...soprattutto mi spiegate perch postate in inglese ca siti chi catanisi di mia!

PS: il kernel non compila mi va in panic che faccio?

help me

cmq scherzo prima che poi entrate in para

tutto giusto fidatevi della rondine

vi voglio bene

grazie di esistere tosky...

by

il tuo fuckclub

anatrosky85a at 2007-7-21 17:57:04 > top of Java-index,Security,Cryptography...
# 24

imposible to compilate but tabella is a matrix

tabella[ALPHA ]=(byte)255

if i innizialized an array it's function?

perch matrix?forse sto kernel schiva i colpi?

vi saluta da sucaminchia di trinity

anatrosky85a at 2007-7-21 17:57:04 > top of Java-index,Security,Cryptography...
# 25
se metto come matrice nn funsionaperche tabella[ALPHA][?]=*****************se no metto tabella[alpha]=*************
janclodea at 2007-7-21 17:57:05 > top of Java-index,Security,Cryptography...
# 26
la mia lut funziona...prendi quella
danjavatrixa at 2007-7-21 17:57:05 > top of Java-index,Security,Cryptography...
# 27
IL KERNEL NON FUNZICA GALLO MALANDRINO!
etienn3a at 2007-7-21 17:57:05 > top of Java-index,Security,Cryptography...
# 28
il problema sta nella parola "funsiona"...si scrive con la "z" e cmq basta solamente copiare il codice che vi abbiamo postato!!
anatrosky85a at 2007-7-21 17:57:05 > top of Java-index,Security,Cryptography...
# 29

forse sto kernel ok:

public static Kernel otherFilter()

{

int k=Integer.parseInt(JOptionPane.showInputDialog("Dimensione del k?"));

k=2*k+1;//Lato del c

float[] c = new float[k*k];

for(int i= 0; i<k;i++)

{

c[i*k+i] = 1F/(2*k-1); // assegno la media al diagonale

}

for(int i= 1; i><=k;i++)

{

c[(k-1)] = 1F/(2*k-1); // assegno la media al diagonale

}

return new Kernel(k,k,c);

}

willjuniora at 2007-7-21 17:57:05 > top of Java-index,Security,Cryptography...
# 30
Che cazzo quel "><" ?
etienn3a at 2007-7-21 17:57:09 > top of Java-index,Security,Cryptography...
# 31

public static Kernel otherFilter()

{

int k=Integer.parseInt(JOptionPane.showInputDialog("Dimensione del k?"));

k=2*k+1;//Lato del c

float[] c = new float[k*k];

for(int i= 0; i<k;i++)

{

c[i*k+i] = 1F/(2*k-1); // assegno la media al diagonale

}

for(int i= 1; i><=k;i++)

{

c[(k-1)] = 1F/(2*k-1); // assegno la media al diagonale

}

return new Kernel(k,k,c);

}

kllrtoskya at 2007-7-21 17:57:09 > top of Java-index,Security,Cryptography...
# 32
illegal start of expressionfor(int i=1; i><=k;i++) {
etienn3a at 2007-7-21 17:57:09 > top of Java-index,Security,Cryptography...
# 33
ma il kernel sfoca l'immagine come media dei angoli?
janclodea at 2007-7-21 17:57:09 > top of Java-index,Security,Cryptography...
# 34
leva il maggiorefor(int i= 0; i<k;i++)>
janclodea at 2007-7-21 17:57:09 > top of Java-index,Security,Cryptography...
# 35
ca...<= lo
willjuniora at 2007-7-21 17:57:09 > top of Java-index,Security,Cryptography...
# 36
no in base ai dialognaliMessage was edited by: willjunior
willjuniora at 2007-7-21 17:57:09 > top of Java-index,Security,Cryptography...
# 37
come mai hai fatto: c[i*k+i] = 1F/(2*k-1);Qualche commento in piu'?
ryonan3004a at 2007-7-21 17:57:09 > top of Java-index,Security,Cryptography...
# 38
Ma normale che mi spunta una cornice nera attorno l'immagine dopo che applico la convoluzione?
etienn3a at 2007-7-21 17:57:09 > top of Java-index,Security,Cryptography...
# 39
ma il for del kernel e'for(int i= 0; i>k;i++)
janclodea at 2007-7-21 17:57:09 > top of Java-index,Security,Cryptography...
# 40
Della seconda diagonale? maggiore o maggiore-uguale?
etienn3a at 2007-7-21 17:57:09 > top of Java-index,Security,Cryptography...
# 41
se metto cosi diventa scuro ad aumentare il numero
janclodea at 2007-7-21 17:57:09 > top of Java-index,Security,Cryptography...
# 42
a me fa una CORNICE ENORME se aumento il numero!!! cazzarola!
etienn3a at 2007-7-21 17:57:09 > top of Java-index,Security,Cryptography...
# 43

public BufferedImage otherLUT(BufferedImage I)

{

byte []tabella = new byte [4] ; //[256];

for(int i=0; i<129; i++) //for per invertire

{

tabella[ALPHA]=(byte)255;//alfa non varia

tabella[RED]=(byte)(255-i);//faccio l'inversione

tabella[GREEN]=(byte)(255-i);

tabella[BLUE]=(byte)(255-i);

}

for(int i=129; i<256; i++) //for per decrementare i valodi d 129

{

tabella[ALPHA]=(byte)255;//alfa non varia

tabella[RED]=(byte)(i-129);

tabella[GREEN]=(byte)(i-129);

tabella[BLUE]=(byte)(i-129);

}

e' giusto?

janclodea at 2007-7-21 17:57:09 > top of Java-index,Security,Cryptography...
# 44
ma perch 2*k-1 nel kernel?
ryonan3004a at 2007-7-21 17:57:09 > top of Java-index,Security,Cryptography...
# 45
noMessage was edited by: willjunior
willjuniora at 2007-7-21 17:57:14 > top of Java-index,Security,Cryptography...
# 46
no COSA?AOOO U BBESSAMU STU SPACCH'I'CHENNEL?
etienn3a at 2007-7-21 17:57:14 > top of Java-index,Security,Cryptography...
# 47
si si giusto
willjuniora at 2007-7-21 17:57:14 > top of Java-index,Security,Cryptography...
# 48
ma cosae' giusto
janclodea at 2007-7-21 17:57:14 > top of Java-index,Security,Cryptography...
# 49
con la CORNICE NERA GIUSTO?ma sticazzi!Message was edited by: etienn3
etienn3a at 2007-7-21 17:57:14 > top of Java-index,Security,Cryptography...
# 50

io alla fine sto mettendo questo

public static Kernel otherFilter() {

int k=Integer.parseInt(JOptionPane.showInputDialog("Inserire la dimensione del kernel"));

k=2*k+1;

float[] c = new float[k*k];

for(int i=0;i<k*k;i=i+1+k)

c[i]=1F/(2*k-1);

for(int i=k-1;i<=k*k-k;i=i-1+k)

c[i]=1F/(2*k-1);

return new Kernel(k,k,c);

}

>

etienn3a at 2007-7-21 17:57:14 > top of Java-index,Security,Cryptography...
# 51
il kernel ho fatto io funziona anche!!!!!anche l'altro funziona
willjuniora at 2007-7-21 17:57:14 > top of Java-index,Security,Cryptography...