I'd like to ask you what does it do?
a = Color.alpha(pixel);
Is it geting transparency pixel?
And I'd like to ask what is it Dwaring Cache in Android?
Color.alpha get the value of the alpha channel. Android colors are ARGB, integer 32bits, 8 bits per channel. It takes the value of A and it shift this value to the right of 24. Something like
return pixel >>> 24;
Edit: alpha expresses the opacity of your color/pixel. Its range between 0, fully transparent and 255 fully opaque
Related
I am trying to define specific gray values in an image. In my application, I create empty bitmaps and generate different patterns on it afterwards(e.g. sinusodial 2D patterns with gray values from 0 - 255 or 0 -1).
In my pevious research I could only find this line of code, that was supposed to solve my poblem:
myBitmap.setPixel(x, y, Color.rgb(45, 127, 0));
But this only tells me how to work with colors, not with gray values.
Does anyone have an idea?
I don't know if there is a way to give an Android bitmap a backing store where each pixel is represented by one byte, but you certainly can set a pixel to gray by setting red, green, and blue values to the same:
int gray = 127; // 0-255
myBitmap.setPixel(x, y, Color.rgb(gray, gray, gray));
I am looking for iOS and Android library for (preferably) or algorithm that would help me to feather edges of the image in similar way how it is handled in Photoshop. The illustration below shows the desired effect of the algorithm. I am not interested feathering bounds of the image, just alpha edges. I have been searching for algorithm that can accomplish it for few days without luck. Any help will be appreciated.
Assuming that you have alpha channel (like on photo with transparent background) it seems that regular convultion blur matrix should satisfy you.
However instead of going through RGB channels - you should go through ALPHA channel only.
Check the blur filter here:
https://en.wikipedia.org/wiki/Kernel_%28image_processing%29
You are interested in box blur/gaussian blur. However to make this effect more smooth - you should use matrix of bigger size.
The reason that algorithm will satisfy your needs is that if all surrounding pixels have alpha 0 - it will be still 0. If 255 - it will stay 255. Just pixels in area of border between alpha 0/255 will be affected.
Edit:
Please check this fiddle with chrome (in ff that's really slow):
http://jsfiddle.net/5L40ms65/
You can take a look into algorithm in the end of code. Since implementation i noted that:
- no need to blur if all neigbour pixels are 255 or 0 (alpha channel)
- it is required to blur also RGB in other case
In general:
RADIUS = 2 (makes total width of matrix = 5)
For x = 0..width
for y = 0..width
if all pixels in square of radius 2 are alpha = 0
do nothing
elsif all pixels in square have alpha = 255
do nothing
else
pixel[x][y].RGB = average RGB of adjacent pixels where alpha != 0
pixel[x][y].ALPHA = average ALPHA in square
Example result with radius=2
Of course this is rather concept program, there is a lot of place for memoization and tuning this script however it should make a big picture clear
You could change the alpha of your border based on the background color of the view.
var r:Float!
var g:Float!
var b:Float!
var a:Float!
if self.view.backgroundColor.getRed(red:r, green:g, blue:b, alpha:a) {
var imgv = UIImageView(frame: CGRect(x:100, y:100, width:100, height:100))
imgv.image = UIImage(named:"name")
imgv.layer.borderWidth = 2.0
imgv.layer.borderColor = UIColor(red:r, green:g, blue:b, alpha:0.5).CGColor
imgv.layer.cornerRadius = imgv.frame.size.width / 2
imgv.clipsToBounds = true
}else{
//Could not get the RGB of background color
}
You may see errors in this code because I have not yet tested it.
I'm working on android's canvas view. I just want to know if this condition is valid semantically.
if(bitmap.getPixel(x,y) == Color.WHITE)
I logged the value of Color.WHITE by:
int white = Color.WHITE;
and this gave me the value of -1 and value of black color was -1633377 something.
I found the way of getting the value of any pixel in bitmap by getPixel() method and it returns an ARGB value. I've tried various ways to do this but none succeeded.Can you guys help me with this?
Thanks.
Please check here
The color's Alpha, Red, Green and Blue components are each stored on one byte (so values in [0-255]) and those 4 bytes are packed in a java "int" which is usually 4 bytes.
You get negative values because you use a signed int, in C++ you would use a unsigned int, but those are not available in Java, more info here
So to answer your question, yes your condition is valid semantically, -1 is the (signed) int value for 0xFFFFFFFF, and Black is not zero probably because this is opaque black, so with alpha=255 => 0xFF000000
I'm using Google Maps v2 API for android and I don't manage to control the transparency of the fillColor.
I would like to be able to see the map under a filled polygon.
Is there a way to do that ?
Thanks for any help !
Well, let me describe how standard 4 bytes color is encoded:
Standard pixel color consists of 4 bytes:
A (alpha channel) - 0-255 (0 - fully transparent, 255 - fully opaque)
R (red color channel) - 0-255
G (green color channel) - 0-255
B (blue color channel) - 0-255
Each channel represents the saturation of particular color part. So if we need to create fully opaque red color, we need to specify following channel values:
255,255,0,0
If we want to make it half-transparent, we need to divide alpha channel value by 2 (255/2 = 127):
127,255,0,0
So let's go back to the android. In Android in most cases you can specify color by specifying it's hex value:
polygon.setFillColor(0xFF00FF00); //not transparent green color
In hex every channel can be specified by 2 hex digits:
A(FF)
R(00)
G(FF)
B(00)
If you want to make this color half-transparent, you need to divide FF by 2:
0xFF/2 = 0x7F //the same as 255/2 = 127
polygon.setFillColor(0x7F00FF00); //half-transparent green color
So basically what you need to do - is to play with alpha channel value in order to get transparency you are looking for
cir=map.addCircle(new CircleOptions().center(new LatLng(10.938341, 76.9548734))
.radius(150)
.strokeColor(Color.rgb(0, 50, 100))
.strokeWidth(5)
.fillColor(Color.argb(20, 50, 0, 255))
.zIndex(55));
cir.setVisible(true);
Basically what worked for Me is :
polygon = mGoogleMap.addPolygon(new PolygonOptions().
addAll(points)
.fillColor(0x33FF0000)
.strokeColor(Color.RED)
.strokeWidth(3))
I am trying to run a denoising algorithm on a bitmap image that I have -- the function returns me a short[], so I tried simply casting it to int[] in order to generate a bitmap and I get this:
I'd like it to be in grayscale, not .. well.. pink. Any ideas?
Instead of replicating the 8-bit intensity in each of the RGB channels, you can use the intensity as the alpha channel. In this scheme, 0 corresponds to transparent (background color) and 255 corresponds to fully opaque (black, or whatever color you want--even pink). The idea is similar to Jason LeBrun's proposal: take the high-order 8 bits of each value, shift 24 bits left, then bitwise-OR with the color you want to use for full intensity (or with nothing, if you want black to represent full intensity).
The pixels of a bitmap are encoded using either ARGB_8888, RGB_565, ARGB_4444, or ALPHA_8. So, the short values that you're returning must happen to correspond to values that look slightly pink-ish in one of those formats.
If you want a grayscale bitmap, you can only have values in the range of 0-256 (For the maximum precious color component of 8 bits if you're using ARGB_8888). So, you'll need to map your short to values within that range, and then replicate that value for each of the RGB components.