开发者

dimming the alpha value of a pixel android

i'm trying to dim the alpha channel of individual pixels in a bitmap. i'd like to keep the pixels color rgb but just make the pixel semi transparent. i've looked at the Color class and tried the Color.argb(int,int,int,int) method, but no good. how can i just set the alpha of a pixel whilst keeping the pixel's original rgb as well?

thanks in advance mat.

[edit] lol terrapin:). hi, below is how i configure my bitmap. i have no underlying image if that's what you mean. what i'm trying to开发者_开发百科 do is basically make certain pixels half transparent. i have a bitmap and have placed a circle on the bitmap. i have the algorithim in place that only targets the pixels within the circle and i can change those pixels to say pink. what i'd like is check each pixel in the circle and make it smi transparent, still keeping half the original pixel colour, if that makes sense :)

 bgr.setPixel(i,y,Color.argb(50,255,255,255));

[edit]

BitmapFactory.Options bfo = new BitmapFactory.Options();
        bfo.inSampleSize = 1;

        bm = BitmapFactory.decodeByteArray(imageArray, 0, imageArray.length, bfo);
        bgr = Bitmap.createBitmap(bm.getWidth(), bm.getHeight(), bm.getConfig());
        bgr = bm.copy(bm.getConfig(), true);


Greetings Terrapin. Your code snippet looks right. Just two thoughts off the top of my head.
1) Are you sure your bitmap is in ARGB_8888 format? You might be getting another format by default, depending on the circumstances.
2) Alpha values are absolute (not percentages), so I think you want the first parameter to be 127, not 50.

Edit: Also, um, when you reduce the alpha you have to make sure you are drawing on top of a background that will show through in an effective way. Please let me know if I have addressed your issue or if you need more help (maybe we need to see more code).

Edit: I think the problem is that you have no background. If you reduce alpha and you're drawing on top of black, it will just make things look darker. In other words (127, 255, 255, 255) is comparable to (255, 127, 127, 127). I'm a live wallpaperer, so I'm always working with canvases. here's how I do something:
c.drawBitmap(sBG, 0, 0, null);
c.drawBitmap(sSprite, mWidth/2, mHeight/2, null);
sBG is a bitmap full of heiroglyphics that show through my "ghostly" sprite (sSprite has alpha ~127).
I just overlay the bitmaps in the canvas, and when I render the canvas, it's all good. :-)

Edit: Reducing the alpha is generally used to let something show through from behind. I think you need to determine exactly what you mean (mathematically) by "fade the color so that it looks a bit translucent." For example turning red into pink would mean mixing in white; that's equivalent to translucency with a white background (mixing in white is how you change saturated colors into pastels). I suggest playing around with GIMP or Photoshop (can adjust layer alphas) to determine what effect will best serve your needs, and then trying to replicate it in Android.

Edit: I thought it might "encourage" you to mention that these are tricky and hopefully interesting things you are grappling with. In computer graphics, sometimes we have to do things that are not necessarily intuitive to achieve a desired effect. I will argue that convincing translucency is non-trivial...requires using background objects, lighting, and/or animation. I don't know much about this specific effect, but here is one link you might enjoy: http://www.neilblevins.com/cg_education/translucency/translucency.htm
Something I do know a bit about is creating metallic textures. And there the trick is this: you almost always have to use reflections. This youtube video is a good demo: http://www.youtube.com/watch?v=k6ZiRNkbWPw
People who get really into this even opt for HDRi! E.g. look at the reflecting sphere here: http://en.wikibooks.org/wiki/Blender_3D:_Noob_to_Pro/HDRi

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