示例#1
0
        /// <summary>
        /// GDRAWGWITHMASK(int ID, int srcID, int maskID, int destX, int destY)
        /// エラーチェックは呼び出し元でのみ行う
        /// </summary>
        public void GDrawGWithMask(GraphicsImage srcGra, GraphicsImage maskGra, Point destPoint)
        {
            if (g == null)
            {
                throw new NullReferenceException();
            }
            Bitmap destImg = this.GetBitmap();

            byte[]    srcBytes     = BytesFromBitmap(srcGra.GetBitmap());
            byte[]    srcMaskBytes = BytesFromBitmap(maskGra.GetBitmap());
            Rectangle destRect     = new Rectangle(destPoint.X, destPoint.Y, srcGra.Width, srcGra.Height);

            System.Drawing.Imaging.BitmapData bmpData =
                destImg.LockBits(new Rectangle(0, 0, destImg.Width, destImg.Height),
                                 System.Drawing.Imaging.ImageLockMode.ReadWrite,
                                 PixelFormat.Format32bppArgb);
            try
            {
                IntPtr ptr    = bmpData.Scan0;
                byte[] pixels = new byte[bmpData.Stride * destImg.Height];
                System.Runtime.InteropServices.Marshal.Copy(ptr, pixels, 0, pixels.Length);


                for (int y = 0; y < srcGra.Height; y++)
                {
                    int destIndex = ((destPoint.Y + y) * destImg.Width + destPoint.X) * 4;
                    int srcIndex  = ((0 + y) * srcGra.Width + 0) * 4;
                    for (int x = 0; x < srcGra.Width; x++)
                    {
                        if (srcMaskBytes[srcIndex] == 255)                        //完全不透明
                        {
                            pixels[destIndex++] = srcBytes[srcIndex++];
                            pixels[destIndex++] = srcBytes[srcIndex++];
                            pixels[destIndex++] = srcBytes[srcIndex++];
                            pixels[destIndex++] = srcBytes[srcIndex++];
                        }
                        else if (srcMaskBytes[srcIndex] == 0)                        //完全透明
                        {
                            destIndex += 4;
                            srcIndex  += 4;
                        }
                        else                        //半透明 alpha/255ではなく(alpha+1)/256で計算しているがたぶん誤差
                        {
                            int mask = srcMaskBytes[srcIndex]; mask++;
                            pixels[destIndex] = (byte)((srcBytes[srcIndex] * mask + pixels[destIndex] * (256 - mask)) >> 8); srcIndex++; destIndex++;
                            pixels[destIndex] = (byte)((srcBytes[srcIndex] * mask + pixels[destIndex] * (256 - mask)) >> 8); srcIndex++; destIndex++;
                            pixels[destIndex] = (byte)((srcBytes[srcIndex] * mask + pixels[destIndex] * (256 - mask)) >> 8); srcIndex++; destIndex++;
                            pixels[destIndex] = (byte)((srcBytes[srcIndex] * mask + pixels[destIndex] * (256 - mask)) >> 8); srcIndex++; destIndex++;
                        }
                    }
                }

                // Bitmapへコピー
                System.Runtime.InteropServices.Marshal.Copy(pixels, 0, ptr, pixels.Length);
            }
            finally
            {
                destImg.UnlockBits(bmpData);
            }
        }
示例#2
0
 /// <summary>
 /// GDRAWG(int ID, int srcID, int destX, int destY, int destWidth, int destHeight, int srcX, int srcY, int srcWidth, int srcHeight)
 /// エラーチェックは呼び出し元でのみ行う
 /// </summary>
 public void GDrawG(GraphicsImage srcGra, Rectangle destRect, Rectangle srcRect)
 {
     //	if (g == null)
     //		throw new NullReferenceException();
     //	Bitmap src = srcGra.GetBitmap();
     //	g.DrawImage(src, destRect, srcRect, GraphicsUnit.Pixel);
 }
示例#3
0
 /// <summary>
 /// GDRAWG(int ID, int srcID, int destX, int destY, int destWidth, int destHeight, int srcX, int srcY, int srcWidth, int srcHeight, float[][] cm)
 /// エラーチェックは呼び出し元でのみ行う
 /// </summary>
 public void GDrawG(GraphicsImage srcGra, Rectangle destRect, Rectangle srcRect, float[][] cm)
 {
     //	if (g == null)
     //		throw new NullReferenceException();
     //	Bitmap src = srcGra.GetBitmap();
     //	ImageAttributes imageAttributes = new ImageAttributes();
     //	ColorMatrix colorMatrix = new ColorMatrix(cm);
     //	imageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default,ColorAdjustType.Bitmap);
     //	//g.DrawImage(img.Bitmap, destRect, srcRect, GraphicsUnit.Pixel, imageAttributes);なんでこのパターンないのさ
     //	g.DrawImage(src, destRect, srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, GraphicsUnit.Pixel, imageAttributes);
 }
示例#4
0
        static public void CreateSpriteG(string imgName, GraphicsImage parent, Rectangle rect)
        {
            if (string.IsNullOrEmpty(imgName))
            {
                throw new ArgumentOutOfRangeException();
            }
            imgName = imgName.ToUpper();
            SpriteG newCImg = new SpriteG(imgName, parent, rect);

            imageDictionary[imgName] = newCImg;
        }
示例#5
0
        //static public T GetContent<T>(string name)where T :AContentItem
        //{
        //	if (name == null)
        //		return null;
        //	name = name.ToUpper();
        //	if (!itemDic.ContainsKey(name))
        //		return null;
        //	return itemDic[name] as T;
        //}
        static public GraphicsImage GetGraphics(int i)
        {
            if (gList.ContainsKey(i))
            {
                return(gList[i]);
            }
            GraphicsImage g = new GraphicsImage(i);

            gList[i] = g;
            return(g);
        }
示例#6
0
        //static public T GetContent<T>(string name)where T :AContentItem
        //{
        //	if (name == null)
        //		return null;
        //	name = name.ToUpper();
        //	if (!itemDic.ContainsKey(name))
        //		return null;
        //	return itemDic[name] as T;
        //}
        static public GraphicsImage GetGraphics(int i)
        {
            GraphicsImage gi;

            gList.TryGetValue(i, out gi);
            if (gi != null)
            {
                return(gi);
            }
            GraphicsImage g = new GraphicsImage(i);

            gList[i] = g;
            return(g);
        }
示例#7
0
 public SpriteG(string name, GraphicsImage gra, Rectangle rect)
     : base(name, gra, rect)
 {
 }
示例#8
0
 public override void Dispose()
 {
     g = null;
 }