我正在解析一个网站,以显示URL中的内容,因为有些图像在那里.我想裁剪从网站解析的图像.我真的很挣扎,有人可以帮我解决这个问题吗?
我正在尝试创建一个拼图益智游戏,我想知道在不使用面具的情况下创建拼图的替代方法.目前我通过拍摄完整的图像拼图碎片,将图像分成四个部分(假设拼图是2x2),然后存储并对每个部分应用遮罩.它看起来像下面
// create standard puzzle pieces
arryPieceEndPos = new int[mCols][mRows];
arryPieceImg = new Bitmap[mCols * mRows];
arryIsPieceLocked = new boolean[mCols * mRows];
int pos = 0;
for (int c = 0; c < mCols; c++) {
for (int r = 0; r < mRows; r++) {
arryPieceImg[pos] = Bitmap.createBitmap(mBitmap,
c * mPieceWidth, r * mPieceHeight,
mPieceWidth, mPieceHeight);
arryIsPieceLocked[pos] = false;
arryPieceEndPos[c][r] = pos;
pos++;
}
}
Run Code Online (Sandbox Code Playgroud)
然后我使用辅助方法将遮罩应用于每个部分
private Bitmap maskMethod(Bitmap bmpOriginal, Bitmap bmpMask) {
// adjust mask bitmap if size …
Run Code Online (Sandbox Code Playgroud) 我有一个由42帧组成的大型spritesheet(3808x1632).我会用这些帧呈现一个动画,我使用一个线程来加载一个包含所有帧的位图数组,并用一个闪屏等待它的结束.我没有使用SurfaceView(和画布的绘图功能),我只是在我的主布局中的ImageView中逐帧加载.我的方法类似于从spritesheet中加载大量图像 完成实际需要大约15秒,这是不可接受的.
我用这种功能:
for (int i=0; i<TotalFramesTeapotBG; i++) {
xStartTeapotBG = (i % framesInRowsTeapotBG) * frameWidthTeapotBG;
yStartTeapotBG = (i / framesInRowsTeapotBG) * frameHeightTeapotBG;
mVectorTeapotBG.add(Bitmap.createBitmap(framesBitmapTeapotBG, xStartTeapotBG, yStartTeapotBG, frameWidthTeapotBG, frameHeightTeapotBG));
}
Run Code Online (Sandbox Code Playgroud)
framesBitmapTeapotBG是一个很大的spritesheet.看得更深,我在logcat中读到createBitmap函数需要花费很多时间,可能是因为spritesheet太大了.我找到了一个可以在大spritesheet上创建窗口的地方,使用rect函数和canvas,创建要在数组中加载的小位图,但它并不是很清楚.我在谈论那篇文章:削减位图的一部分
我的问题是:如何加速spritesheet切割?
编辑:我正在尝试使用这种方法,但我看不到最终的动画:
for (int i=0; i<TotalFramesTeapotBG; i++) {
xStartTeapotBG = (i % framesInRowsTeapotBG) * frameWidthTeapotBG;
yStartTeapotBG = (i / framesInRowsTeapotBG) * frameHeightTeapotBG;
Bitmap bmFrame = Bitmap.createBitmap(frameWidthTeapotBG, frameHeightTeapotBG, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(bmFrame);
Rect src = new Rect(xStartTeapotBG, yStartTeapotBG, frameWidthTeapotBG, frameHeightTeapotBG);
Rect dst = new Rect(0, 0, frameWidthTeapotBG, …
Run Code Online (Sandbox Code Playgroud)