1
我正在構建一個3d(紅色,青色)程序。它進行得很好,但是當結合時,「圖像」(見代碼)似乎沒有受到影響。鎖定位不會影響我的圖像
我的錯誤是什麼?
假設:
RImage_P(point) = {5,5}
startCyan(point) = {0,0}
startRed(point) = {5,5}
CImage
,RImage
是下面的代碼。 圖像結果是一個完全黑色的透明圖像。 爲了測試和調試,我評論了Alpha(結果相同)。
private void bitCombine(System.Drawing.Point startCyan, System.Drawing.Point startRed)
{
using (Bitmap image = new Bitmap(CImage.Width + Math.Abs(RImage_P.X), CImage.Height + Math.Abs(RImage_P.Y),PixelFormat.Format32bppArgb))
{
var rectfull = new Rectangle(0, 0, image.Width, image.Height);
var rect = new Rectangle(0, 0, CImage.Width, CImage.Height);
var bitsC = CImage.LockBits(rect, ImageLockMode.ReadOnly
, PixelFormat.Format32bppArgb);
var bitsA = alpha.LockBits(rect, ImageLockMode.ReadOnly
, PixelFormat.Format32bppArgb);
var bitsOutput = image.LockBits(rectfull, ImageLockMode.WriteOnly
, PixelFormat.Format32bppArgb);
unsafe
{
for (int y = 0; y < CImage.Height; y++)
{
byte* ptrC = (byte*)bitsC.Scan0 + y * bitsC.Stride;
byte* ptrA = (byte*)bitsA.Scan0 + y * bitsA.Stride;
byte* ptrOutput = (byte*)bitsOutput.Scan0
+ (y+startCyan.Y)* bitsOutput.Stride;
for (int x = 0; x < CImage.Width; x++)// cyan values
{// gui+ is reversed BGRA
ptrOutput[4 * (x+startCyan.X)] = ptrC[4 * x]; // blue
ptrOutput[4 * (x + startCyan.X) + 1] = ptrC[4 * x + 1];// green
//ptrOutput[4 * (x + startCyan.X) + 3] = ptrA[4 * x + 3];// alpha
}
}
CImage.UnlockBits(bitsC);
var bitsR = RImage.LockBits(rect, ImageLockMode.ReadOnly
, PixelFormat.Format32bppArgb);
for (int y = 0; y < RImage.Height; y++)// red values
{
byte* ptrR = (byte*)bitsR.Scan0 + y * bitsR.Stride;
byte* ptrA = (byte*)bitsA.Scan0 + y * bitsA.Stride;
byte* ptrOutput = (byte*)bitsOutput.Scan0
+ (y+ startRed.Y) * bitsOutput.Stride;
for (int x = 0; x < RImage.Width; x++)
{// gui+ is reversed BGRA
ptrOutput[4 * (x + startRed.X) + 2] = ptrR[4 * x + 2]; // red
//ptrOutput[4 * (x + startRed.X) + 3] = ptrA[4 * x + 3];// alpha
}
}
RImage.UnlockBits(bitsR);
alpha.UnlockBits(bitsA);
image.UnlockBits(bitsOutput);
this.image = image;
}
}
}
這些圖像:
發佈的代碼將永遠不會設置藍色和alpha,alpha在0將產生黑色圖像。通過從非常小的位圖開始調試代碼,以便更好地跟蹤輸入和輸出。 –