我有一些在iOs中运行良好的代码,但当在Android上运行时,这些代码会导致图像完全混乱。我已经找到了一个部分解决方案(不是调用某些代码),但它暗示了一些可怕的错误:
// some bitmap object buffer for mainthread only
R.BitmapRef := FPersistentBitmapBuffer;
// this TImage now contains the original wrongly sized bitmap
ImageBackground.Bitmap.Assign(R.BitmapRef);
// calculated somewhere
TmpNewWidth := 500;
TmpNewHeight := 500;
// draw the bitmap resized to wanted size
R.BitmapRef.Width := Round(TmpNewWidth);
R.BitmapRef.Height := Round(TmpNewHeight);
R.BitmapRef.Canvas.BeginScene();
R.BitmapRef.Canvas.DrawBitmap(ImageBackground.Bitmap, RectF(0,0,ImageBackground.Bitmap.Width,ImageBackground.Bitmap.Height), RectF(0,0,TmpNewWidth,TmpNewHeight), 1);
R.BitmapRef.Canvas.EndScene();
// assign it back to the image
ImageBackground.Bitmap.Assign(R.BitmapRef);
// THIS code causes the image shown in TImageBackground to look completely garbled ... which would indicate something is shareing memory/reference somewhere somehow... There is more odd behavior like debugger unhooking (it seems) if mouse in Delphi debugger hovers over ImageBackground.Bitmap - no error is reported
R.BitmapRef.Clear(TAlphaColorRec.White); 正如我们所看到的,这是把它搞砸的最后一行。在一些测试中,它似乎已经足够删除他的线条,但在另一些测试中是不够的。这是我对这个问题最好的引导/描述/例子。
下面是一个例子,说明了一个被混淆的图像是什么样的。因为每次我运行这个应用程序时,它们看起来都是乱七八糟的,我怀疑它一定与图像有某种联系,但没有任何视觉上的相似之处。

我的问题是什么可能是错的?我正在测试德尔菲XE7的试用版,所以我无法访问源代码。它在iOS上使用XE4和XE7运行得完美无缺,但在安卓系统下,事情正在发生。我想可能是一些位图数据共享了一个引用.有没有人对如何检验这一理论/可能的解决办法有任何想法?
发布于 2014-12-27 11:44:07
这看起来显然是错的。我建议你到http://quality.embarcadero.com去填个便宜货
尝试使用CopyFromBitmap代替“分配”。这将创建图像的唯一副本。如果您调用MyBitmap.Map(TMapAccess.Write, MyBitmapData);,然后是MyBitmap.UnMap(MyBitmapData);,您也会得到一个新的独特图像。
https://stackoverflow.com/questions/27614194
复制相似问题