当前位置: 首页>>代码示例>>C#>>正文


C# WriteableBitmap.SaveJpeg方法代码示例

本文整理汇总了C#中System.Windows.Media.Imaging.WriteableBitmap.SaveJpeg方法的典型用法代码示例。如果您正苦于以下问题:C# WriteableBitmap.SaveJpeg方法的具体用法?C# WriteableBitmap.SaveJpeg怎么用?C# WriteableBitmap.SaveJpeg使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Media.Imaging.WriteableBitmap的用法示例。


在下文中一共展示了WriteableBitmap.SaveJpeg方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Create

        public static Uri Create(string filename, string text, SolidColorBrush backgroundColor, double textSize, Size size)
        {
            var background = new Rectangle();
            background.Width = size.Width;
            background.Height = size.Height;
            background.Fill = backgroundColor;

            var textBlock = new TextBlock();
            textBlock.Width = 500;
            textBlock.Height = 500;
            textBlock.TextWrapping = TextWrapping.Wrap;
            textBlock.Text = text;
            textBlock.FontSize = textSize;
            textBlock.Foreground = new SolidColorBrush(Colors.White);
            textBlock.FontFamily = new FontFamily("Segoe WP");

            var tileImage = "/Shared/ShellContent/" + filename;
            using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                var bitmap = new WriteableBitmap((int)size.Width, (int)size.Height);
                bitmap.Render(background, new TranslateTransform());
                bitmap.Render(textBlock, new TranslateTransform() { X = 39, Y = 88 });
                var stream = store.CreateFile(tileImage);
                bitmap.Invalidate();
                bitmap.SaveJpeg(stream, (int)size.Width, (int)size.Height, 0, 99);
                stream.Close();
            }
            return new Uri("ms-appdata:///local" + tileImage, UriKind.Absolute);
        }
开发者ID:halllo,项目名称:DailyQuote,代码行数:29,代码来源:LockScreenImage.cs

示例2: convertImageToBase64

        public static string convertImageToBase64(Image image)
        {
            try
            {
                byte[] bytearray = null;

                using (MemoryStream ms = new MemoryStream())
                {
                    if (image.Source == null)
                    {

                    }
                    else
                    {
                        WriteableBitmap wbitmp = new WriteableBitmap((BitmapImage)image.Source);

                        wbitmp.SaveJpeg(ms, 46, 38, 0, 100);
                        bytearray = ms.ToArray();
                    }
                }

                string str = Convert.ToBase64String(bytearray);
                return str;
            }
            catch (Exception)
            {

                return "";
            }
            
        }
开发者ID:kleitz,项目名称:WPApp,代码行数:31,代码来源:ImageConvert.cs

示例3: client_OpenReadCompleted

        private void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
        {
            var bitmap = new BitmapImage();
            bitmap.SetSource(e.Result);

            String tempJPEG = "MyWallpaper1.jpg";

            using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (myIsolatedStorage.FileExists(tempJPEG))
                {
                    myIsolatedStorage.DeleteFile(tempJPEG);
                }

                var fileStream = myIsolatedStorage.CreateFile(tempJPEG);

                var uri = new Uri(tempJPEG, UriKind.Relative);
                Application.GetResourceStream(uri);

                var wb = new WriteableBitmap(bitmap);

                wb.SaveJpeg(fileStream, wb.PixelWidth, wb.PixelHeight, 0, 90);

                fileStream.Close();
            }

            LockScreenChange(tempJPEG);
        }
开发者ID:oferhaze,项目名称:Ferrari,代码行数:28,代码来源:LockScreenService.cs

示例4: toByte

        public static byte[] toByte(Image img)
        {
            BitmapImage bmpToArray = img.Source as BitmapImage;
            WriteableBitmap wb = new WriteableBitmap(bmpToArray);
            
            

            MemoryStream msWrite = new MemoryStream();
            wb.SaveJpeg(msWrite, 100, 100, 0, 90);
            msWrite.Seek(0, SeekOrigin.Begin);

            if (msWrite != null)
            {
                msWrite.Position = 0;
                MemoryStream ms = new MemoryStream();
                byte[] buffer = new byte[msWrite.Length];
                int read;
                while ((read = msWrite.Read(buffer, 0, buffer.Length)) > 0)
                {
                    ms.Write(buffer, 0, read);
                }

                return buffer;
            }
            return null;
        }
开发者ID:Marksys,项目名称:markdice,代码行数:26,代码来源:Util.cs

