c# BitmapData implementation in android -
i developing oil painting application.i got following c# code.
public static bitmap oilpaintfilter(this bitmap sourcebitmap, int levels, int filtersize) { bitmapdata sourcedata = sourcebitmap.lockbits(new rectangle(0, 0, sourcebitmap.width, sourcebitmap.height), imagelockmode.readonly, pixelformat.format32bppargb); byte[] pixelbuffer = new byte[sourcedata.stride * sourcedata.height]; byte[] resultbuffer = new byte[sourcedata.stride * sourcedata.height]; marshal.copy(sourcedata.scan0, pixelbuffer, 0, pixelbuffer.length); sourcebitmap.unlockbits(sourcedata); int[] intensitybin = new int [levels]; int[] bluebin = new int [levels]; int[] greenbin = new int [levels]; int[] redbin = new int [levels]; levels = levels - 1; int filteroffset = (filtersize - 1) / 2; int byteoffset = 0; int calcoffset = 0; int currentintensity = 0; int maxintensity = 0; int maxindex = 0; double blue = 0; double green = 0; double red = 0; (int offsety = filteroffset; offsety < sourcebitmap.height - filteroffset; offsety++) { (int offsetx = filteroffset; offsetx < sourcebitmap.width - filteroffset; offsetx++) { blue = green = red = 0; currentintensity = maxintensity = maxindex = 0; intensitybin = new int[levels + 1]; bluebin = new int[levels + 1]; greenbin = new int[levels + 1]; redbin = new int[levels + 1]; byteoffset = offsety * sourcedata.stride + offsetx * 4; (int filtery = -filteroffset; filtery <= filteroffset; filtery++) { (int filterx = -filteroffset; filterx <= filteroffset; filterx++) { calcoffset = byteoffset + (filterx * 4) + (filtery * sourcedata.stride); currentintensity = (int )math.round(((double) (pixelbuffer[calcoffset] + pixelbuffer[calcoffset + 1] + pixelbuffer[calcoffset + 2]) / 3.0 * (levels)) / 255.0); intensitybin[currentintensity] += 1; bluebin[currentintensity] += pixelbuffer[calcoffset]; greenbin[currentintensity] += pixelbuffer[calcoffset + 1]; redbin[currentintensity] += pixelbuffer[calcoffset + 2]; if (intensitybin[currentintensity] > maxintensity) { maxintensity = intensitybin[currentintensity]; maxindex = currentintensity; } } } blue = bluebin[maxindex] / maxintensity; green = greenbin[maxindex] / maxintensity; red = redbin[maxindex] / maxintensity; resultbuffer[byteoffset] = clipbyte(blue); resultbuffer[byteoffset + 1] = clipbyte(green); resultbuffer[byteoffset + 2] = clipbyte(red); resultbuffer[byteoffset + 3] = 255; } } bitmap resultbitmap = new bitmap(sourcebitmap.width, sourcebitmap.height); bitmapdata resultdata = resultbitmap.lockbits(new rectangle(0, 0, resultbitmap.width, resultbitmap.height), imagelockmode.writeonly, pixelformat.format32bppargb); marshal.copy(resultbuffer, 0, resultdata.scan0, resultbuffer.length); resultbitmap.unlockbits(resultdata); return resultbitmap; }
in above code need implement " bitmapdata " in android no equivalent method in android.i have changed sample methods stride , height , length.
thanks in advance...
Comments
Post a Comment