如何在android java中将图像加载为像素图像? [英] how to load image as pixel image in android java?

查看:47
本文介绍了如何在android java中将图像加载为像素图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个Android应用它显示图像的所有像素,但是当我缩放像素角的颜色与周围的其他像素融合时,我希望像素在其正方形中完美显示其颜色(如缩放时的像素图或ms画图)我尝试在画布上绘制一个矩形并绘制一个1×1的位图用我想要的颜色,但它融合了

i want to creat an android app that shows all pixels of an image but when i zoom color of the corners of the pixels blend with other pixels around it i want pixels to show their color perfectly in their squares ( like pixel art or ms paint when you zoom it) i tried drawing a rectangle on canvas and drawing a bitmap 1×1 with color what i want but it blends

这是图片和代码上图4×4它产生了什么降低图片我想要的

here is a picture and code upper pic 4×4 what it creates lower pic what i want

try{   
 //creating bitmap from other for background

 bt2 = Bitmap.createBitmap(bt,i2,i3,i,i);

}

Canvas c=new Canvas(bt2);
c.drawColor(Color.argb(255,255,255,255));

//creating 1×1 image
Bitmap bt3 = Bitmap.createBitmap(bt,0,0,1,  1  );
//blue color to draw for pixel looking

Canvas c2 =new Canvas(bt3);
c2.drawColor(Color.argb(255,0,0,255));


int w=bt2.getWidth();
int h= bt2.getHeight();

//geting pixels so i would use it

btpixels=new int [w*h];
bt2.getPixels(btpixels,
   0,w,0,0,w,h );
   
int j =0;
Paint paint =new Paint();

for(j=0;j<w;j++)
{

paint.setARGB(255,0,255,0);
//drawing blue bitmap on bt2

c.drawBitmap(bt3,j,j,paint) ;

//paint.setColor( btpixels[j]);

 /*  c.drawRect(
   (float)i-1,     
   (float) i-1, 
   (float)i,
   (float)i,
 paint );  */
 
 }
img.setImageBitmap( bt2 );

}catch(IllegalArgumentException e){  }   
 

推荐答案

我了解如何阻止像素融合.我在屏幕300ppi上使用2×2图像.如果我想显示每英寸1个像素,则应使用像素位图(此处bt3)宽度为300最好是像素正方形的宽度=屏幕宽度/像素数

i understood how to stop pixels from blending. I was using 2×2 image on the screen 300ppi . If i want to show 1 pixel per inch i should use pixel bitmap(here bt3) width as 300 best would be width of the pixel square = width of the screen / num of pixels

这篇关于如何在android java中将图像加载为像素图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