示例5: task_Completed

        private async void task_Completed(object sender, PhotoResult e)
        {
            /* byte[] imageBits = new byte[(int)e.ChosenPhoto.Length];
            e.ChosenPhoto.Read(imageBits, 0, imageBits.Length);
            e.ChosenPhoto.Seek(0, System.IO.SeekOrigin.Begin);
            MemoryStream screenshot = new MemoryStream(imageBits);
            BitmapImage imageFromStream = new BitmapImage();
            imageFromStream.SetSource(screenshot); */
            Stream imgstream = e.ChosenPhoto;
            //System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage();
            //bmp.SetSource(e.ChosenPhoto);
            //img.Source = bmp;
            ApplyButton.Visibility = Visibility.Visible;
            session = await EditingSessionFactory.CreateEditingSessionAsync(imgstream);
            try
            {
                session.AddFilter(FilterFactory.CreateCartoonFilter(true));

                // Save the image as a jpeg to the camera roll
                using (MemoryStream stream = new MemoryStream())
                {
                    WriteableBitmap bitmap = new WriteableBitmap(3552, 2448);
                    await session.RenderToWriteableBitmapAsync(bitmap);
                    bitmap.SaveJpeg(stream, bitmap.PixelWidth, bitmap.PixelHeight, 0, 100);
                    img.Source = bitmap;
                }
                //Force the framework to redraw the Image.
            }
            catch (Exception exception)
            {
                MessageBox.Show("Exception:" + exception.Message);
            }
            
        }
开发者ID:ycaihua,项目名称:CartoonMaker,代码行数:34,代码来源:MainPage.xaml.cs

示例6: DoCapture

        public byte[] DoCapture()
        {
            FrameworkElement toSnap = null;
            
            if (!AutomationIdIsEmpty)
                toSnap = GetFrameworkElement(false);

            if (toSnap == null)
                toSnap = AutomationElementFinder.GetRootVisual();

            if (toSnap == null)
                return null;

            // Save to bitmap
            var bmp = new WriteableBitmap((int)toSnap.ActualWidth, (int)toSnap.ActualHeight);
            bmp.Render(toSnap, null);
            bmp.Invalidate();

            // Get memoryStream from bitmap
            using (var memoryStream = new MemoryStream())
            {
                bmp.SaveJpeg(memoryStream, bmp.PixelWidth, bmp.PixelHeight, 0, 95);
                memoryStream.Seek(0, SeekOrigin.Begin);
                return memoryStream.GetBuffer();
            }
        }
开发者ID:Expensify,项目名称:WindowsPhoneTestFramework,代码行数:26,代码来源:TakePictureCommand.cs

示例7: WebClientOpenReadCompleted

        void WebClientOpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
        {
            const string tempJpeg = "TempJPEG";
            var streamResourceInfo = new StreamResourceInfo(e.Result, null);

            var userStoreForApplication = IsolatedStorageFile.GetUserStoreForApplication();
            if (userStoreForApplication.FileExists(tempJpeg))
            {
                userStoreForApplication.DeleteFile(tempJpeg);
            }

            var isolatedStorageFileStream = userStoreForApplication.CreateFile(tempJpeg);

            var bitmapImage = new BitmapImage { CreateOptions = BitmapCreateOptions.None };
            bitmapImage.SetSource(streamResourceInfo.Stream);

            var writeableBitmap = new WriteableBitmap(bitmapImage);
            writeableBitmap.SaveJpeg(isolatedStorageFileStream, writeableBitmap.PixelWidth, writeableBitmap.PixelHeight, 0, 85);

            isolatedStorageFileStream.Close();
            isolatedStorageFileStream = userStoreForApplication.OpenFile(tempJpeg, FileMode.Open, FileAccess.Read);

            // Save the image to the camera roll or saved pictures album.
            var mediaLibrary = new MediaLibrary();

            // Save the image to the saved pictures album.
            mediaLibrary.SavePicture(string.Format("SavedPicture{0}.jpg", DateTime.Now), isolatedStorageFileStream);

            isolatedStorageFileStream.Close();
        }
开发者ID:trilok567,项目名称:Windows-Phone,代码行数:30,代码来源:Page1.xaml.cs

示例8: resizeImage

 // call by reference
 public static void resizeImage(ref WriteableBitmap bmp)
 {
     // TODO: memory management
     // we have 2 options
     // i) use "using" statement
     // ii) dispose of object "ms" before the method finishes (**check bmp1 as ms is set as it's source )
     MemoryStream ms = new MemoryStream();
     int h, w;
     if (bmp.PixelWidth > bmp.PixelHeight)
     {
         double aspRatio = bmp.PixelWidth / (double)bmp.PixelHeight;
         double hh, ww;
         hh = (640.0 / aspRatio);
         ww = hh * aspRatio;
         h = (int)hh;
         w = (int)ww;
     }
     else
     {
         double aspRatio = bmp.PixelHeight / (double)bmp.PixelWidth;
         double hh, ww;
         hh = (480.0 / aspRatio);
         ww = hh * aspRatio;
         h = (int)hh;
         w = (int)ww;
     }
     bmp.SaveJpeg(ms, w, h, 0, 100);
     bmp.SetSource(ms);
 }
