我听说API 14之后不再支持AndroID标志“模糊”,但是我也想使用Java方法.我的主要问题是从ImagevIEw drawable *** 作位图.
如何从图像视图中获取位图并进行 *** 作(可能会使用高斯模糊)并将其设置回到图像视图?我认为这个过程涉及提取drawable,将drawable转换为位图,在该位图上执行我的模糊方法,然后进行相反 *** 作,直到再次设置为imagevIEw
但是我希望这个过程很清楚,谢谢
解决方法 以下是实现高斯模糊的代码.可能这可以帮助你import androID.graphics.Bitmap;import androID.graphics.Matrix;/** * @author robert.hinds * * Wrapper class for the AndroID Bitmap - used by all filters * */public class AndroIDImage { //original bitmap image private Bitmap image; //format of image (jpg/png) private String formatname; //dimensions of image private int wIDth,height; // RGB Array color protected int[] colourArray; public AndroIDImage(Bitmap img){ this.image = img; formatname = "jpg"; wIDth = img.getWIDth(); height = img.getHeight(); updateColourArray(); } /** * Method to reset the image to a solID colour * * @param color - colour to rest the entire image to */ public voID clearImage(int color){ for(int y=0; y<height; y++){ for(int x=0; x<wIDth; x++){ image.setPixel(x,y,color); } } } /** * Set colour array for image - called on initialisation * by constructor * * @param bitmap */ private voID updateColourArray(){ colourArray = new int[wIDth * height]; image.getPixels(colourArray,wIDth,height); int r,g,b; for (int y = 0; y < height; y++){ for (int x = 0; x < wIDth; x++){ int index = y * wIDth + x; r = (colourArray[index] >> 16) & 0xff; g = (colourArray[index] >> 8) & 0xff; b = colourArray[index] & 0xff; colourArray[index] = 0xff000000 | (r << 16) | (g << 8) | b; } } } /** * Method to set the colour of a specific pixel * * @param x * @param y * @param colour */ public voID setPixelColour(int x,int y,int colour){ colourArray[((y*image.getWIDth()+x))] = colour; image.setPixel(x,colour); } /** * Get the colour for a specifIEd pixel * * @param x * @param y * @return colour */ public int getPixelColour(int x,int y){ return colourArray[y*wIDth+x]; } /** * Set the colour of a specifIEd pixel from an RGB combo * * @param x * @param y * @param c0 * @param c1 * @param c2 */ public voID setPixelColour(int x,int c0,int c1,int c2){ colourArray[((y*image.getWIDth()+x))] = (255 << 24) + (c0 << 16) + (c1 << 8) + c2; image.setPixel(x,colourArray[((y*image.getWIDth()+x))]); } /** * Method to get the RED colour for the specifIEd * pixel * @param x * @param y * @return colour of R */ public int getRComponent(int x,int y){ return (getColourArray()[((y*wIDth+x))]& 0x00FF0000) >>> 16; } /** * Method to get the GREEN colour for the specifIEd * pixel * @param x * @param y * @return colour of G */ public int getGComponent(int x,int y){ return (getColourArray()[((y*wIDth+x))]& 0x0000FF00) >>> 8; } /** * Method to get the BLUE colour for the specifIEd * pixel * @param x * @param y * @return colour of B */ public int getBComponent(int x,int y){ return (getColourArray()[((y*wIDth+x))] & 0x000000FF); } /** * Method to rotate an image by the specifIEd number of degrees * * @param rotatedegrees */ public voID rotate (int rotatedegrees){ Matrix mtx = new Matrix(); mtx.postRotate(rotatedegrees); image = Bitmap.createBitmap(image,height,mtx,true); wIDth = image.getWIDth(); height = image.getHeight(); updateColourArray(); } /** * @return the image */ public Bitmap getimage() { return image; } /** * @param image the image to set */ public voID setimage(Bitmap image) { this.image = image; } /** * @return the formatname */ public String getFormatname() { return formatname; } /** * @param formatname the formatname to set */ public voID setFormatname(String formatname) { this.formatname = formatname; } /** * @return the wIDth */ public int getWIDth() { return wIDth; } /** * @param wIDth the wIDth to set */ public voID setWIDth(int wIDth) { this.wIDth = wIDth; } /** * @return the height */ public int getHeight() { return height; } /** * @param height the height to set */ public voID setHeight(int height) { this.height = height; } /** * @return the colourArray */ public int[] getColourArray() { return colourArray; } /** * @param colourArray the colourArray to set */ public voID setColourArray(int[] colourArray) { this.colourArray = colourArray; }}
import com.bvise.fotoflipper.core.AndroIDImage;public interface IAndroIDFilter { public AndroIDImage process(AndroIDImage imageIn);}import androID.graphics.Bitmap;import androID.graphics.color;public class ConvolutionMatrix{ public static final int SIZE = 3; public double[][] Matrix; public double Factor = 1; public double Offset = 1; public ConvolutionMatrix(int size) { Matrix = new double[size][size]; } public voID setAll(double value) { for (int x = 0; x < SIZE; ++x) { for (int y = 0; y < SIZE; ++y) { Matrix[x][y] = value; } } } public voID applyConfig(double[][] config) { for(int x = 0; x < SIZE; ++x) { for(int y = 0; y < SIZE; ++y) { Matrix[x][y] = config[x][y]; } } } public static Bitmap computeConvolution3x3(Bitmap src,ConvolutionMatrix matrix) { int wIDth = src.getWIDth(); int height = src.getHeight(); Bitmap result = Bitmap.createBitmap(wIDth,src.getConfig()); int A,R,G,B; int sumR,sumG,sumB; int[][] pixels = new int[SIZE][SIZE]; for(int y = 0; y < height - 2; ++y) { for(int x = 0; x < wIDth - 2; ++x) { // get pixel matrix for(int i = 0; i < SIZE; ++i) { for(int j = 0; j < SIZE; ++j) { pixels[i][j] = src.getPixel(x + i,y + j); } } // get Alpha of center pixel A = color.Alpha(pixels[1][1]); // init color sum sumR = sumG = sumB = 0; // get sum of RGB on matrix for(int i = 0; i < SIZE; ++i) { for(int j = 0; j < SIZE; ++j) { sumR += (color.red(pixels[i][j]) * matrix.Matrix[i][j]); sumG += (color.green(pixels[i][j]) * matrix.Matrix[i][j]); sumB += (color.blue(pixels[i][j]) * matrix.Matrix[i][j]); } } // get final Red R = (int)(sumR / matrix.Factor + matrix.Offset); if(R < 0) { R = 0; } else if(R > 255) { R = 255; } // get final Green G = (int)(sumG / matrix.Factor + matrix.Offset); if(G < 0) { G = 0; } else if(G > 255) { G = 255; } // get final Blue B = (int)(sumB / matrix.Factor + matrix.Offset); if(B < 0) { B = 0; } else if(B > 255) { B = 255; } // apply new pixel result.setPixel(x + 1,y + 1,color.argb(A,B)); } } // final image return result; }}
import androID.graphics.Bitmap;import com.bvise.fotoflipper.core.AndroIDImage;import com.bvise.fotoflipper.core.ConvolutionMatrix;import com.bvise.fotoflipper.filters.IAndroIDFilter;public class GaussianBlur implements IAndroIDFilter{ @OverrIDe public AndroIDImage process(AndroIDImage imageIn) { // Todo auto-generated method stub Bitmap src=imageIn.getimage(); double[][] GaussianBlurConfig = new double[][] { { 1,2,1 },{ 2,4,2 },{ 1,1 } }; ConvolutionMatrix convMatrix = new ConvolutionMatrix(3); convMatrix.applyConfig(GaussianBlurConfig); convMatrix.Factor = 200; convMatrix.Offset = 0; return new AndroIDImage(ConvolutionMatrix.computeConvolution3x3(src,convMatrix)); }}总结
以上是内存溢出为你收集整理的android程序化模糊imageview drawable全部内容,希望文章能够帮你解决android程序化模糊imageview drawable所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)