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


C# WriteableBitmap.Blit方法代码示例

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


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

示例1: OnRender

        protected override void OnRender(DrawingContext dc)
        {
            var bitmap = new WriteableBitmap((int)(Screen.PixelWidth * this.Zoom), (int)(Screen.PixelHeight * this.Zoom), 96, 96, PixelFormats.Pbgra32, null);

            base.OnRender(dc);

            var size = Screen.Tileset.TileSize * this.Zoom;

            for (int y = 0; y < Screen.Height; y++)
            {
                for (int x = 0; x < Screen.Width; x++)
                {
                    var tile = Screen.TileAt(x, y);
                    var location = tile.Sprite.CurrentFrame.SheetLocation;
                    var rect = new Rect(0, 0, location.Width, location.Height);

                    if (_grayscale)
                    {
                        var image = SpriteBitmapCache.GetOrLoadFrameGrayscale(Screen.Tileset.SheetPath.Absolute, location);
                        bitmap.Blit(new Rect(x * size, y * size, size, size), image, rect);
                    }
                    else
                    {
                        var image = SpriteBitmapCache.GetOrLoadFrame(Screen.Tileset.SheetPath.Absolute, location);
                        bitmap.Blit(new Rect(x * size, y * size, size, size), image, rect);
                    }
                }
            }

            dc.DrawImage(bitmap, new Rect(0, 0, bitmap.PixelWidth, bitmap.PixelHeight));
        }
开发者ID:Tesserex,项目名称:C--MegaMan-Engine,代码行数:31,代码来源:TileScreenLayer.cs

示例2: MakeSmallerCopy

 public static WriteableBitmap MakeSmallerCopy(this WriteableBitmap original, int maxDimension)
 {
     var ratio = 0.0;
     if (original.PixelHeight > original.PixelWidth)
     {
         ratio = ((double)original.PixelHeight) / maxDimension;
     }
     else
     {
         ratio = ((double)original.PixelWidth) / maxDimension;
     }
     if (ratio > 1.0)
         ratio = 1.0;
     var newWidth = (int)Math.Floor(((double)original.PixelWidth) / ratio);
     var newHeight = (int)Math.Floor(((double)original.PixelHeight) / ratio);
     var toReturn = new WriteableBitmap(newWidth, newHeight);
     toReturn.Blit(toReturn.BoundingRect(), original, original.BoundingRect());
     return toReturn;
 }
开发者ID:krsumeet,项目名称:face,代码行数:19,代码来源:WriteableBitmapExtensions.cs

示例3: GenerateGuildEmblemImage

		/// <summary>
		/// Generates the guild emblem image.
		/// </summary>
		/// <param name="guildEmblemData">The guild emblem data.</param>
		/// <param name="guildSide">The guild side.</param>
		/// <param name="width">The width.</param>
		/// <param name="height">The height.</param>
		/// <returns></returns>
		public static BitmapSource GenerateGuildEmblemImage(GuildEmblem guildEmblemData, GuildSide guildSide, int width = 216, int height = 240)
		{
			WriteableBitmap guildEmblemImage;

			try
			{
				guildEmblemImage = new WriteableBitmap(216, 240);

				var factionBackgroundImage = new WriteableBitmap(216, 216).FromResource(String.Format("Images/GuildDetails/Emblem_Background_{0}.png", guildSide));
				guildEmblemImage.Blit(new Rect(0, 0, 216, 216), factionBackgroundImage, new Rect(0, 0, 216, 216), WriteableBitmapExtensions.BlendMode.Alpha);

				var shadowImage = new WriteableBitmap(179, 210).FromResource("Images/GuildDetails/Emblem_Shadow.png");
				guildEmblemImage.Blit(new Rect(18, 27, 179, 210), shadowImage, new Rect(0, 0, 179, 210), WriteableBitmapExtensions.BlendMode.Alpha);

				var backgroundColor = GetColorFromHexString(guildEmblemData.BackgroundColor);
				var emblemBackgroundImage = new WriteableBitmap(179, 210).FromResource("Images/GuildDetails/Emblem_Background.png");
				guildEmblemImage.Blit(new Rect(18, 27, 179, 210), emblemBackgroundImage, new Rect(0, 0, 179, 210), backgroundColor, WriteableBitmapExtensions.BlendMode.Alpha);

				var borderColor = GetColorFromHexString(guildEmblemData.BorderColor);
				var borderImage = new WriteableBitmap(147, 159).FromResource(String.Format("Images/GuildDetails/Emblem_Border_{0}.png", guildEmblemData.Border));
				guildEmblemImage.Blit(new Rect(31, 40, 147, 159), borderImage, new Rect(0, 0, 147, 159), borderColor, WriteableBitmapExtensions.BlendMode.Alpha);

				var iconColor = GetColorFromHexString(guildEmblemData.IconColor);
				var iconImage = new WriteableBitmap(125, 125).FromResource(String.Format("Images/GuildDetails/Emblems/Emblem_{0}.png", guildEmblemData.Icon.ToString().PadLeft(3, '0')));
				guildEmblemImage.Blit(new Rect(33, 57, 125, 125), iconImage, new Rect(0, 0, 125, 125), iconColor, WriteableBitmapExtensions.BlendMode.Alpha);

				var hooksImage = new WriteableBitmap(179, 32).FromResource("Images/GuildDetails/Emblem_Hooks.png");
				guildEmblemImage.Blit(new Rect(18, 27, 179, 32), hooksImage, new Rect(0, 0, 179, 32), WriteableBitmapExtensions.BlendMode.Alpha);
			}
			catch (Exception ex)
			{
				guildEmblemImage = new WriteableBitmap(216, 240).FromResource(String.Format("Images/GuildDetails/Emblem_Default_{0}.png", guildSide));
			}

			var resized = guildEmblemImage.Resize(width, height, WriteableBitmapExtensions.Interpolation.Bilinear);
			return resized;
		}
