當前位置: 首頁>>代碼示例>>C#>>正文


C# Imaging.BitmapFrame類代碼示例

本文整理匯總了C#中System.Windows.Media.Imaging.BitmapFrame的典型用法代碼示例。如果您正苦於以下問題:C# BitmapFrame類的具體用法?C# BitmapFrame怎麽用?C# BitmapFrame使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


BitmapFrame類屬於System.Windows.Media.Imaging命名空間,在下文中一共展示了BitmapFrame類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: JpgToBase64

        public static string JpgToBase64(BitmapFrame aBMP)
        {
            try
            {
                string pBase64String = null;
                JpegBitmapEncoder encoder = new JpegBitmapEncoder();
                //BmpBitmapEncoder encoder = new BmpBitmapEncoder();
                encoder.Frames.Add(aBMP);
                MemoryStream ms = new MemoryStream();

                //Convert.ToBase64String
                encoder.Save(ms);
                byte[] pPole = new byte[ms.Length];
                ms.Seek(0, SeekOrigin.Begin);
                ms.Read(pPole, 0, pPole.Length);
                pBase64String = Convert.ToBase64String(pPole);
                ms.Close();
                return pBase64String;
            }
            catch (Exception)
            {

                return null;
            }
        }
開發者ID:Ttxman,項目名稱:NanoTrans,代碼行數:25,代碼來源:MyKONST.cs

示例2: DesignTimeSearchResult

	    public DesignTimeSearchResult(BitmapFrame icon, string processName, string title, string error = null)
		{
			View = new BasicListEntry();
			Icon = icon;
			ProcessName = processName;
			Title = title;
		    Error = error;
		}
開發者ID:olivierdagenais,項目名稱:GoToWindow,代碼行數:8,代碼來源:DesignTimeSearchResult.cs

示例3: ToByteArray

 private static byte[] ToByteArray(BitmapFrame bfResize)
 {
     MemoryStream msStream = new MemoryStream();
     JpegBitmapEncoder encoder = new JpegBitmapEncoder();
     encoder.Frames.Add(bfResize);
     encoder.Save(msStream);
     return msStream.ToArray();
 }
開發者ID:senioroman4uk,項目名稱:SignetRecognition,代碼行數:8,代碼來源:ImageHandler.cs

示例4: GetPngStream

        private static MemoryStream GetPngStream(BitmapFrame photo)
        {
            MemoryStream result = new MemoryStream();

            PngBitmapEncoder targetEncoder = new PngBitmapEncoder();
            targetEncoder.Frames.Add(photo);
            targetEncoder.Save(result);

            return result;
        }
開發者ID:keyvan,項目名稱:ImageResizer4DotNet,代碼行數:10,代碼來源:ResizerPrivate.cs

示例5: ImageToByte

 public static byte[] ImageToByte(BitmapFrame bfResize)
 {
     using (MemoryStream msStream = new MemoryStream())
     {
         PngBitmapEncoder pbdDecoder = new PngBitmapEncoder();
         pbdDecoder.Frames.Add(bfResize);
         pbdDecoder.Save(msStream);
         return msStream.ToArray();
     }
 }
開發者ID:MisterTobi,項目名稱:restaurant-cafe,代碼行數:10,代碼來源:ImageHandler.cs

示例6: GetFramePixelDepth

		/// <summary>
		/// Gets the pixel depth (in bits per pixel, bpp) of the specified frame
		/// </summary>
		/// <param name="frame">The frame to get BPP for</param>
		/// <returns>The number of bits per pixel in the frame</returns>
		static int GetFramePixelDepth (BitmapFrame frame)
		{
			if (frame.Decoder.CodecInfo.ContainerFormat == new Guid("{a3a860c4-338f-4c17-919a-fba4b5628f21}")
			    && frame.Thumbnail != null)
			{
				// Windows Icon format, original pixel depth is in the thumbnail
				return frame.Thumbnail.Format.BitsPerPixel;
			}
			// Other formats, just assume the frame has the correct BPP info
			return frame.Format.BitsPerPixel;
		}
開發者ID:Exe0,項目名稱:Eto,代碼行數:16,代碼來源:MultiSizeImage.cs

