Link to home
Start Free TrialLog in
Avatar of OP
OP

asked on

How to make the image 70% transparent

hi all,
       would like to know how to make the .GIF(image only has black and white colur) 70% transparent for black and 100% transparent for white. heres my codes,

public int convertPixelToGray(int rgb)
{int grayShade4, grayShade5, grayShade6;
     int transparency=(rgb >> 24) & 0x50;
     int red  = (rgb >> 16) & 0x50;
     if (red <= 255)
     grayShade4 = 0;
          else
     grayShade4 = 77;
     int green = (rgb >> 8)  & 0x50;
     if (green <= 255)
     grayShade5 = 0;
          else
     grayShade5 = 77;
     int blue = rgb & 0x50;
     if (blue <= 255)
     grayShade6 = 0;
          else
     grayShade6 = 77;
return ( (transparency<< 24)|(grayShade4 << 16)|(grayShade5 << 8)|grayShade6);
}

dont know y, the image cant even be displayed. could anyone help me pls........
         
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of OP
OP

ASKER

i tried to implement this into my program but the outcome is 2 black box. is it because my program is an applet? i already extends Applet, how to extend RGBImageFilter???

pls pardon me, im still at the learning stage.

thank you.
The MyFilter class above already extends RGBFilter.
How are you currently using it?
Avatar of OP

ASKER

i used media tracker to call the image, then i use pixel grabber to convert the pixels into an array. but theres an error telling me that the method cant be applied because the definition is not correct.
Whats the exact error and what line does it refer to.
and how are you calling it?
Avatar of OP

ASKER

the error state,

applyAlpha(int[],int) in GrabberImage cannot be applied to (int)pixels[i]= applyAlpha(pixels[i]);
----------------------------------------------------------
i use the following method to call it,

public void init() {
          MediaTracker mt  = new MediaTracker(this);
          URL            url = getClass().getResource("copyright.gif");

          try {
               im = createImage((ImageProducer)url.getContent());
               mt.addImage(im, 0);
               mt.waitForID(0);
          }
          catch(Exception e) { e.printStackTrace(); }

          int[] pixels = new int[w*h];
          PixelGrabber pg = new PixelGrabber(im, 110, 5, w, h,
                                                       pixels, 0, w);
          try {
               pg.grabPixels();
          }
          catch(InterruptedException e) {
               e.printStackTrace();
          }
          for (int i=0; i<pixels.length; i++)
                  pixels[i]= applyAlpha(pixels[i]);
----------------------------------------------------------
and the following to display the image,

public void paint(Graphics g) {
          g.drawImage(im,0,0,this);
                 }
a. pixels[i]= applyAlpha(pixels[i]);

You have not supplied the alpha parameter.

b. the original image will still get displayd.
You need to create a new image with the modifid pixels if you want to see the changes.
Avatar of OP

ASKER

where do i apply the parameter?
Dear expert(s),

A request has been made to delete this Q in CS:
https://www.experts-exchange.com/questions/20406038/Please-delete-this-Question.html

Without a response in 72 hrs, a moderator will finalize this question by:

 - Saving this Q as a PAQ and refunding the points to the questionner

When you agree or disagree, please add a comment here.

Thank you.

modulo

Community Support Moderator
Experts Exchange
I disagree.
I have not only explained the problem with the current code, but have also suuplied an alternative filter.
Avatar of OP

ASKER

but i did not use the code you provided. the second set of codes that i listed was totally from my fren. and it was he who helped me solved the problem.

but thanks for the help, objects.

to moderators,
im willing to give objects the points he deserved. lets closed this with everyone being happy. but please delete this Question. thank you.


Hi OP,

It's ofcourse possible that multiple ways of coding lead to the same effect.
I'm glad you support objects comment, but I can't both delete a Q and have it answered.
One of the intentions of EE is to build a knowledge base of answered Q's for people to find a solution. This Q is even offering two !

modulo

Community Support Moderator
Experts Exchange
Avatar of OP

ASKER

dear moderator,
               i agree with you. but the codes i listed was from my fren whom wishes to have it deleted. i pasted it without asking his consent, its totally my fault. i dont mind the question being available, but would be grateful if you could delete the codes i pasted on 11/21/2002 08:28PM PST


other comments and Q are fine.

hope you understand. thank you.

lastly, how do i award objects points? thank you.
I've removed the code as it's already described by it's merits.

For awarding the points you can select the link "accept as answer" you'll see in the comment-line of objects comment.

OK ?

modulo

Community Support Moderator
Experts Exchange
Avatar of OP

ASKER

ok. thank you very much.
Avatar of OP

ASKER

thanks for your help, objects.