开发者ID:DarkQuantum,项目名称:WoW-Armory-for-Windows-Phone-8,代码行数:45,代码来源:ImageHelper.cs

示例4: ExtractImage

        private void ExtractImage(List<WriteableBitmap> tempTiles, BitmapSource image, int spacing, int offset, IProgress<ProgressDialogState> progress = null)
        {
            var sourceImage = BitmapFactory.ConvertToPbgra32Format(image);

            var jump = 16 + spacing;
            var totalTiles = ((image.PixelWidth - offset) / jump) * ((image.PixelHeight - offset) / jump);
            var currentTile = 0;

            for (var y = offset; y < image.PixelHeight; y += jump)
            {
                for (var x = offset; x < image.PixelWidth; x += jump)
                {
                    var tileImage = new WriteableBitmap(16, 16, 96, 96, PixelFormats.Pbgra32, null);
                    tileImage.Blit(new System.Windows.Rect(0, 0, 16, 16), sourceImage, new System.Windows.Rect(x, y, 16, 16));
                    tempTiles.Add(tileImage);

                    currentTile++;
                    if (progress != null)
                    {
                        progress.Report(new ProgressDialogState() {
                            ProgressPercentage = currentTile * 100 / totalTiles,
                            Description = string.Format("Extracting {0} / {1}", currentTile, totalTiles)
                        });
                    }
                }
            }
        }
开发者ID:Tesserex,项目名称:C--MegaMan-Engine,代码行数:27,代码来源:TilesetImporter.cs

示例5: AppendNewTilesToSheet

        private void AppendNewTilesToSheet(List<WriteableBitmap> tempTiles)
        {
            var total = tempTiles.Count;
            var tileWidth = Tilesheet.PixelWidth / 16;
            var addedTileHeight = (int)Math.Ceiling(total / (double)tileWidth);

            var tilesheet = new WriteableBitmap(Tilesheet.PixelWidth, Tilesheet.PixelHeight + addedTileHeight * 16, 96, 96, PixelFormats.Pbgra32, null);
            var writeableSource = BitmapFactory.ConvertToPbgra32Format(Tilesheet);
            var originalRect = new System.Windows.Rect(0, 0, Tilesheet.PixelWidth, Tilesheet.PixelHeight);
            tilesheet.Blit(originalRect, writeableSource, originalRect);

            var x = 0;
            var y = Tilesheet.PixelHeight;
            var source = new System.Windows.Rect(0, 0, 16, 16);

            foreach (var frame in tempTiles)
            {
                var dest = new System.Windows.Rect(x, y, 16, 16);
                tilesheet.Blit(dest, frame, source);

                var tile = Tileset.AddTile();
                tile.Sprite.CurrentFrame.SetSheetPosition(x, y);

                if (x < 16 * (tileWidth - 1))
                {
                    x += 16;
                }
                else
                {
                    x = 0;
                    y += 16;
                }
            }

            Tilesheet = tilesheet;
            SpriteBitmapCache.InsertSource(Tileset.SheetPath.Absolute, tilesheet);
            Tileset.RefreshSheet();
        }
