
我使用两个“for”循环来做到这一点,但它只打印一行像素……
如果有人有任何想法怎么办????请帮助…..
我的代码就是这个……..
button start = (button) findVIEwByID(R.ID.start);start.setonClickListener(new VIEw.OnClickListener() { @OverrIDe public voID onClick(VIEw v) { //Toast.makeText(getBaseContext(),"Printing...",Toast.LENGTH_SHORT).show(); iImageArray = new int[bMap.getWIDth()* bMap.getHeight()]; //initializing the array for the image size bMap.getPixels(iImageArray,bMap.getWIDth(),bMap.getHeight()); //copy pixel data from the Bitmap into the 'intArray' array //Canvas canvas = new Canvas (bMap); //replace the red pixels with yellow ones for (int i=0; i < bMap.getHeight(); i++) { for(int j=0; j<bMap.getWIDth(); j++) { iImageArray[j] = 0xFFFFFFFF; } } bMap = Bitmap.createBitmap(iImageArray,bMap.getHeight(),Bitmap.Config.ARGB_8888);//Initialize the bitmap,with the replaced color image.setimageBitmap(bMap); //canvas.drawPoints(iImageArray,bMap.getHeight()*bMap.getWIDth(),paint); } }); 我想以灰度打印位图,为此我找到了这个代码….
public Bitmap toGrayscale(Bitmap bmpOriginal){ int wIDth,height; height = bmpOriginal.getHeight(); wIDth = bmpOriginal.getWIDth(); Bitmap bmpGrayscale = Bitmap.createBitmap(wIDth,height,Bitmap.Config.RGB_565); Canvas c = new Canvas(bmpGrayscale); Paint paint = new Paint(); colorMatrix cm = new colorMatrix(); cm.setSaturation(0); colorMatrixcolorFilter f = new colorMatrixcolorFilter(cm); paint.setcolorFilter(f); c.drawBitmap(bmpOriginal,paint); return bmpGrayscale;} iImageArray [i] = 0xFFFFFFFF;
我有这个测试,而不是实际的灰度值…..
原始版本:
//replace the red pixels with yellow ones for (int i=0; i < bMap.getHeight(); i++) { for(int j=0; j<bMap.getWIDth(); j++) { iImageArray[j] = 0xFFFFFFFF; } } 修正版:
//replace the red pixels with yellow onesint iWIDth = bMap.getWIDth(); for (int i=0; i < bMap.getHeight(); i++) { for(int j=0; j<bMap.getWIDth(); j++) { iImageArray[(i*iWIDth)+j] = 0xFF00FFFF; // actual value of yellow } } 总结 以上是内存溢出为你收集整理的android – 如何逐个像素地显示位图?全部内容,希望文章能够帮你解决android – 如何逐个像素地显示位图?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)