开发者ID:jaydeep17,项目名称:CameraTest7,代码行数:30,代码来源:Utils.cs

示例9: capture

        public static Boolean capture(int quality)
        {
            try
            {
                PhoneApplicationFrame frame = (PhoneApplicationFrame)Application.Current.RootVisual;
                WriteableBitmap bitmap = new WriteableBitmap((int)frame.ActualWidth, (int)frame.ActualHeight);
                bitmap.Render(frame, null);
                bitmap.Invalidate();

                string fileName = DateTime.Now.ToString("'Capture'yyyyMMddHHmmssfff'.jpg'");
                IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication();
                if (storage.FileExists(fileName))
                    return false;

                IsolatedStorageFileStream stream = storage.CreateFile(fileName);
                bitmap.SaveJpeg(stream, bitmap.PixelWidth, bitmap.PixelHeight, 0, quality);
                stream.Close();

                stream = storage.OpenFile(fileName, FileMode.Open, FileAccess.Read);
                MediaLibrary mediaLibrary = new MediaLibrary();
                Picture picture = mediaLibrary.SavePicture(fileName, stream);
                stream.Close();

                storage.DeleteFile(fileName);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                return false;
            }

            return true;
        }
开发者ID:miyabi,项目名称:CaptureScreen,代码行数:33,代码来源:CaptureScreen.cs

示例10: CreateTileBackground

        public static string CreateTileBackground(this Project project)
        {
            Grid grid = new Grid();
            Rectangle rect = new Rectangle();
            rect.Width = 173;
            rect.Height = 173;
            rect.Fill = new SolidColorBrush(project.Color.ToColor());

            TextBlock text = new TextBlock();
            text.Text = "TASK";
            text.Foreground = new SolidColorBrush(Colors.White);
            text.FontSize = 32;
            grid.Children.Add(rect);
            grid.Children.Add(text);
            grid.Arrange(new Rect(0d, 0d, 173d, 173d));

            WriteableBitmap wbmp = new WriteableBitmap(grid, null);
            string tiledirectory = "tiles";
            string fullPath = tiledirectory + @"/" + project.Name + ".jpg";
            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {

                if (!store.DirectoryExists(tiledirectory))
                {
                    store.CreateDirectory(tiledirectory);
                }

                using (var stream = store.OpenFile(fullPath, System.IO.FileMode.OpenOrCreate))
                {
                    wbmp.SaveJpeg(stream, 173, 173, 0, 100);
                }

            }
            return "isostore:/" + fullPath;
        }
开发者ID:WindowsPhone-8-TrainingKit,项目名称:HOL-BackgroundTransferService,代码行数:35,代码来源:ShellTileHelpersUI.cs

示例11: camera_Completed

        void camera_Completed(object sender, PhotoResult e)
        {
            if (e.TaskResult == TaskResult.OK)
            {
                //Code to display the photo on the page in an image control named myImage.
                System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage();
                bmp.SetSource(e.ChosenPhoto);

                using (System.IO.IsolatedStorage.IsolatedStorageFile isoStore = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication())
                {
                    if (!isoStore.DirectoryExists(item.Group.Title))
                        isoStore.CreateDirectory(item.Group.Title);

                    string fileName = string.Format("{0}/{1}.jpg", item.Group.Title, DateTime.Now.ToString("dd-MM-yyyy HH-mm-ss"));

                    using (System.IO.IsolatedStorage.IsolatedStorageFileStream targetStream = isoStore.CreateFile(fileName))
                    {
                        WriteableBitmap wb = new WriteableBitmap(bmp);
                        wb.SaveJpeg(targetStream, wb.PixelWidth, wb.PixelHeight, 0, 100);
                        targetStream.Close();
                    }

                    if (null == item.UserImages)
                        item.UserImages = new System.Collections.ObjectModel.ObservableCollection<string>();

                    item.UserImages.Add(fileName);
                }
            }
        }
开发者ID:WindowsPhone-8-TrainingKit,项目名称:HOL-WPNotifications,代码行数:29,代码来源:RecipeDetailPage.xaml.cs

示例12: TakeInIsolatedSotrage

        public static String TakeInIsolatedSotrage(UIElement elt, String name)
        {
            string imageFolder = "Shared/ShellContent/";
            using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (!myIsolatedStorage.DirectoryExists(imageFolder))
                {
                    myIsolatedStorage.CreateDirectory(imageFolder);
                }

                if (myIsolatedStorage.FileExists(name))
                {
                    myIsolatedStorage.DeleteFile(name);
                }

                string filePath = System.IO.Path.Combine(imageFolder, name);
                IsolatedStorageFileStream fileStream = myIsolatedStorage.CreateFile(filePath);

                var bmp = new WriteableBitmap(elt, null);
                var width = (int)bmp.PixelWidth;
                var height = (int)bmp.PixelHeight;
                using (var ms = new MemoryStream(width * height * 4))
                {
                    bmp.SaveJpeg(ms, width, height, 0, 100);
                    ms.Seek(0, SeekOrigin.Begin);
                    var lib = new MediaLibrary();
                    Extensions.SaveJpeg(bmp, fileStream, width, height, 0, 80);
                }
                fileStream.Close();
                Debugger.Log(0, "", "isostore:/" + filePath);
                return  "isostore:/"+filePath; 
            }
        }
