[英]how to load image as pixel image in android java?
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我想创建一个显示图像所有像素的 android 应用程序,但是当我缩放像素角的颜色与周围其他像素混合时,我希望像素在它们的正方形中完美显示它们的颜色(如像素艺术或 ms 绘画时)你放大它)我试着在画布上画一个矩形,然后用我想要的颜色画一个 1×1 的位图,但它混合了
here is a picture and code upper pic 4×4 what it creates lower pic what i want这是一张图片和代码 上图 4×4 它创建了什么下图我想要什么
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){ }
i understood how to stop pixels from blending.我了解如何阻止像素混合。 I was using 2×2 image on the screen 300ppi .
我在屏幕上使用 2×2 图像 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
如果我想每英寸显示 1 个像素,我应该使用像素位图(这里是 bt3)宽度,因为 300 最好是像素正方形的宽度 = 屏幕宽度 / 像素数
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.