开发者ID:Tesserex,项目名称:C--MegaMan-Engine,代码行数:38,代码来源:TilesetImporter.cs

示例6: CompactTilesheet

        public void CompactTilesheet()
        {
            var allFrames = RipAllFrames();
            var total = allFrames.Count;
            var root = Math.Sqrt(total);
            var width = (int)Math.Ceiling(root);
            var height = (int)Math.Ceiling(total / (double)width);

            var tilesheet = new WriteableBitmap(width * 16, height * 16, 96, 96, PixelFormats.Pbgra32, null);

            var x = 0;
            var y = 0;
            var source = new System.Windows.Rect(0, 0, 16, 16);

            foreach (var frame in allFrames)
            {
                var dest = new System.Windows.Rect(x, y, 16, 16);
                tilesheet.Blit(dest, frame.Key, source);

                foreach (var spriteFrame in frame.Value)
                {
                    spriteFrame.SetSheetPosition(x, y);
                }

                if (x < 16 * (width - 1))
                {
                    x += 16;
                }
                else
                {
                    x = 0;
                    y += 16;
                }
            }
            
            Tilesheet = tilesheet;
            SpriteBitmapCache.InsertSource(Tileset.SheetPath.Absolute, tilesheet);
            Tileset.RefreshSheet();
        }
开发者ID:Tesserex,项目名称:C--MegaMan-Engine,代码行数:39,代码来源:TilesetImporter.cs

示例7: GetImagePixels

        /**
         * Extracts image pixels into byte array "pixels"
         */
        protected void GetImagePixels()
        {
            int w = image.PixelWidth;
            int h = image.PixelHeight;
            //		int type = image.GetType().;
            if ((w != width)
                || (h != height)
                )
            {
                // create new image with right size/format
                WriteableBitmap temp =
                    new WriteableBitmap(width, height);
                temp.Blit(new Rect(0.0, 0.0, width, height), image, new Rect(0.0, 0.0, image.PixelWidth, image.PixelHeight));
                image = temp;
            }
            /*
                ToDo:
                improve performance: use unsafe code
            */
            pixels = new Byte[3 * image.PixelWidth * image.PixelHeight];
            int count = 0;
            WriteableBitmap tempBitmap = new WriteableBitmap(image);
            for (int th = 0; th < image.PixelHeight; th++)
            {
                for (int tw = 0; tw < image.PixelWidth; tw++)
                {
                    Color color = tempBitmap.GetPixel(tw, th);
                    pixels[count] = color.R;
                    count++;
                    pixels[count] = color.G;
                    count++;
                    pixels[count] = color.B;
                    count++;
                }
            }

            //		pixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
        }
开发者ID:icyflash,项目名称:NGif,代码行数:41,代码来源:AnimatedGifEncoder.cs

示例8: CutFrame

 private WriteableBitmap CutFrame(WriteableBitmap sheet, Common.Geometry.Rectangle frameRect)
 {
     var wb = new WriteableBitmap(frameRect.Width, frameRect.Height, 96, 96, PixelFormats.Pbgra32, null);
     var srcRect = new System.Windows.Rect(frameRect.X, frameRect.Y, frameRect.Width, frameRect.Height);
     var destRect = new System.Windows.Rect(0, 0, frameRect.Width, frameRect.Height);
     wb.Blit(destRect, sheet, srcRect);
     return wb;
 }
开发者ID:Tesserex,项目名称:C--MegaMan-Engine,代码行数:8,代码来源:TilesetImporter.cs

