コード例 #1
0
        public static PlatformBitmap From(Stream bitmapStream, bool isOpaque)
        {
            if (Environment.OSVersion.Platform == PlatformID.WinCE && !isOpaque)
            {
                //return new StandardBitmap(OptimizeBitmap(bitmapStream));

                if (myImagingFactory == null)
                {
                    myImagingFactory = (IImagingFactory)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("327ABDA8-072B-11D3-9D7B-0000F81EF32E")));
                }
                byte[] bytes = new byte[bitmapStream.Length];
                bitmapStream.Read(bytes, 0, (int)bitmapStream.Length);
                IImage imagingResource;
                uint   hresult = myImagingFactory.CreateImageFromBuffer(bytes, (uint)bitmapStream.Length, BufferDisposalFlag.BufferDisposalFlagNone, out imagingResource);

                IBitmapImage bitmap;
                myImagingFactory.CreateBitmapFromImage(imagingResource, 0, 0, PixelFormatID.PixelFormat32bppARGB, InterpolationHint.InterpolationHintDefault, out bitmap);
                Marshal.FinalReleaseComObject(imagingResource);
                imagingResource = bitmap as IImage;

                return(new WindowsCEBitmap(imagingResource));
            }
            else
            {
                return(new StandardBitmap(bitmapStream));
            }
        }
コード例 #2
0
        private IImage GetImageFromSkinFile(string imageName)
        {
            //Если не получилось получить файл со скина
            // throw new Exception
            if (!_imageList.ContainsKey(imageName))
            {
                return(null);
            }

            try
            {
                using (FileStream skinFile = File.OpenRead(_skinFolderPath + "\\" + _skinName + ".skn"))
                {
                    EntryPoint pt = _imageList[imageName];
                    skinFile.Position = pt.Start;
                    byte[] array = new byte[pt.Lenght];
                    skinFile.Read(array, 0, pt.Lenght);
                    skinFile.Close();
                    IImage img;

                    IntPtr bytes = Marshal.AllocHGlobal(array.Length);
                    Marshal.Copy(array, 0, bytes, array.Length);
                    _imagingFactory.CreateImageFromBuffer(bytes, (uint)array.Length,
                                                          BufferDisposalFlag.BufferDisposalFlagNone, out img);
                    return(img);
                }
            }
            catch (Exception)
            {
                return(null);
            }
        }
コード例 #3
0
ファイル: ResourceManager.cs プロジェクト: hksonngan/fleux
        public IImageWrapper GetIImageFromEmbeddedResource(string resourceName, Assembly asm)
        {
            return(this.CreateOrGet(this.iimagesMap,
                                    resourceName,
                                    () =>
            {
                var original = resourceName;
                var keyName = asm.GetManifestResourceNames().FirstOrDefault(p => p.EndsWith(resourceName)) ??
                              asm.GetManifestResourceNames().FirstOrDefault(p => p.EndsWith(original));

                // if there is not a dpi aware image just use the original name for find it
                IImage imagingResource;
                using (var strm = asm.GetManifestResourceStream(keyName))
                {
                    var cbBuf = (uint)strm.Length;
                    byte[] pbBuf = new byte[strm.Length];
                    strm.Read(pbBuf, 0, unchecked ((int)strm.Length));
                    //var pbBuf = strm.GetBuffer();
                    factory.CreateImageFromBuffer(pbBuf, cbBuf, BufferDisposalFlag.BufferDisposalFlagNone, out imagingResource);
                }
                return new IImageWrapper(imagingResource);
            }));
        }
コード例 #4
0
ファイル: MainForm.cs プロジェクト: yukine/ArkSwitch
 /// <summary>
 /// Static constructor...
 /// </summary>
 static MainForm()
 {
     // Cache the no-app-icon image.
     using (var st = Assembly.GetExecutingAssembly().GetManifestResourceStream("ArkSwitch.Images.Application.png"))
     {
         var buf = new byte[st.Length];
         st.Read(buf, 0, (int)st.Length);
         ImgFactory.CreateImageFromBuffer(buf, (uint)buf.Length, BufferDisposalFlag.BufferDisposalFlagNone, out NoIconImage);
         ImageInfo info;
         NoIconImage.GetImageInfo(out info);
         NoIconImageSize = new Size((int)info.Width, (int)info.Height);
         buf             = null;
     }
 }
