開発環境はVisual Studio2010 SP1 言語はC#、.Net Framework4.0です。実行環境はwin7 64bitです。
ある領域の画素に透明度を与えたbmp(format8bppIndex)をPictureBoxに貼り付けたところ、
透明度が無い画像が表示されてしまいます。pictureboxの背景を黒にして以下のコードを実行すると、黄色が透明度の無い状態で表示されてしまいました。
以前、Visual Studio 2005 SP1、.Net Framework2.0、win732bitで行っていたころは、そんなことは無かったはずなのですが、、、。なにか原因や解決策がありましたらご教示ください。
よろしくお願いいたします。
lang
1 Bitmap test = new Bitmap(512, 512, PixelFormat.Format8bppIndexed); 2 ColorPalette myColorPalette = test.Palette; 3 4 for (int i = 0; i < myColorPalette.Entries.Length; i++) 5 { 6 if (i == 1) 7 myColorPalette.Entries[i] = Color.FromArgb(64, Color.Yellow); 8 else 9 myColorPalette.Entries[i] = Color.Transparent; 10 } 11 12 test.Palette = myColorPalette; 13 14 Rectangle rect = new Rectangle(0, 0, 512, 512); 15 BitmapData bmpData = test.LockBits(rect, ImageLockMode.ReadWrite, test.PixelFormat); 16 17 unsafe 18 { 19 byte* p = (byte*)bmpData.Scan0; 20 for (int y = 0; y < bmpData.Height; y++) 21 { 22 for (int x = 0; x < bmpData.Width; x++) 23 { 24 if ((x > 100 && x < 256) && (y > 100 && y < 256)) 25 { 26 *p++ = 1; 27 } 28 else 29 { 30 *p++ = 0; 31 } 32 } 33 for (int x = bmpData.Width; x < bmpData.Stride; x++) 34 { 35 *p++ = 0; 36 } 37 } 38 39 test.UnlockBits(bmpData); 40 pictureBox1.Image = test; 41
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/06/09 16:04
2015/06/09 16:13
2015/06/09 16:23
2015/06/09 16:42
2015/06/09 16:45