示例9: btnSave_Click

        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.Filter = "JPEGファイル (*.jpg)|*.jpg|PNGファイル (*.png)|*.png|ビットマップファイル (*.bmp)|*.bmp";
            if (sfd.ShowDialog() == true)
            {
                IImageEncoder enc;
                string fn = sfd.SafeFileName.ToLower();
                if(fn.EndsWith(".jpg"))
                {
                    enc = new JpegEncoder();
                }
                else if (fn.EndsWith(".png"))
                {
                    enc = new PngEncoder();
                }
                else if (fn.EndsWith(".bmp"))
                {
                    enc = new BmpEncoder();
                }
                else
                {
                    MessageBox.Show("エラー");
                    return;
                }

                double scaledWidth = (cropImage.Width * zoom);
                double scaledHeight = (cropImage.Height * zoom);
                double scaledLeft = (imageWidth - scaledWidth) / 2;
                double scaledTop = (imageHeight - scaledHeight) / 2;
                Rect r = new Rect((double)cropCanvas.GetValue(Canvas.LeftProperty), (double)cropCanvas.GetValue(Canvas.TopProperty), cropCanvas.Width, cropCanvas.Height);
                Rect r2 = new Rect(scaledLeft, scaledTop, scaledWidth , scaledHeight);
                r.Intersect(r2);
                double clipedLeft = r.Left - scaledLeft;
                double clipedTop = r.Top - scaledTop;
                r.X = clipedLeft;
                r.Y = clipedTop;
                ScaleTransform st = new ScaleTransform();
                st.ScaleX = zoom;
                st.ScaleY = zoom;
                WriteableBitmap wb = new WriteableBitmap(cropImage, st);
                WriteableBitmap outputWb = new WriteableBitmap((int)r.Width, (int)r.Height);
                outputWb.Blit(new Rect(0, 0, r.Width, r.Height), wb, new Rect(r.Left, r.Top, r.Width, r.Height));
                ImageTools.Image img = ToImage(outputWb);
                using (Stream stream = sfd.OpenFile())
                {
                    enc.Encode(img, stream);
                }
            }
        }
开发者ID:gtk2k,项目名称:PakuriEasyCropper,代码行数:50,代码来源:MainPage.xaml.cs

示例10: SaveTileImages

        public static void SaveTileImages(string channelName, Uri image)
        {
            var bitmapImage = new BitmapImage() { CreateOptions = BitmapCreateOptions.None };
            bitmapImage.ImageFailed += (s, e) => 
            { };
            bitmapImage.ImageOpened += (s, e) =>
            {
                #region Create Image with Live Logo
                using (IsolatedStorageFile local = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    // Create a new folder named DataFolder.
                    if (!local.DirectoryExists(imageFolder))
                        local.CreateDirectory(imageFolder);

                    var writeableBitmap = new WriteableBitmap(s as BitmapImage);
                    writeableBitmap.Invalidate();

                    string offlineFilePath = System.IO.Path.Combine(imageFolder, channelName + ".jpg");
                    using (var imageOfflineFileStream = new IsolatedStorageFileStream(offlineFilePath, System.IO.FileMode.Create, local))
                    {
                        writeableBitmap.SaveJpeg(imageOfflineFileStream, writeableBitmap.PixelWidth, writeableBitmap.PixelHeight, 0, 100);
                    }

                    BitmapImage icon = new BitmapImage();
                    icon.CreateOptions = BitmapCreateOptions.None;
                    icon.UriSource = new Uri("/Assets/live_icon.png", UriKind.Relative);
                    WriteableBitmap iconWB = new WriteableBitmap(icon);

                    int AnsX1 = 175;
                    int AnsY1 = 0;
                    int AnsX2 = 300;
                    int AnsY2 = 125;

                    Rect sourceRect = new Rect(0, 0, iconWB.PixelWidth, iconWB.PixelHeight);
                    Rect destRect = new Rect(AnsX1, AnsY1, AnsX2 - AnsX1, AnsY2 - AnsY1);

                    writeableBitmap.Blit(destRect, iconWB, sourceRect);
                    writeableBitmap.Invalidate();

                    string onlineFilePath = System.IO.Path.Combine(imageFolder, "live-" + channelName + ".jpg");
                    using (var imageOnlineFileStream = new IsolatedStorageFileStream(onlineFilePath, System.IO.FileMode.Create, local))
                    {
                        writeableBitmap.SaveJpeg(imageOnlineFileStream, writeableBitmap.PixelWidth, writeableBitmap.PixelHeight, 0, 100);
                    }
                }
                #endregion
            };

            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                bitmapImage.UriSource = image;
            });
        }
开发者ID:Rwprice,项目名称:Twitchy,代码行数:53,代码来源:LiveTileHelper.cs

