以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  图片剪切  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=152203)

--  作者:漂亮美眉vszh
--  发布时间:2020/7/9 15:15:00
--  图片剪切
老师:在FOXTABLE内画了一个图,然后另存在一个图片,后续此图片会粘贴至EXCEL内,但图片太长了,需要用代码剪掉一部分,代码如何写?
图片点击可在新窗口打开查看此主题相关图片如下:1234.png
图片点击可在新窗口打开查看

--  作者:有点蓝
--  发布时间:2020/7/9 15:32:00
--  
Dim file As String = "E:\\问题\\123.png"
Dim img As Image = getimage(file)
Dim bmpOut As new Bitmap(290, 185, PixelFormat.Format24bppRgb) \'290为裁剪区域宽度,185为高度
Dim myGraphics As Graphics = Graphics.FromImage(bmpOut)
myGraphics.Clear(Color.White)
myGraphics.DrawImage(img, new Rectangle(0, 0, 290, 185), new Rectangle(270, 100, 290, 185), GraphicsUnit.Pixel) \'270为原图需要裁剪的区域的左边距,100为上边距
myGraphics.Dispose()
bmpOut.Save("E:\\问题\\123_1.png")

--  作者:林月
--  发布时间:2021/8/11 6:49:00
--  
这个代码应该是按照指定宽度290,指定高度185来裁剪的。 那要是想宽与高比例4:3剪切呢,如何操作呢 这里就会出现两种情况,一种是宽比高度大,就应该是以高度为标准按照三分之四倍确定宽度的值。 另外一种宽度比高度小,那就是以宽度的四分之三确定高度的值,不知道代码怎么实验,好像我的思路有点复杂,请老师指点
[此贴子已经被作者于2021/8/11 6:55:35编辑过]

--  作者:有点蓝
--  发布时间:2021/8/11 8:41:00
--  
先比较宽度和高度,如果宽大,就按比例计算高度;否则按比例计算宽度
--  作者:sunion
--  发布时间:2021/8/11 9:22:00
--  
以这个代码为例,我们如何获取get到图片的宽度和高度,new Rectangle这里第一、二个参数270、100如何设置,是留空吗?



Dim file As String = "E:\\问题\\123.png"
Dim img As Image = getimage(file)

                                                             ‘如何获取宽度?
                                                             ‘如何获取高度?

Dim bmpOut As new Bitmap(290, 185, PixelFormat.Format24bppRgb) \'290为裁剪区域宽度,185为高度
Dim myGraphics As Graphics = Graphics.FromImage(bmpOut)
myGraphics.Clear(Color.White)
myGraphics.DrawImage(img, new Rectangle(0, 0, 290, 185), new Rectangle(270, 100, 290, 185), GraphicsUnit.Pixel) \'270为原图需要裁剪的区域的左边距,100为上边距
myGraphics.Dispose()
bmpOut.Save("E:\\问题\\123_1.png")

--  作者:有点蓝
--  发布时间:2021/8/11 9:25:00
--  
参考:http://www.foxtable.com/webhelp/topics/2714.htm