Android问题与';创建位图';和亚像素数据

Android问题与';创建位图';和亚像素数据,android,android-image,Android,Android Image,我目前正在开发一个小型Android应用程序,以熟悉API。但是,我在使用createBitmap时遇到了一个关于亚像素数据的问题。我目前有这些代码块。(注意:正在读取的图像是128x128 RGB565 jpeg): 以下是显示问题的图像: 我撒谎了。我还不允许发布图片,所以这里有一个图片链接: 那么,为什么我可以正确显示原始图像,但不能正确显示从其亚像素数据创建的图像?我已经使用版本2.1到3.0运行了应用程序,并且3.0在正确显示图像方面没有问题。这只是3.0版之前的设备的问题,还是我遗

我目前正在开发一个小型Android应用程序,以熟悉API。但是,我在使用createBitmap时遇到了一个关于亚像素数据的问题。我目前有这些代码块。(注意:正在读取的图像是128x128 RGB565 jpeg):

以下是显示问题的图像:

我撒谎了。我还不允许发布图片,所以这里有一个图片链接:


那么,为什么我可以正确显示原始图像,但不能正确显示从其亚像素数据创建的图像?我已经使用版本2.1到3.0运行了应用程序,并且3.0在正确显示图像方面没有问题。这只是3.0版之前的设备的问题,还是我遗漏了什么?我发现了一篇关于堆叠的文章,描述了使用的实体图像(RBG565)和包含alpha的图像(argb888)之间的问题。其中,如果图像类型为argb888,我的方法将不起作用,如果是这样,我需要物理处理像素数据,自己复制亚像素数据,并创建自己的像素缓冲区来存储该数据。我一时兴起就尝试了这一点,这让我陷入了同样的问题。我只是想为什么不试试呢?我还尝试了Bitmap.createBitmap的其他变体,但没有成功。在这一点上,我有点不知所措,我想我应该问问社区。

到底是什么问题?看起来你的偏移量太离谱了,当你使用位移位而不是简单的除法时,这是意料之中的。在这种情况下,除法与右移无关。这是指直肠的位置。此外,它只会影响一个单位的问题。当我考虑到rect的位置时,我并不关心这个问题。问题是当我尝试访问图像的子像素时,它们是不正确的。在提供的图像中,您可以看到原始图像。当我尝试将y偏移设置为64时,图像的一半向下(或黑线所在的位置),我应该看到Test2。此外,当我试图剪辑图像以仅显示Test1时,它也失败了。编辑:我想我必须按shift+enter键进入新行>>,我感觉整个位图都很好。createBitmap(图像、x、y、宽度、高度)功能已启用。如果我使用:Bitmap.createBitmap(image,0,0,imageWidth,imageHeight),其中imageWidth/imageHeight是图像的宽度和高度,我仍然会得到一个混乱的位图。如果我只使用Bitmap.createBitmap(图像),它可以很好地复制它。我不确定他们在做什么,但从外观上看,他们的一些功能在3.0之前的版本中无法正常工作。这很可能是用软管处理的-但还有另一个createBitmap重载,需要跨步宽度和位图类型参数。也许这就是你需要在这里使用的。嗯,我有一个安卓设备,我想为它制作一些应用程序会很好。显然。。。目前开发不足。也许一旦它们合并到4.0中,它会更好一些,但它显然有一些怪癖。这说明了应用程序质量的不足。
public class MainMenu extends View {
private int vWidth;     // Width of our view
private int vHeight;    // Height of our view
private Bitmap imgButtons;
private Rect rect;
private MenuItem testButton;
private MenuItem testButton2;

public MainMenu(Context context) {
    super(context);

    // Get our view dimensions
    vWidth = getWidth();
    vHeight = getHeight();

    // Load our menu buttons' image
    BitmapFactory.Options imgOptions = new BitmapFactory.Options();
    imgButtons = BitmapFactory.decodeResource(getResources(), R.drawable.mainmenubuttons, imgOptions);
    rect = new Rect(100, 400, 228, 528);

    // Create our menu buttons and load their specific images
    testButton = new MenuItem(100, 50);
    testButton2 = new MenuItem(100, 200);

    testButton.LoadImage(imgButtons, 128, 64, 0, 0);
    testButton2.LoadImage(imgButtons, 128, 64, 0, 64);
}

@Override
public void onDraw(Canvas canvas) {
    canvas.drawBitmap(imgButtons, null, rect, null);
    testButton.Draw(canvas);
    testButton2.Draw(canvas);
}

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (event.getAction() != MotionEvent.ACTION_DOWN)
        super.onTouchEvent(event);

    return true;
}
}

class MenuItem {
private int xPos; // Center x-coordinate
private int yPos; // Center y-coordinate
private int width; // Button width
private int height; // Button height
private Rect rect;
private Bitmap buttonImage;

public MenuItem(int withXPos, int withYPos) {
    xPos = withXPos;
    yPos = withYPos;
}

public void LoadImage(Bitmap image, int imageWidth, int imageHeight, int xOffset, int yOffset) {
    width = imageWidth;
    height = imageHeight;

    buttonImage = Bitmap.createBitmap(image, xOffset, yOffset, width, height);
    rect = new Rect(xPos - (width >> 1), yPos - (height >> 1), 
                    xPos + (width >> 1), yPos + (height >> 1));
}

public void Draw(Canvas canvas) {
    canvas.drawBitmap(buttonImage, null, rect, null);
}
}