示例11: DrawGrid

        private void DrawGrid(WriteableBitmap bitmap)
        {
            if (CentralPoint.X == 0 && CentralPoint.Y == 0)
            {
                CentralPoint = new System.Windows.Point(bitmap.PixelWidth / 2, bitmap.PixelHeight / 2);
            }
            WriteableBitmap tempbitmap = new WriteableBitmap(bitmap.PixelWidth, bitmap.PixelHeight, bitmap.DpiX,
                                                             bitmap.DpiY, PixelFormats.Pbgra32, bitmap.Palette);

            tempbitmap.DrawLine(0, (int)CentralPoint.Y - (StarWindowSize / 2), bitmap.PixelWidth, (int)CentralPoint.Y - (StarWindowSize / 2), Colors.White);
            tempbitmap.DrawLine(0, (int)CentralPoint.Y + (StarWindowSize / 2), bitmap.PixelWidth, (int)CentralPoint.Y + (StarWindowSize / 2), Colors.White);

            tempbitmap.DrawLine((int)CentralPoint.X - (StarWindowSize / 2), 0, (int)CentralPoint.X - (StarWindowSize / 2), bitmap.PixelHeight, Colors.White);
            tempbitmap.DrawLine((int)CentralPoint.X + (StarWindowSize / 2), 0, (int)CentralPoint.X + (StarWindowSize / 2), bitmap.PixelHeight, Colors.White);

            bitmap.Blit(new Rect(0, 0, bitmap.PixelWidth, bitmap.PixelHeight), tempbitmap,
                        new Rect(0, 0, bitmap.PixelWidth, bitmap.PixelHeight));

        }
开发者ID:tomriddle1234,项目名称:digiCamControl,代码行数:19,代码来源:AstroLiveViewViewModel.cs

示例12: Screen

        private async Task<WriteableBitmap> Screen()
        {
            //截图
            await Task.Delay(200);

            using (System.IO.Stream stream1 = Application.GetResourceStream(new Uri(@"Assets/qcode.png", UriKind.Relative)).Stream)
            {
                double width = Application.Current.Host.Content.ActualWidth;
                double heigth = Application.Current.Host.Content.ActualHeight;
                WriteableBitmap wbmp = new WriteableBitmap((int)width, (int)heigth);
                wbmp.Render(App.Current.RootVisual, null);
                wbmp.Invalidate();


                WriteableBitmap wideBitmap = new WriteableBitmap((int)width, (int)(heigth + 280));

                BitmapImage image1 = new BitmapImage();
                image1.SetSource(stream1);
                stream1.Close();
                //stream1.Flush();

                wideBitmap.Blit(new Rect(0, 0, width, heigth), new WriteableBitmap(wbmp), new Rect(0, 0, wbmp.PixelWidth, wbmp.PixelHeight), WriteableBitmapExtensions.BlendMode.Additive);
                wideBitmap.Blit(new Rect((width - 280) / 2, heigth, 280, 280), new WriteableBitmap(image1), new Rect(0, 0, image1.PixelWidth, image1.PixelHeight), WriteableBitmapExtensions.BlendMode.Additive);

                return wideBitmap;
            }
        }
开发者ID:RaulVan,项目名称:FMRadioPro,代码行数:27,代码来源:MainPage.xaml.cs

示例13: DrawImage

        private static void DrawImage(WriteableBitmap targetBitmap, WriteableBitmap bitmap, Rect dest, TileInfo tile, MemoryCache<Feature> memoryCache, double opacity)
        {
            try
            {
                //todo: look at GDI rendering to deal with clipping
                                var destRounded = RoundToPixel(dest);
                var sourceRect = new Rect(0, 0, 256, 256);

                opacity = 1; // hack, opacity not supported 
                // Create the opacity color which sets the transparencey of the blitted image.
                var color = Color.FromArgb((byte)Convert.ToInt32(255 * opacity), 255, 255, 255);
                //todo: rethink opacity. There is opacity at layer level, and could be at tile level.

                targetBitmap.Blit(destRounded, bitmap, sourceRect, color, WriteableBitmapExtensions.BlendMode.Alpha);
                //!!!targetBitmap.DrawRectangle((int)destRounded.Left, (int)destRounded.Top, (int)destRounded.Right, (int)destRounded.Bottom, Colors.Red);
            }
            catch (Exception ex)
            {
                // todo report error
                Console.WriteLine(ex.Message);
                memoryCache.Remove(tile.Index);
            }
        }
