如何以高分辨率将可滚动面板保存到位图 [英] How to save a scrollable panel to a bitmap in high resolution

查看:82
本文介绍了如何以高分辨率将可滚动面板保存到位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨:)请问,请帮帮我吗?我已经花了很多时间而无法解决它。我有一个带有按钮和图像的可滚动面板,我想以.bmp图像的方式发送所有内容。但是我的高度只有它的一半,底部的
a黑色空间没有填满其余的面板。


我认为这看起来像是因为我正在使用的代码。我正在尝试改编一个采用表格的大纲。我喜欢它,因为它在过程结束时显示了高分辨率图像。嗯,这是代码。请问,请告诉我b $ b我的错误是什么?



进口System.Drawing.Imaging

Imports System.Windows.Forms

模块模块1



   私有声明自动功能BitBlt Lib" gdi32.dll" (ByVal _

   hdcDest As IntPtr,ByVal nXDest As Integer,ByVal _

   nYDest As Integer,ByVal nWidth As Integer,ByVal _

   nHeight As Integer,ByVal hdcSrc As IntPtr,ByVal nXSrc _

   As Integer,ByVal nYSrc As Integer,ByVal dwRop As  _

   System.Int32)As Boolean

    Private Const SRCCOPY As Integer =& HCC0020



    "******************* **************

    'PEGAR LO SIGUIENTE EN EL EVENTO QUE QUIERAS:SaveFormToBMP

    "******************* **************
$


    Sub SavePanelToBMP2()

        Dim bm As Bitmap = GetPanelImage()

        Dim RutaDeImagen As String =" C:\ Users \ Sergio \Google Drive \BIBLIOTECAS 2 \ Visual Studio 2010 \Projects \ Myy Virtual Folder 1 \ MyMy虚拟文件夹1 \\\\Debug \\ \\ CUIDES ESTA CARPETA \IMPRESIONES \ test111.bmp" b
        bm.Save(RutaDeImagen,ImageFormat.Bmp)

       哔()(

   结束分


   私有函数GetPanelImage()作为位图

        '获取此表单的图形对象。

        Dim me_gr As Graphics = OMypanel.CreateGraphics



$
        '制作一个位图来保存图像。

        Dim bm As New Bitmap(OMypanel.Width,_

     OMypanel.Height,me_gr)







        Dim bm_gr As Graphics = Graphics.FromImage(bm)

        Dim bm_hdc As IntPtr = bm_gr.GetHdc



        '获取表单的hDC。我们必须在&bbsp
 之后执行此操作。       '创建新的位图,使用me_gr。

        Dim me_hdc As IntPtr = me_gr.GetHdc



        '将表格的图像粘贴到位图上。

        BitBlt(bm_hdc,0,0,OMypanel.Width,_

       OMypanel.Height,_

        me_hdc,0,0,SRCCOPY)

        me_gr.ReleaseHdc(me_hdc)

        bm_gr.ReleaseHdc(bm_hdc)



        '返回结果。

       返回bm

   结束功能



结束模块


解决方案

不幸的是,只有我自己知道可滚动控件客户端矩形显示区域。


因此,建议的可滚动控件或Form的方法是使用另一个Panel,它可以包含所有控件而无需滚动,大小因此所有控件都显示在其客户端矩形中。


然后将Panel作为控件添加到可滚动控件控件数组。


让我们说Panel2包含所有控件并且不可滚动且不需要因为它是大小足以使所有控件显示在其客户端矩形中。并且Panel2的位置设置为0,0。


然后Panel1是可滚动面板。 Panel1.Controls.Add(Panel2)可以工作。



Panel Class
提供
DrawToBitmap方法
然后您可以使用它将Panel2绘制到一个Bitmap,我相信它将绘制Panel并显示所有控件在Panels客户端矩形到Bitmap。


虽然这样做之后我想你已经拥有的代码会得到一个精确的Panel2图形对象,上面有所有控件。


Hi :) Could you, please, help me with this? I have spent many hours and couldn't solve it, yet. I have a scrollable panel with buttons and an image and I'd like to send everything the way it looks to a .bmp image. But I get just half the height of it and a black space at the bottom which wasn't filled with the rest of the panel.

I think it looks like this because of the code I'm using. I'm trying to adapt one which takes a screenshoot of the form. I liked it because it showed a high resolution image at the end of the process. Well, this is the code. Could you, please,  tell me what I'm doing wrong?

Imports System.Drawing.Imaging
Imports System.Windows.Forms
Module Module1

    Private Declare Auto Function BitBlt Lib "gdi32.dll" (ByVal _
   hdcDest As IntPtr, ByVal nXDest As Integer, ByVal _
   nYDest As Integer, ByVal nWidth As Integer, ByVal _
   nHeight As Integer, ByVal hdcSrc As IntPtr, ByVal nXSrc _
   As Integer, ByVal nYSrc As Integer, ByVal dwRop As  _
   System.Int32) As Boolean
    Private Const SRCCOPY As Integer = &HCC0020

    '***************************************************************
    'PEGAR LO SIGUIENTE EN EL EVENTO QUE QUIERAS: SaveFormToBMP
    '***************************************************************

    Sub SavePanelToBMP2()
        Dim bm As Bitmap = GetPanelImage()
        Dim RutaDeImagen As String = "C:\Users\Sergio\Google Drive\BIBLIOTECAS 2\Visual Studio 2010\Projects\My Virtual Folder 1\My Virtual Folder 1\bin\Debug\CUIDAR ESTA CARPETA\IMPRESIONES\test111.bmp"
        bm.Save(RutaDeImagen, ImageFormat.Bmp)
        Beep()

    End Sub

    Private Function GetPanelImage() As Bitmap
        ' Get this form's Graphics object.
        Dim me_gr As Graphics = OMypanel.CreateGraphics


        ' Make a Bitmap to hold the image.
        Dim bm As New Bitmap(OMypanel.Width, _
        OMypanel.Height, me_gr)



        Dim bm_gr As Graphics = Graphics.FromImage(bm)
        Dim bm_hdc As IntPtr = bm_gr.GetHdc

        ' Get the form's hDC. We must do this after 
        ' creating the new Bitmap, which uses me_gr.
        Dim me_hdc As IntPtr = me_gr.GetHdc

        ' BitBlt the form's image onto the Bitmap.
        BitBlt(bm_hdc, 0, 0, OMypanel.Width, _
            OMypanel.Height, _
            me_hdc, 0, 0, SRCCOPY)
        me_gr.ReleaseHdc(me_hdc)
        bm_gr.ReleaseHdc(bm_hdc)

        ' Return the result.
        Return bm
    End Function

End Module

解决方案

Unfortunately a scrollable controls client rectangle displayed area is only able to be drawn to my knowledge.

So the suggested method for a scrollable control or Form for that matter is to then use another Panel which can contain all of the controls without needing to be scrolled, sized so all of the controls display in its client rectangle.

Then add that Panel as a control to the scrollable controls control array.

Lets say Panel2 contains all the controls and is not scrollable and does not need to be since it is sized large enough that all of the controls display in its client rectangle. And Panel2's location is set to 0, 0.

Then Panel1 is the scrollable panel. Panel1.Controls.Add(Panel2) would work.

And since the Panel Class provides a DrawToBitmap Method then you can use that to draw Panel2 to a Bitmap which I believe will draw the Panel and all the controls displayed in the Panels client rectangle to a Bitmap.

Although after doing this I suppose the code you already have would get an accurate graphics object of Panel2 with all the controls on it.


这篇关于如何以高分辨率将可滚动面板保存到位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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