尺寸问题 [英] Dimentions problem

查看:86
本文介绍了尺寸问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


你好专家!


我有这条VB.Net代码,想知道是否有人可以帮我找出那个部分我需要哪个缺少,我知道这个论坛是针对网络表单,但我想也许有人可以用我的Windows窗体帮助我,我的代码需要一个屏幕
拍摄我的屏幕并将其保存到所需的位置我在其中提到, 这里是代码:

   Imports      系统      运行时       InteropServices     
进口 系统 绘图 成像 < /跨度> <跨度>&NBSP;
 
公开 FaultReport  
 
  &NBSP;
Dim ScreenSize 作为 尺寸 = 尺寸 我的 计算机 屏幕 Bounds 宽度 我的 计算机 屏幕 Bounds 高度   ;
  &NBSP;
Dim screenGrab As 位图 我的 计算机 屏幕 Bounds 宽度 我的 计算机 屏幕 Bounds 高度 <跨度>&NBSP;
  &NBSP;
Dim g As 系统 绘图 图形 = 系统 绘图 图形 FromImage screenGrab  
 
 
 
  &NBSP;
私人 Sub Button1_Click ByVal 发​​件人 正如 系统 对象 ByVal e 正如 系统 EventArgs H andles Button1 点击  
  
  &NBSP; &NBSP; &NBSP;