开发者ID:HackatonArGP,项目名称:Guardianes,代码行数:23,代码来源:WbxMapRenderer.cs

示例14: Init


//.........这里部分代码省略.........
                mCurrentDrawTarget = (WriteableBitmap)res.GetInternalObject();
                mCurrentDrawTargetIndex = drawTarget;
                return oldDrawTarget;
            };

            syscalls.maGetScrSize = delegate()
            {
                return MoSync.Util.CreateExtent(mBackBuffer.PixelWidth, mBackBuffer.PixelHeight);
            };

            syscalls.maGetImageSize = delegate(int handle)
            {
                Resource res = runtime.GetResource(MoSync.Constants.RT_IMAGE, handle);
                BitmapSource src = (BitmapSource)res.GetInternalObject();
                if (src == null)
                    MoSync.Util.CriticalError("maGetImageSize used with an invalid image resource.");
                int w = 0, h = 0;

                MoSync.Util.RunActionOnMainThreadSync(() =>
                {
                    w = src.PixelWidth;
                    h = src.PixelHeight;
                });

                return MoSync.Util.CreateExtent(w, h);
            };

            syscalls.maDrawImage = delegate(int image, int left, int top)
            {
                Resource res = runtime.GetResource(MoSync.Constants.RT_IMAGE, image);
                WriteableBitmap src = (WriteableBitmap)res.GetInternalObject();
                Rect srcRect = new Rect(0, 0, src.PixelWidth, src.PixelHeight);
                Rect dstRect = new Rect(left, top, src.PixelWidth, src.PixelHeight);
                mCurrentDrawTarget.Blit(dstRect, src, srcRect, WriteableBitmapExtensions.BlendMode.Alpha);
            };

            syscalls.maDrawImageRegion = delegate(int image, int srcRectPtr, int dstPointPtr, int transformMode)
            {
                Resource res = runtime.GetResource(MoSync.Constants.RT_IMAGE, image);
                WriteableBitmap src = (WriteableBitmap)res.GetInternalObject();

                Memory dataMemory = core.GetDataMemory();
                int srcRectX = dataMemory.ReadInt32(srcRectPtr + MoSync.Struct.MARect.left);
                int srcRectY = dataMemory.ReadInt32(srcRectPtr + MoSync.Struct.MARect.top);
                int srcRectW = dataMemory.ReadInt32(srcRectPtr + MoSync.Struct.MARect.width);
                int srcRectH = dataMemory.ReadInt32(srcRectPtr + MoSync.Struct.MARect.height);
                int dstPointX = dataMemory.ReadInt32(dstPointPtr + MoSync.Struct.MAPoint2d.x);
                int dstPointY = dataMemory.ReadInt32(dstPointPtr + MoSync.Struct.MAPoint2d.y);

                Rect srcRect = new Rect(srcRectX, srcRectY, srcRectW, srcRectH);
                Rect dstRect = new Rect(dstPointX, dstPointY, srcRectW, srcRectH);

                GraphicsUtil.DrawImageRegion(mCurrentDrawTarget, dstPointX, dstPointY, srcRect, src, transformMode, mClipRect);
            };

            syscalls.maCreateDrawableImage = delegate(int placeholder, int width, int height)
            {
                Resource res = runtime.GetResource(MoSync.Constants.RT_PLACEHOLDER, placeholder);
                res.SetResourceType(MoSync.Constants.RT_IMAGE);
                WriteableBitmap bitmap = null;

                MoSync.Util.RunActionOnMainThreadSync(() =>
                {
                    bitmap = new WriteableBitmap(width, height);

                    for (int i = 0; i < bitmap.PixelWidth * bitmap.PixelHeight; i++)
开发者ID:ronald132,项目名称:MoSync,代码行数:67,代码来源:MoSyncGraphicsModule.cs

示例15: DrawGrid

        private void DrawGrid(WriteableBitmap writeableBitmap)
        {
            Color color = Colors.White;
            color.A = 50;
            
            if (OverlayActivated)
            {
                if (SelectedOverlay != null && File.Exists(SelectedOverlay))
                {
                    if (_overlayImage == null)
                    {
                        BitmapImage bitmapSource = new BitmapImage();
                        bitmapSource.DecodePixelWidth = writeableBitmap.PixelWidth;
                        bitmapSource.BeginInit();
                        bitmapSource.UriSource = new Uri(SelectedOverlay);
                        bitmapSource.EndInit();
                        _overlayImage = BitmapFactory.ConvertToPbgra32Format(bitmapSource);
                        _overlayImage.Freeze();
                    }
                    int x = writeableBitmap.PixelWidth * OverlayScale / 100;
                    int y = writeableBitmap.PixelHeight * OverlayScale / 100;
                    int xx = writeableBitmap.PixelWidth * OverlayHorizontal / 100;
                    int yy = writeableBitmap.PixelWidth * OverlayVertical / 100;
                    writeableBitmap.Blit(
                        new Rect(0 + (x / 2) + xx, 0 + (y / 2) + yy, writeableBitmap.PixelWidth - x,
                            writeableBitmap.PixelHeight - y),
                        _overlayImage,
                        new Rect(0, 0, _overlayImage.PixelWidth, _overlayImage.PixelHeight));
                }
            }

            switch (GridType)
            {
                case 1:
                {
                    for (int i = 1; i < 3; i++)
                    {
                        writeableBitmap.DrawLine(0, (int) ((writeableBitmap.Height/3)*i),
                            (int) writeableBitmap.Width,
                            (int) ((writeableBitmap.Height/3)*i), color);
                        writeableBitmap.DrawLine((int) ((writeableBitmap.Width/3)*i), 0,
                            (int) ((writeableBitmap.Width/3)*i),
                            (int) writeableBitmap.Height, color);
                    }
                    writeableBitmap.SetPixel((int) (writeableBitmap.Width/2), (int) (writeableBitmap.Height/2), 128,
                        Colors.Red);
                }
                    break;
                case 2:
                {
                    for (int i = 1; i < 10; i++)
                    {
                        writeableBitmap.DrawLine(0, (int) ((writeableBitmap.Height/10)*i),
                            (int) writeableBitmap.Width,
                            (int) ((writeableBitmap.Height/10)*i), color);
                        writeableBitmap.DrawLine((int) ((writeableBitmap.Width/10)*i), 0,
                            (int) ((writeableBitmap.Width/10)*i),
                            (int) writeableBitmap.Height, color);
                    }
                    writeableBitmap.SetPixel((int) (writeableBitmap.Width/2), (int) (writeableBitmap.Height/2), 128,
                        Colors.Red);
                }
                    break;
                case 3:
                {
                    writeableBitmap.DrawLineDDA(0, 0, (int) writeableBitmap.Width,
                        (int) writeableBitmap.Height, color);

                    writeableBitmap.DrawLineDDA(0, (int) writeableBitmap.Height,
                        (int) writeableBitmap.Width, 0, color);
                    writeableBitmap.SetPixel((int) (writeableBitmap.Width/2), (int) (writeableBitmap.Height/2), 128,
                        Colors.Red);
                }
                    break;
                case 4:
                {
                    writeableBitmap.DrawLineDDA(0, (int) (writeableBitmap.Height/2), (int) writeableBitmap.Width,
                        (int) (writeableBitmap.Height/2), color);

                    writeableBitmap.DrawLineDDA((int) (writeableBitmap.Width/2), 0,
                        (int) (writeableBitmap.Width/2), (int) writeableBitmap.Height, color);
                    writeableBitmap.SetPixel((int) (writeableBitmap.Width/2), (int) (writeableBitmap.Height/2), 128,
                        Colors.Red);
                }
                    break;
                default:
                    break;
            }

            if (ShowRuler)
            {
                int x1 = writeableBitmap.PixelWidth*HorizontalMin/100;
                int x2 = writeableBitmap.PixelWidth*HorizontalMax/100;
                int y2 = writeableBitmap.PixelHeight*(100-VerticalMin)/100;
                int y1 = writeableBitmap.PixelHeight*(100-VerticalMax)/100;

                FillRectangle2(writeableBitmap, 0, 0, writeableBitmap.PixelWidth, writeableBitmap.PixelHeight, Color.FromArgb(128, 128, 128, 128));
                FillRectangleDeBlend(writeableBitmap, x1, y1, x2, y2, Color.FromArgb(128, 128, 128, 128));
                writeableBitmap.DrawRectangle( x1, y1, x2, y2, color);

//.........这里部分代码省略.........
开发者ID:tomriddle1234,项目名称:digiCamControl,代码行数:101,代码来源:LiveViewViewModel.cs


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