何が起こっているのかわからないので、これはおそらく適切に表現された質問ではありません。私は学ぼうとしていますが、これについて何らかの方向性が得られることを願っています。初心者に対するあなたの忍耐に感謝します。
変更中のコードがあります。画像を表示します。画像を変更して、別のウィンドウに表示したい。画像を表示するコードをコピーして変更を行うと、元の画像と変更された画像の両方に対して変更された画像が表示されます。
GCHandle が同じメモリを参照し続けているようですか? ハンドル名を変更して、本当に新しいハンドルを作成していませんか? 長いコードで申し訳ありませんが、私は迷っています。
何がうまくいかないのですか?
最も困惑しているのは、それが機能していたということです。その後、何かを変更しましたが、現在は機能するバージョンに戻ることができません。私のコードは機能していたものと同じだと思います。いくつかの設定はどこですか?
System.Runtime.InteropServices.GCHandle gch3 = System.Runtime.InteropServices.GCHandle.Alloc(scaled, System.Runtime.InteropServices.GCHandleType.Pinned);
int pitch = mImageWidth;
if (pitch % 4 != 0)
pitch = ((pitch / 4) + 1) * 4;
System.Drawing.Bitmap bitmap = new Bitmap(mImageWidth, mImageHeight, pitch, System.Drawing.Imaging.PixelFormat.Format8bppIndexed, gch3.AddrOfPinnedObject());
gch3.Free();
if (pal == null)
{
System.Drawing.Imaging.ColorPalette cp = bitmap.Palette;
for (i = 0; i < cp.Entries.Length; ++i)
{
cp.Entries[i] = Color.FromArgb(i, i, i);
}
pal = cp;
}
bitmap.Palette = pal;
FirstImageDisplay.Image = bitmap;
//second image here
for (i = 0; i < frame.Length; ++i)
scaled[i] = (byte)(.5 * scaled[i]);
System.Runtime.InteropServices.GCHandle gch4 = System.Runtime.InteropServices.GCHandle.Alloc(scaled, System.Runtime.InteropServices.GCHandleType.Pinned);
int pitch1 = mImageWidth;
if (pitch1 % 4 != 0)
pitch1 = ((pitch1 / 4) + 1) * 4;
System.Drawing.Bitmap bitmap2 = new Bitmap(mImageWidth, mImageHeight, pitch, System.Drawing.Imaging.PixelFormat.Format8bppIndexed, gch4.AddrOfPinnedObject());
gch4.Free();
if (pal == null)
{
System.Drawing.Imaging.ColorPalette cp = bitmap.Palette;
for (i = 0; i < cp.Entries.Length; ++i)
{
cp.Entries[i] = Color.FromArgb(i, i, i);
}
pal = cp;
}
bitmap.Palette = pal;
SecondImageDisplay.Image = bitmap;
//end second image code