将图像分成块-C# [英] dividing images into blocks-C#
本文介绍了将图像分成块-C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一个基于C#的图像处理应用程序。在该项目中,要完成一项任务,我想要一种机制将图像分成块。
假设我有一个图像,我想将该图像分成3X3矩阵,即9个部分。我怎么能这样做?
I'm developing a C# based image processing application.On that project, to do a task I want a mechanism to divide an image in to blocks.
Suppose i have an image and i want to split that image into 3X3 matrix i.e. 9 parts. How can i do that?
推荐答案
比如说,你需要创建一个代表单个块的独立位图。怎么样?创建所需大小的位图
的新实例。比你需要在其中绘制一些图像。使用方法System.Drawing.Graphics.FromImage
。它将为您提供在位图上绘制内容的实例。使用此实例和源位图,在目标(片段)位图上绘制源位图的一部分。不要忘记处理所有需要处理的东西;使用使用
语句(不要与using指令混淆)。这就是全部。
请参阅:
https://msdn.microsoft.com/en-us/library/system.drawing.bitmap%28v=vs.110%29.aspx [ ^ ],
https://msdn.microsoft.com/en-us/library/system.drawing.graphics%28v=vs.110%29.aspx [ ^ ],
https:// msdn .microsoft.com / zh-cn / library / system.drawing.graphics.fromimage(v = vs.110).aspx [ ^ ],
https://msdn.microsoft.com/en-us/library/system.drawing.graphics.drawimage%28v=vs.110 %29.aspx [ ^ ]。
-SA
Say, you need to create a separate bitmap representing a single block. How? Create a new instance ofBitmap
of required size. Than you need to draw some image in it. Use the methodSystem.Drawing.Graphics.FromImage
. It will give you the instance to draw something on a bitmap. Using this instance and source bitmap, draw a part of the source bitmap on your target (fragment) bitmap. Don't forget to dispose all that needs to be disposed; useusing
statement for that (not to be mixed up with "using" directive). That's all.
Please see:
https://msdn.microsoft.com/en-us/library/system.drawing.bitmap%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.drawing.graphics%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.drawing.graphics.fromimage(v=vs.110).aspx[^],
https://msdn.microsoft.com/en-us/library/system.drawing.graphics.drawimage%28v=vs.110%29.aspx[^].
—SA
这篇关于将图像分成块-C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文