示例7: GenSheet

        //Function to Gen the sprite sheet with a string of images
        public void GenSheet(string[] images)
        {
            BitmapFrame[] frames = new BitmapFrame[images.Length];
            // Atlas Dimensions
            int iW = 0;
            int iH = 0;

            // Loads the images to tile (no need to specify PngBitmapDecoder, the correct decoder is automatically selected)
            for (int i = 0; i < images.Length; i++)
            {
               frames[i] = BitmapDecoder.Create(new Uri(images[i]), BitmapCreateOptions.None, BitmapCacheOption.OnLoad).Frames.First();
            }
            //Make it so that the two biggest heights and widths depict size
            for(int i = 0; i<frames.Length; i++)
            {
                iW += frames[i].PixelWidth;
            }
            for(int i = 1; i<frames.Length; i++)
            {
                iH = Math.Max(frames[i-1].PixelHeight, frames[i].PixelHeight);
            }
            // Draws the images into a DrawingVisual component
            DrawingVisual drawingVisual = new DrawingVisual();
            using (DrawingContext drawingContext = drawingVisual.RenderOpen())
            {
                int prevFrames = 0;//var prevFrames changed during loop
                for (int i = 0; i < frames.Length; i++)
                {
                    //loading all the images using a for loop for a finite number of images
                    drawingContext.DrawImage(frames[i], new Rect(prevFrames, 0, frames[i].PixelWidth, frames[i].PixelHeight));
                    //saves the width of the prevFrame so that the next image can draw next to it and produces a row of images
                    prevFrames += frames[i].PixelWidth;

                }
            }
            // Converts the Visual (DrawingVisual) into a BitmapSource
            RenderTargetBitmap bmp = new RenderTargetBitmap(iW, iH, 96, 96, PixelFormats.Pbgra32);
            bmp.Render(drawingVisual);

            // Creates a PngBitmapEncoder and adds the BitmapSource to the frames of the encoder
            PngBitmapEncoder encoder = new PngBitmapEncoder();
            encoder.Frames.Add(BitmapFrame.Create(bmp));

            string directory = Directory.GetCurrentDirectory();

            // Saves the image into a file using the encoder
            using (Stream stream = File.Create(directory + @"\tile.png"))
                encoder.Save(stream);
            Vector[] eeek = stripSorter(frames);

            XML eek = new XML();
            eek.BuildXMLDoc(images, frames, iW, iH, eeek);
        }
開發者ID:JayStilla,項目名稱:SpriteMapGenerator,代碼行數:54,代碼來源:MyCanvas.cs

示例8: SetTile

        public void SetTile(int _x, int _y, BitmapFrame _image)
        {
            // hat das bild noch keine ID?
            if(!images.Contains(_image))
            {
                // id erstellen
                images.Add(_image);
            }

            // id setzen
            Tiles[_x, _y] = images.IndexOf(_image);
        }
開發者ID:ColonelBlack94,項目名稱:ToolDev_GPD415,代碼行數:12,代碼來源:Map.cs

示例9: ToByteArrayWpf

 public static byte[] ToByteArrayWpf(BitmapFrame targetFrame, int quality)
 {
     byte[] targetBytes;
     using (var memoryStream = new MemoryStream()) {
         var targetEncoder = new JpegBitmapEncoder {
                                                       QualityLevel = quality
                                                   };
         targetEncoder.Frames.Add(targetFrame);
         targetEncoder.Save(memoryStream);
         targetBytes = memoryStream.ToArray();
     }
     return targetBytes;
 }
開發者ID:eakova,項目名稱:resizer,代碼行數:13,代碼來源:Utils.cs

示例10: Resize

 private static BitmapFrame Resize(BitmapFrame photo, int width, int height, BitmapScalingMode scalingMode)
 {
     DrawingGroup group = new DrawingGroup();
     RenderOptions.SetBitmapScalingMode(group, scalingMode);
     group.Children.Add(new ImageDrawing(photo, new Rect(0, 0, width, height)));
     DrawingVisual targetVisual = new DrawingVisual();
     DrawingContext targetContext = targetVisual.RenderOpen();
     targetContext.DrawDrawing(group);
     RenderTargetBitmap target = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Default);
     targetContext.Close();
     target.Render(targetVisual);
     BitmapFrame targetFrame = BitmapFrame.Create(target);
     return targetFrame;
 }