コード例 #5
0
        public WinCEImagingBitmap(Stream stream)
        {
            // this class should only be used in WinCE
            System.Diagnostics.Debug.Assert(Environment.OSVersion.Platform == PlatformID.WinCE);

            if (myImagingFactory == null)
            {
                myImagingFactory =
                    (IImagingFactory)Activator.CreateInstance(
                        Type.GetTypeFromCLSID(new Guid("327ABDA8-072B-11D3-9D7B-0000F81EF32E")));
            }

            int bytesLength;

            byte[]       bytes;
            MemoryStream memStream = stream as MemoryStream;

            if (memStream != null)
            {
                bytesLength = (int)memStream.Length;
                bytes       = memStream.GetBuffer();
            }
            else
            {
                bytesLength = (int)stream.Length;
                bytes       = new byte[bytesLength];
                stream.Read(bytes, 0, bytesLength);
            }

            uint hresult = myImagingFactory.CreateImageFromBuffer(bytes,
                                                                  (uint)bytesLength,
                                                                  BufferDisposalFlag.BufferDisposalFlagNone,
                                                                  out myImage);

            myImage.GetImageInfo(out myInfo);
            myScaleFactorX = 1 / myInfo.Xdpi * 2540;
            myScaleFactorY = 1 / myInfo.Ydpi * 2540;

            IBitmapImage bitmap;

            myImagingFactory.CreateBitmapFromImage(myImage,
                                                   0,
                                                   0,
                                                   PixelFormatID.PixelFormat32bppARGB,
                                                   InterpolationHint.InterpolationHintDefault,
                                                   out bitmap);
            Marshal.FinalReleaseComObject(myImage);
            myImage = bitmap as IImage;
        }
コード例 #6
0
ファイル: Theming.cs プロジェクト: yukine/ArkSwitch
        private static IImage GetIImage(string filename)
        {
            if (!filename.Contains(Path.DirectorySeparatorChar))
            {
                filename = Path.Combine(ThemeDirectory, filename);
            }
            if (!File.Exists(filename))
            {
                return(null);
            }

            IImage img;

            using (var st = File.Open(filename, FileMode.Open))
            {
                var buf = new byte[st.Length];
                st.Read(buf, 0, (int)st.Length);
                ImgFactory.CreateImageFromBuffer(buf, (uint)buf.Length, BufferDisposalFlag.BufferDisposalFlagNone, out img);
            }

            return(img);
        }
コード例 #7
0
        unsafe public static BitmapLoadData BeginLoadBitmap(Stream bitmapStream, bool isTransparent)
        {
            // .NET CF does NOT support transparent images. Need to use the COM IImageFactory to create images with alpha.
            if (myImagingFactory == null)
            {
                myImagingFactory = (IImagingFactory)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("327ABDA8-072B-11D3-9D7B-0000F81EF32E")));
            }

            int bytesLength;

            byte[]       bytes;
            MemoryStream memStream = bitmapStream as MemoryStream;

            if (memStream != null)
            {
                bytesLength = (int)memStream.Length;
                bytes       = memStream.GetBuffer();
            }
            else
            {
                bytesLength = (int)bitmapStream.Length;
                bytes       = new byte[bytesLength];
                bitmapStream.Read(bytes, 0, bytesLength);
            }

            IImage    image;
            ImageInfo info;
            uint      hresult = myImagingFactory.CreateImageFromBuffer(bytes, (uint)bytesLength, BufferDisposalFlag.BufferDisposalFlagNone, out image);

            image.GetImageInfo(out info);

            int resizedWidth  = (int)info.Width;
            int resizedHeight = (int)info.Height;

            resizedWidth  = Texture.GetValidTextureDimensionFromSize(resizedWidth);
            resizedHeight = Texture.GetValidTextureDimensionFromSize(resizedHeight);

            int resizedDim = Math.Max(resizedWidth, resizedHeight);

            if (resizedDim == (int)info.Width && resizedDim == (int)info.Height)
            {
                resizedWidth  = 0;
                resizedHeight = 0;
            }
            else
            {
                resizedWidth  = resizedDim;
                resizedHeight = resizedDim;
            }

            IBitmapImage bitmap;

            myImagingFactory.CreateBitmapFromImage(image, (uint)resizedWidth, (uint)resizedHeight, PixelFormatID.PixelFormatDontCare, InterpolationHint.InterpolationHintDefault, out bitmap);
            Marshal.FinalReleaseComObject(image);

            Size size;

            bitmap.GetSize(out size);
            RECT            rect = new RECT(0, 0, size.Width, size.Height);
            BitmapImageData data;

            if (isTransparent)
            {
                bitmap.LockBits(ref rect, ImageLockMode.ImageLockModeWrite | ImageLockMode.ImageLockModeRead, PixelFormatID.PixelFormat32bppARGB, out data);
                for (int y = 0; y < data.Height; y++)
                {
                    for (int x = 0; x < data.Stride; x += 4)
                    {
                        byte *bp   = (byte *)data.Scan0 + data.Stride * y + x;
                        byte  temp = bp[0];
                        bp[0] = bp[2];
                        bp[2] = temp;
                    }
                }
            }
            else
            {
                bitmap.LockBits(ref rect, ImageLockMode.ImageLockModeRead, PixelFormatID.PixelFormat16bppRGB565, out data);
            }

            BitmapLoadData ret = new BitmapLoadData();

            ret.Data          = data;
            ret.Bitmap        = bitmap;
            ret.Width         = (int)info.Width;
            ret.Height        = (int)info.Height;
            ret.IsTransparent = isTransparent;

            return(ret);
        }