Dim fileNameWithPath As 字符串 = " C:\ FaultReport \" &安培; " FaultReport " &安培; TextBox5.Text& " jpg "&NBSP;
 
 
  &NBSP; &NBSP; &NBSP;尝试&NBSP;
 
  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; g.CopyFromScreen(新点(0,0),新点(0,0),ScreenSize) 
  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; screenGrab.Save(fileNameWithPath,System.Drawing.Imaging.ImageFormat.Jpeg) 
  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; MsgBox("
您的 故障 报告 已保存 Successfuly C :/ FaultReport ") 
  &NBSP; &NBSP; &NBSP;赶上例外情况 
  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; MsgBox("
错误 保存您的故障报告 please 再次尝试 ")&NBSP;
  &NBSP; &NBSP; &NBSP;结束尝试 
 
 
 
  &NBSP;结束子 
结束班

但问题是我不想要我的整个屏幕的屏幕截图,我只需要屏幕截图我的表单,所以我添加了以下内容,从屏幕截图的底部删除了不合适的部分,这对我来说非常适合,而且额外的
是:

 <跨度>&NBSP; &NBSP;    Dim       ScreenSize      作为     尺寸      =           尺寸      我的      计算机      屏幕       Bounds       宽度        我的      计算机      屏幕       Bounds       高度       -      50      <跨度>&NBSP; 
  &NBSP; Dim screenGrab As 位图 我的 计算机 屏幕 Bounds 宽度 我的 计算机 屏幕 Bounds 高度 - 50

现在唯一的问题是这个屏幕截图顶部的额外问题,这里我加了-50在从底部切下的高度之后,buti无法移除顶部部分 我是如何从底部移除额外的,可以任何人请查看
我的代码并尝试告诉我如何从中移除屏幕上方的镜头?我真的很感激,并提前感谢...

解决方案

您好:)


根据Winform的说法,你应该切断宽度和高度。


示例代码如下:


有关更多样本,您可以看到:


http: //www.codeproject.com/KB/cs/TeboScreen.aspx

   ;   私有   Sub    Button1_Click 发件人  作为  系统对象 ,   e   作为  系统 EventArgs )  句柄   Button1 点击          Dim    ScreenSize   作为  尺寸  =    尺寸宽度 ,  高度
         Dim   screenGrab   作为    位图宽度 ,  高度
         Dim   g   作为  系统绘图图形  =  系统绘图图形 FromImage screenGrab
         Dim   fileNameWithPath   作为  字符串  =  " C:\ _FaultReport.png"

          尝试             g .CopyFromScreen(< span style ="color:blue"> New   Point ,  顶部),     <跨度>乐ft   +  宽度,  顶部  +  高度),  ScreenSize
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; <跨度>克 <跨度>保存()
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; <跨度> screenGrab <跨度>保存(<跨度> fileNameWithPath
,  系统绘图成像 ImageFormat Png
             Application DoEvents ()

             <跨度>处置()
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; <跨度> MSGBOX
"你&NBSP;故障&NBSP;报告与NBSP;具有&NBSP;一直&NBSP;保存&NBSP; Successfuly&NBSP;在&NBSP; C:/ FaultReport"
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;   Catch   ex   作为  < span style ="color:#2b91af">例外

             MsgBox (的"错误 以 保存&NBSP;您的&NBSP;故障&NBSP;报告&NBSP;请&NBSP;尝试&NBSP;再次"
&NBSP;&NBSP;&NBSP;       结束  尝试

     结束  Sub


Hello experts!

I have this piece of VB.Net code and was wondering if someone can help me out figure out the part that i need which is missing, i know this forum is for web forms but i thought maybe some one can help me out with my windows form, my code takes a screeen shot of my screen and saves it for the desired location i mentioned in it, here is the code:

Imports System.Runtime.InteropServices 
Imports System.Drawing.Imaging 
 
Public Class FaultReport 
 
    Dim ScreenSize As Size = New Size(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height) 
    Dim screenGrab As New Bitmap(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height) 
    Dim g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(screenGrab) 
 
 
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
  
        Dim fileNameWithPath As String = "C:\FaultReport\" & "FaultReport" & TextBox5.Text & ".jpg" 
 
 
        Try 
 
            g.CopyFromScreen(New Point(0, 0), New Point(0, 0), ScreenSize) 
            screenGrab.Save(fileNameWithPath, System.Drawing.Imaging.ImageFormat.Jpeg) 
            MsgBox("Your Fault Report Has been Saved Successfuly in C:/FaultReport") 
        Catch ex As Exception 
            MsgBox("Error in saving your fault report, please try again") 
        End Try 
 
 
 
    End Sub 
End Class

but the problem is i dont want a screen shot of my whole screen, i need a screen shot for only my form, so i added the following which removed the unnessesary part from the bottom of the screen shot which was perfect for me, and the addition is:

    Dim ScreenSize As Size = New Size(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height -50) 
    Dim screenGrab As New Bitmap(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height -50)

now the only problem i have is the the extra on the top of this screen shot, here i added -50 after the height to cut from its bottom, buti couldnt remove the top part just how i removed the extra from the bottom, can any one please review my code and try to tell me how do i remove from the top of the screen shot? i would really appreciate it, and thanx in advance...

解决方案

Hello:)

You should cut off the width and height as the same as what you can see according to the Winform's.

Sample codes like this below:

For more samples, you can see:

http://www.codeproject.com/KB/cs/TeboScreen.aspx

    Private Sub Button1_Click(sender As System.Objecte As System.EventArgsHandles Button1.Click
        Dim ScreenSize As Size = New Size(Me.WidthMe.Height)
        Dim screenGrab As New Bitmap(Me.WidthMe.Height)
        Dim g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(screenGrab)
        Dim fileNameWithPath As String = "C:\FaultReport.png"

        Try
            g.CopyFromScreen(New Point(Me.LeftMe.Top), New Point(Me.Left + Me.WidthMe.Top + Me.Height), ScreenSize)
            g.Save()
            screenGrab.Save(fileNameWithPathSystem.Drawing.Imaging.ImageFormat.Png)
            Application.DoEvents()

            g.Dispose()
            MsgBox("Your Fault Report Has been Saved Successfuly in C:/FaultReport")
        Catch ex As Exception
            MsgBox("Error in saving your fault report, please try again")
        End Try

    End Sub


这篇关于尺寸问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