開發者ID:keyvan,項目名稱:ImageResizer4DotNet,代碼行數:14,代碼來源:ResizerPrivate.cs

示例11: CreateImageFile

 private void CreateImageFile(FileStream file,BitmapFrame frame,ImageType type)
 {
     if(file==null)return;
     BitmapEncoder encoder=null;
     switch(type)
     {
     case ImageType.Bmp:encoder=new BmpBitmapEncoder();break;
     case ImageType.Jpg:encoder=new JpegBitmapEncoder(){QualityLevel=100};break;
     case ImageType.Png:encoder=new PngBitmapEncoder();break;
     case ImageType.Gif:encoder=new GifBitmapEncoder();break;
     case ImageType.Tiff:encoder=new TiffBitmapEncoder(){Compression=TiffCompressOption.Default};break;
     }
     encoder.Frames.Add(frame);
     encoder.Save(file);
 }
開發者ID:DP458,項目名稱:Clipboard_Watcher,代碼行數:15,代碼來源:MainWindow.Save.cs

示例12: GetThumbnail

 /// <summary>
 /// ThumbnailExceptionWorkArround when image cause a format exception by accessing the Thumbnail
 /// </summary>
 /// <param name="frame"></param>
 /// <returns></returns>
 static BitmapSource GetThumbnail(BitmapFrame frame)
 {
     try
     {
         if (frame != null &&
             frame.PixelWidth == 16 && frame.PixelHeight == 16 &&
             ((frame.Format == PixelFormats.Bgra32) || (frame.Format == PixelFormats.Bgr24)))
             return frame;
         else
             return null;
     }
     catch (Exception)
     {
         return null;
     }
 }
開發者ID:rad1oactive,項目名稱:BetterExplorer,代碼行數:21,代碼來源:IconConverter.cs

示例13: ConvertToBitmapImage

 private BitmapImage ConvertToBitmapImage(BitmapFrame bf)
 {
     BmpBitmapEncoder encoder = new BmpBitmapEncoder
     {
         Frames = { bf }
     };
     MemoryStream stream = new MemoryStream();
     encoder.Save(stream);
     stream.Seek(0L, SeekOrigin.Begin);
     BitmapImage image = new BitmapImage();
     image.BeginInit();
     image.StreamSource = stream;
     image.EndInit();
     stream.Close();
     return image;
 }
開發者ID:QuocHuy7a10,項目名稱:Arianrhod,代碼行數:16,代碼來源:GifAnimation.cs

示例14: AddToolboxImage

        private void AddToolboxImage(BitmapFrame _image)
        {
            // neues bild erstellen
            Image newImage = new Image();

            // groesse des bildes festlegen
            newImage.Width = 50.0f;
            newImage.Height = 50.0f;
            newImage.Margin = new Thickness(5.0d);

            // event registrieren
            newImage.MouseDown += Image_MouseDown;

            // bildquelle angeben
            newImage.Source = _image;

            // bild der toolbox hinzufuegen
            ToolBoxStackPanel.Children.Add(newImage);
        }
開發者ID:ColonelBlack94,項目名稱:ToolDev_GPD415,代碼行數:19,代碼來源:MainWindow.xaml.cs

示例15: Photo

        /// <summary>
        /// Constructor
        /// </summary>
        public Photo(string path, string name)
        {
            _source = new Uri(path);
            _image = BitmapFrame.Create(_source);
            //_name = name.Remove(name.Length - 4); //Remove fileextension
            _name = Tools.RemoveExtension(name);
            _name = Tools.RemoveStartNumber(_name);

            //Create Thumbnail for png and Bmp images
            if (_image.Thumbnail == null)
            {
                _myThumbnail = new BitmapImage();
                _myThumbnail.BeginInit();
                _myThumbnail.UriSource = _source;
                _myThumbnail.DecodePixelWidth = 436;
                _myThumbnail.DecodePixelHeight = 326;
                _myThumbnail.EndInit();
            }
        }
開發者ID:virucho,項目名稱:TouchInfoPoint,代碼行數:22,代碼來源:PhotoModel.cs


注:本文中的System.Windows.Media.Imaging.BitmapFrame類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。