Bonjour,
J'aimerais transformer une variable int en byte. Comment faire ?
J'ai tente :
int c;
byte[][][] x;
x[1][1][1]=(byte)c;
mais mon programme ne marche pas.
Comment faire ?
Bonjour,
J'aimerais transformer une variable int en byte. Comment faire ?
J'ai tente :
int c;
byte[][][] x;
x[1][1][1]=(byte)c;
mais mon programme ne marche pas.
Comment faire ?
salut,
Déja tu n'initialise pas ton tableau dynamiquement, ni ton entier :
Ensuite, il faut utiliser la fonction de Integer byteValue() :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 int c=1; byte[][][] x=new byte[taille1][taille2][taille3];
Bye
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 byte[1][1][1]=new Integer(c).byteValue();
Fred
ca marche pas non plus, mon probleme vient d'autre part peut etre ...
Mon programme ne m'affiche pas d'erreur il est juste en train de reflechir eternellement.
si jet mets x[1][1][1]=(byte)0xff; ca marche.
en revanche avec
short[][][] voxels;
x[1][1][1]=(byte)voxels[1][1][1];
mon programme ne s'acheve pas.
Devrais je renommer short[][][] voxels; par
byte[][][] voxels ;????
Des idees ? Quelles sont mes erreurs ?
es-tu sur que tu n'as pas d'exception levée ?
Pourrais tu poster ta classe entiere ?
merci
Fred
j'ai pas lu le topic mais je pense que tout ce dont tu as besoin se trouve ici :
http://gfx.developpez.com/tutoriel/java/binaire/
mavina j'apprecie ton aide et voici les classes utiles de mon programme :
Voici la classe RegionGrowing :
C'est dans cette classe que certains pixels vont etre selectionne suivant un critere. Ces pixels sont selectionnes parmi les pixels crees dans la classe VoxelkData :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 public class RegionGrowing { /** Source pixels */ protected static short[][][] srcPixels = null; public VoxelData Voxelsrc; /** Value of a member pixel in output image */ public final static byte MARKER = (byte) 0xff; /** Value of background (not member) pixel in output image */ public final static byte BACKGROUND = (byte) 0x00; //marker= -1 not member=1 BACKGROUND=0 /** * Used to mark pixels that were determined to not be members. This value is * changed to BACKGROUND in the output image. */ protected final static byte NOT_MEMBER = (byte) 0x01; /** Pixels of the destibation image */ protected byte[][] destPixels = null; protected byte[][][] destVoxels =null; final protected void checkForGrow(int x, int y, int z) { if (x < xMin || x >= xMax || y < yMin || y >= yMax || z < zMin || z >= zMax) { return; } int value = this.Voxelsrc.getSample(x,y,z); if (value >= valueMin && value < valueMax) { destVoxels[x][y][z] =new Integer(this.Voxelsrc.getSample(x,y,z)).byteValue();//MARKER;//(byte) this.Voxelsrc.getSample(x,y,z);//MARKER; // System.out.println("value ok= "+value); candidatePoints.addLast(new Voxel(x,y,z)); } else { destVoxels[x][y][z] = NOT_MEMBER; } } else { //System.out.println("(this.Voxelsrc.getSample(x,y,z)= "+(this.Voxelsrc.getSample(x,y,z))); } }
J'ai vire le superflus : j'espere avoir ete assez clair .
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78 package src.testproject; import java.io.*; import java.awt.image.*; import javax.swing.*; import java.awt.*; public class VoxelData extends javax.swing.JFrame { /** * This is the 3D byte array of sample values that have been successfully converted * to the correct range of values for the sample. * NOTE: They may not need to be converted because I am not viewing them * yet straight. * */ private short[][][] voxels; private byte[][][] bytes; private String str_datasetPath="C:/Etudes/DCU/ee593 Telecom project/3dVisualisation/Help from Vincent/0017384_s"; //Give the path to the dataset private javax.swing.JLabel jLabelSlice; private javax.swing.JSlider jSlider1; private InputStream in; private short widthInVoxels; private short heightInVoxels; private short depthInVoxels; private short maxDensityValue; private short minDensityValue; private int int_nbByteImage; private int int_ColorRange; private float voxelWidth ; //mm per voxel on x private float voxelHeight; //mm per voxel on y private float voxelDepth; private int check; private BufferedImage ScanImage; //Constructor public VoxelData() { initComponents(); // displaySlice(1); } private void initComponents() {// //[rows][columns][slices] voxels = new short[widthInVoxels][heightInVoxels][ depthInVoxels]; //We use twice the number of columns cause we need two bytes for each voxel,hence the volume will be twice the width. bytes = new byte[depthInVoxels][heightInVoxels][2*widthInVoxels ]; for(int z=0;z<depthInVoxels;z++) // for(int z=0;z<60;z++) { for(int y=0; y<heightInVoxels; y++) { check=in.read(bytes[z][y]); for(int x=0;x<widthInVoxels;x++) { //Converts 2 bytes to a short. Each short is in the range -1024 -> +2048 //This file reading process takes 11secs. Could leave the voxels as //bytes to speed up the reading process to 1sec.Leave out this loop to do so. voxels[x][y][z]=(short)((bytes[z][y][2*x]<<8)|((bytes[z][y][(2*x)+1])& 0xff)); // System.out.println("voxels= "+voxels[x][y][z]+"bytes= "+((bytes[z][y][2*x]<<8)|((bytes[z][y][(2*x)+1])& 0xff))); /* int int_vox = (readShort()-minDensity)*255/(maxDensity-minDensity); //convert the voxel value into a range from 0 to 255 //The int_vox is ANDed with a hex value,then shifted left by two bytes, then ORed with the other values. //This method of shifting and masking is a good way of separating the different bytes in an int or float etc. int int_hex = 0xff000000 | ((int_vox & 0x000000ff) << 16) | ((int_vox & 0x000000ff) << 8) | (int_vox & 0x000000ff); */ } } } public int getSample( int row, int column, int slice ){ return(this.voxels[row][column][slice]);
Pourquoi j'obtiens pas de reponse ? est ce que mon poste etait trop long ?
Je ne sais pas si tu as résolu ta question mais par rapport à ce post, juste une remarque.Envoyé par Battosaiii
Deja tes tableaux short[][][] voxels et x[1][1][1] sont des objets Java donc ton cast ne va surement pas marcher (normalement avec eclipse il te signale cette erreur)
donc pour transformer ton tableau de short en tableau de byte, il faut le faire element par element, avec un parcours de ton tableau
voila en esperant que ça te depanne
Partager