欢迎来到天天文库
浏览记录
ID:10120418
大小:252.00 KB
页数:6页
时间:2018-06-11
《(24).基本图形的使用(3)图形的操作》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、接上一篇文章,在WPF中对图形进行操作,上一篇文章中使用了ImageSource(BitmapSource)中的两种:1、使用BitmapImage加载图片2、使用RenderTargetBitmap创建图片3、使用RenderTargetBitmap修改图片本文继续4、使用WriteableBitmap修改图片在使用RenderTargetBitmap修改图片中,原图片不变,只相当于在原图片的基础上添加一节新的内容,而如果对图片进行大的更改RenderTargetBitmap就不可以了,我们可以使用Writea
2、bleBitmap对图片进行修改,例如将生成一个返向位图:1:5:6:<
3、Grid.RowDefinitions>7:8:9:10:11:12:13: 1:pri
4、vatevoidBuildImage()2:{3:BitmapImageimg=newBitmapImage();4:img.BeginInit();5: 6:img.UriSource=newUri("http://images.cnblogs.com/logo.gif");7: 8:img.DownloadCompleted+=delegate9:{10:BitmapSourcesource=newFormatConvertedBitmap(11:img,PixelFormats.Pbgra32,null,0
5、);12: 13:WriteableBitmapbmp=newWriteableBitmap(source);14: 15:intwidth=bmp.PixelWidth;16:intheight=bmp.PixelHeight;17: 18:int[]pixelData=newint[width*height];19:intwidthInBytes=4*width;20: 21:bmp.CopyPixels(pixelData,widthInBytes,0);22: 23:for(inti=0;i6、ata.Length;i++)24:{25:pixelData[i]^=0x00ffffff;26:}27: 28:bmp.WritePixels(newInt32Rect(0,0,width,height),pixelData,widthInBytes,0);29: 30:targetImage.Source=bmp;31:};32: 33:img.EndInit();34:}35: 36:privatevoidWindow_Loaded(objectsender,RoutedEventArgse)37:{387、:BuildImage();39:}执行后的结果如下图所示:5、图像效果所有的用户界面元素都有BitmapEffects属性,可以对其内部的内容(不仅是图片)实现某些特殊的效果,例如:1:8、ndow2"Height="300"Width="300">5:6:7:8:9:10:11:12:13:
6、ata.Length;i++)24:{25:pixelData[i]^=0x00ffffff;26:}27: 28:bmp.WritePixels(newInt32Rect(0,0,width,height),pixelData,widthInBytes,0);29: 30:targetImage.Source=bmp;31:};32: 33:img.EndInit();34:}35: 36:privatevoidWindow_Loaded(objectsender,RoutedEventArgse)37:{38
7、:BuildImage();39:}执行后的结果如下图所示:5、图像效果所有的用户界面元素都有BitmapEffects属性,可以对其内部的内容(不仅是图片)实现某些特殊的效果,例如:1:8、ndow2"Height="300"Width="300">5:6:7:8:9:10:11:12:13:
8、ndow2"Height="300"Width="300">5:6:7:8:9:10:11:12:13:
此文档下载收益归作者所有