开发者ID:fstn,项目名称:WindowsPhoneApps,代码行数:33,代码来源:ScreenShot.cs

示例13: SaveTile

        public void SaveTile(bool failed, UserBalance balance, string backcontent, string path)
        {
            try
            {
                var color = (bool)IsolatedStorageSettings.ApplicationSettings["tileAccentColor"]
                    ? (SolidColorBrush)Application.Current.Resources["PhoneAccentBrush"]
                    : new SolidColorBrush(new Color { A = 255, R = 150, G = 8, B = 8 });
                var tile = GetElement();
                tile.Measure(new Size(336, 336));
                tile.Arrange(new Rect(0, 0, 336, 336));
                var bmp = new WriteableBitmap(336, 336);
                bmp.Render(tile, null);
                bmp.Invalidate();

                using (var isf = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    if (!isf.DirectoryExists("/CustomLiveTiles"))
                    {
                        isf.CreateDirectory("/CustomLiveTiles");
                    }

                    using (var stream = isf.OpenFile(path, FileMode.OpenOrCreate))
                    {
                        bmp.SaveJpeg(stream, 336, 366, 0, 100);
                    }
                }
            }
            catch (Exception)
            {
                //sleep for 0.5 seconds in order to try to resolve the isolatedstorage issues
                Thread.Sleep(500);
                SaveTile(failed, balance, backcontent, path);
            }
        }
开发者ID:JanJoris,项目名称:VikingApp,代码行数:34,代码来源:BaseTile.cs

示例14: SampleOriginalImage

        // Sample the original image
        private void SampleOriginalImage()
        {
            originalBitmap = new WriteableBitmap(originalImage);
            double ratio = (double)originalBitmap.PixelWidth / (double)originalBitmap.PixelHeight;
            double w = Application.Current.RootVisual.RenderSize.Width;
            double h = Application.Current.RootVisual.RenderSize.Height;
            double previewWidth;
            double previewHeight;

            if (w / ratio > h)
            {
                previewHeight = h;
                previewWidth = h * ratio;
            }
            else
            {
                previewWidth = w;
                previewHeight = w / ratio;
            }

            originalPreviewBitmap = originalBitmap.Resize((int)previewWidth, (int)previewHeight, System.Windows.Media.Imaging.WriteableBitmapExtensions.Interpolation.Bilinear);
            currentPreviewBitmap = originalBitmap.Resize((int)previewWidth, (int)previewHeight, System.Windows.Media.Imaging.WriteableBitmapExtensions.Interpolation.Bilinear);

            // Create buffer
            previewStream = new MemoryStream();
            currentPreviewBitmap.SaveJpeg(previewStream, originalPreviewBitmap.PixelWidth, originalPreviewBitmap.PixelHeight, 0, 75);
            previewBuffer = previewStream.GetWindowsRuntimeBuffer();
        }
开发者ID:powerytg,项目名称:indulged-flickr,代码行数:29,代码来源:ProFXCore.cs

示例15: ViewportRectangle_Tap

		async void ViewportRectangle_Tap(object sender, System.Windows.Input.GestureEventArgs e)
		{
			WriteableBitmap bitmap = new WriteableBitmap(ViewportRectangle, null);
			string fileName = Guid.NewGuid().ToString();

			using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
			{
				using (IsolatedStorageFileStream isfStream = new IsolatedStorageFileStream(fileName, FileMode.Create, isf))
				{
					int width = (int)ViewportRectangle.ActualWidth;
					int height = (int)ViewportRectangle.ActualHeight;
					await Task.Run(() =>
					{
						bitmap.SaveJpeg(isfStream, width, height, 0, 100);
					});
				}

				using (IsolatedStorageFileStream isfStream = new IsolatedStorageFileStream(fileName, FileMode.Open, isf))
				{
					BitmapImage bitmapImage = new BitmapImage();
					bitmapImage.SetSource(isfStream);
					CapturedImage.Source = bitmapImage;
					VisualStateManager.GoToState(this, CompletedCaptureState.Name, false);
				}
			}
		}
开发者ID:romeowa,项目名称:pisa,代码行数:26,代码来源:CameraControl.xaml.cs


注:本文中的System.Windows.Media.Imaging.WriteableBitmap.SaveJpeg方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。