how to load image as pixel image in android java?

纵然是瞬间 提交于 2021-01-29 07:04:55

问题


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

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){  }   
 

enter image description here


回答1:


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



来源:https://stackoverflow.com/questions/63555990/how-to-load-image-as-pixel-image-in-android-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!