Mikonyx
Messages postés76Date d'inscriptionjeudi 31 janvier 2002StatutMembreDernière intervention 1 septembre 2004
-
27 mars 2002 à 13:23
cs_Jo
Messages postés138Date d'inscriptionjeudi 24 août 2000StatutMembreDernière intervention 6 avril 2002
-
28 mars 2002 à 22:08
Salut!
Est-il possible de définir une couleur ki serait transparente pour une image....??merci
Miko
cs_Jo
Messages postés138Date d'inscriptionjeudi 24 août 2000StatutMembreDernière intervention 6 avril 2002 28 mars 2002 à 12:37
Salut,
Bon moi je viens de trouver ca sur mon disque dur, et ca devrait pouvoir t'aider:
Quelque note ki vont ave:
when Java's createImage method encounters a transparent colour in a gif. I solved this by manipulating the pixels in arrays (while cursing Netscape), and by passing the applet a value for a notional transparent pixel in the params.
int loadedimagewidth, loadedimageheight, // sizes of images...
mainpicwidth, mainpicheight, maskwidth, maskheight,
leftwidth, leftheight, rightwidth, rightheight,
pix[], // pixel array from loadedimage
m_pix[], b_pix[], //pixel arrays for mask, background,
l_pix[], r_pix[], //pixel arrays for left eye, right eye
m_pix_size; // size of m_pix (and b_pix) array
int lsocktlx=1000, lsocktly=1000, // offsets of eye sockets on mask
lsockbrx=-1, lsockbry=-1, // - left socket top left x etc.
rsocktlx=1000, rsocktly=1000, // - these values are temporary, the actual
rsockbrx=-1, rsockbry=-1; // - values are calculated in sockets()
int dpleft_topleft_x, dpleft_topleft_y, // offsets to topleft & botright x & y
dpleft_botright_x, dpleft_botright_y, // of left eye (l_pix) on drawpic.
dpright_topleft_x, dpright_topleft_y, // offsets to topleft & botright x & y
dpright_botright_x, dpright_botright_y; // of right eye (r_pix) on drawpic.
double DtoRfactor, wideH, highH, // for calculating eye movements
movewidth, moveheight, incx, incy; // in mouseDrag() and prepMath()
boolean got_params true, prepedMath false, // startup flags allLoaded false, allSetUp false, // startup flags animated false, dobounce false, // ongoing status flags
imageDone; // ongoing status flag
int leftx=0, lefty=0, rightx=0, righty=0, // for moving relative to eye-centres lx -9, ly -9, rx = -9, ry = -9, // copies above in buildImage() dragx -1, dragy -1; // old posns to test if changed by drag
public boolean imageUpdate(Image img, int infoflags,
int x, int y, int width, int height)
{
if ((infoflags & ImageObserver.ALLBITS) != 0)
{
imageDone = true;
return false;
}
else
return true;
}
private void pnlDraw()
{
if (pnlsetup && pnl.isVisible())
{
Graphics g = pnl.getGraphics();
g.drawImage(pnlimg, 1, 1, null);
}
}
reshape(0, 0, mainpicwidth, mainpicheight);
int i, j, k 0, mp_pix[] new int[mainpicwidth * mainpicheight];
for (i = 0; i < mainpicheight; i++)
for (j = mainpicwidth; j < (mainpicwidth+mainpicwidth); j++)
mp_pix[k++] = pix[i * loadedimagewidth + j];
for (i = 0; i < maskheight; i++)
for (j = 0; j < maskwidth; j++)
m_pix[k++] = pix[j + start + (i * loadedimagewidth)];
b_pix = new int[m_pix_size];// array for buildImage to lay bkgnd colour
// & eyes & mask on
buildMIS = new MemoryImageSource(maskwidth, maskheight, b_pix, 0, maskwidth);
sockets();
}
private void sockets()
{
// finds offsets of eye sockets on mask by looking for pixel values of 0
int i, j, k 0, l maskwidth/2;
for (i = 0; i < maskheight; i++)
{
for (j = 0; j < maskwidth; j++)
{
if (m_pix[k++] == 0)
{
if (j <= l)// left half
{
if (j < lsocktlx) lsocktlx = j;
if (i < lsocktly) lsocktly = i;
if (j > lsockbrx) lsockbrx = j;
if (i > lsockbry) lsockbry = i;
}
else // right half
{
if (j < rsocktlx) rsocktlx = j;
if (i < rsocktly) rsocktly = i;
if (j > rsockbrx) rsockbrx = j;
if (i > rsockbry) rsockbry = i;
}
}
}
}
}
for (i = 0; i < rightheight; i++)// copy eye pixels into r_pix array
for (j = 0; j < rightwidth; j++)
r_pix[k++] = pix[j + start + (i * loadedimagewidth)];
// offsets to topleft & botright x & y of eye (r_pix) on drawpic
dpright_topleft_x = righteye_middle_x - mask_topleft_x - (rightwidth/2);
dpright_topleft_y = righteye_middle_y - mask_topleft_y - (rightheight/2);
dpright_botright_x = dpright_topleft_x + rightwidth;
dpright_botright_y = dpright_topleft_y + rightheight;
}
private int findColor(String s)
{
int n, i;
Point p;
String t;
s = s.trim();
if (s.indexOf("none") != -1) return -1;
if (s.indexOf("black") != -1) return 0x000000; // (0, 0, 0);
if (s.indexOf("white") != -1) return 0xFFFFFF; // (255, 255, 255);
if (s.indexOf("red") != -1) return 0xFF0000; // (255, 0, 0);
if (s.indexOf("green") != -1) return 0x00FF00; // (0, 255, 0);
if (s.indexOf("blue") != -1) return 0x0000FF; // (0, 0, 255);
if (s.indexOf("dark") != -1) return 0x404040; // (64, 64, 64);
if (s.indexOf("light") != -1) return 0xC0C0C0; // (192, 192, 192);
if (s.indexOf("gray") != -1) return 0x808080; // (128, 128, 128);
if (s.indexOf("grey") != -1) return 0x808080; // (128, 128, 128);
if (s.indexOf("yellow") != -1) return 0xFFFF00; // (255, 255, 0);
if (s.indexOf("cyan") != -1) return 0x00FFFF; // (0, 255, 255);
if (s.indexOf("magenta") != -1) return 0xFF00FF; // (255, 0, 255);
if (s.indexOf("orange") != -1) return 0xFFC800; // (255, 200, 0);
if (s.indexOf("pink") != -1) return 0xFFAFAF; // (255, 175, 175);
if (s.indexOf("#") != -1)// if hex format #number
{
s = s.replace('#', ' ');
s = s.trim();
try {n = Integer.parseInt(s, 16);};
catch (NumberFormatException nfe) {n = -1;}
return n % 0x1000000;
}
i s.indexOf(","); if (i -1) return -1;
try {t = s.substring(0, i+1) + " 0";}
catch (StringIndexOutOfBoundsException e) {return -1;}
p = findPoint(t);
n = p.x << 16; // got red (p.y ignored)
try {t = s.substring(i+1);}
catch (StringIndexOutOfBoundsException e) {return -1;}
p = findPoint(t);
n += p.x << 8; // got green
n += p.y; // got blue
return n % 0x1000000;
}
private Point findPoint(String s)
{
int i, j, len = s.length(); String one "", two ""; boolean building false, building_one false, building_two = false;
char c;
for (i = 0; i < len; i++)
{
c = s.charAt(i);
if (Character.isDigit(c))
{
if (!building)
{
building = true;
if (building_one)
{
building_two = true;
two += String.valueOf(c);
}
else
{
building_one = true;
one += String.valueOf(c);
}
}
else
{
if (building_two)
two += String.valueOf(c);
else
one += String.valueOf(c);
}
}
else
{
building = false;
}
}
String s = "The Watcher Applet from";
String t = "donclark@powernet.co.uk";
Font gf = pnl.getFont();
boolean toobig = true;
Font f = null;
FontMetrics fm = null; int w, sw 0, tw 0, ps = 19;
while (toobig)
{ ps -1; if (ps 8) toobig = false;
f = new Font(gf.getName(), Font.PLAIN, ps);
pnl.setFont(f);
fm = pnl.getFontMetrics(f); sw fm.stringWidth(s); tw fm.stringWidth(t);
if (sw > tw) w sw; else w tw;
if (w < (pnlx - 4)) toobig = false;
}
int ma fm.getMaxAscent(), md fm.getMaxDescent(); int imgwidth pnlx - 2, imgheight (ma + md + 2) * 2;
pnly = imgheight + 2;
pnl.resize(pnlx, pnly);
pnl.move(2, mainpicheight-pnly-2);// allows for a 2 pixel border
// lposns[][] & rposns[][] store the left & right x & y posns for moving the
// eyes to centre [x][0] & [y][0], from start posns [x][bmo] & [y][bmo]. // bno bounce number total no. of posns, from 0,0 to start positions.
// bmo = bounce number minus one
dleftx leftx; dlefty lefty; drightx = rightx; drighty = righty;
Graphics g = getGraphics();
animated = true;
int steps, rep_count, rep_total;
for (steps = bmo; steps > 0; steps--) // do steps (number of bounce sequences)
{
if (!(lposns[0][steps]==0 && lposns[1][steps]==0 && // if(!...) block to
rposns[0][steps]==0 && rposns[1][steps]==0)) // skip non-movements
{
rep_total = 1; // as bounce gets smaller it is repeated
if (bounces < 3)
{ if ((bounces 2) && (steps 1)) rep_total = 2;
} else if ((steps 2) || (steps 3)) rep_total = 2; else if (steps 1) rep_total 3;
for (rep_count = 0; rep_count < rep_total; rep_count++) // do repeats
{
for (count = steps; count >= 0; count--) // move to centre
{
leftx=lposns[0][count]; lefty=lposns[1][count];
rightx=rposns[0][count]; righty=rposns[1][count];
paint(g);
}
for (count = 1; count < steps; count++)// move to other side
{
leftx=-lposns[0][count]; lefty=-lposns[1][count];
rightx=-rposns[0][count]; righty=-rposns[1][count];
paint(g);
}
for (count = steps; count >= 0 ; count--)// move to centre again
{
leftx=-lposns[0][count]; lefty=-lposns[1][count];
rightx=-rposns[0][count]; righty=-rposns[1][count];
paint(g);
}
for (count = 1; count < steps; count++)// move to original posn.
{
leftx=lposns[0][count]; lefty=lposns[1][count];
rightx=rposns[0][count]; righty=rposns[1][count];
paint(g);
}
}// end of repeats loop
}// end of if (posns not 0) block
}//end of steps loop
System.gc();
animated = false;
return;
}
public boolean mouseDown(Event evt, int x, int y)
{ dragx x; dragy y;
leftx=0; lefty=0;
rightx=0; righty=0;
lx = 1; // so that (lx != leftx) to make buildImage create new pic
animated = true;
paint(getGraphics());
requestFocus();
return true;
}
public boolean mouseUp(Event evt, int x, int y)
{ if ((dragx x) && (dragy y))
animated = false;
else
dobounce = true;