منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب
كيف أحول System.Drawing.Graphics إلى System.Drawing.Image ؟ - نسخة قابلة للطباعة

+- منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب (http://vb4arb.com/vb)
+-- قسم : قسم لغة الفيجوال بيسك VB.NET (http://vb4arb.com/vb/forumdisplay.php?fid=182)
+--- قسم : قسم اسئلة VB.NET (http://vb4arb.com/vb/forumdisplay.php?fid=183)
+--- الموضوع : كيف أحول System.Drawing.Graphics إلى System.Drawing.Image ؟ (/showthread.php?tid=7176)



كيف أحول System.Drawing.Graphics إلى System.Drawing.Image ؟ - Aly El-Haddad - 29-11-12

السلام عليكم و رحمة الله و بركاته
الس[SIZE=4]ؤال واضح من العنوان، كيف أ[SIZE=4]حول System.Drawing.Graphics إلى System.Drawing.Image ؟[/SIZE]

أكثر توضيحاً:
كيف أحول الكائن الناتج عن Me.CreateGraphics() إلى System.Drawing.Image
أنا أعرف الكود:
كود :
[SIZE=4][SIZE=4]Dim bmp As New Bitmap(50, 50)
Di[SIZE=4]m gfcs As Graphics = Graphics.FromImage(bmp)
gfcs.DrawImage([SomeImageObject][SIZE=4])[/SIZE][/SIZE]
[/SIZE][/SIZE][/b][/SIZE][/COLOR][b]
[COLOR=#000000]
لكن هذ[SIZE=4]ا لرسم صورة على ا[SIZE=4]لـBitmap bmp
[SIZE=4]و أعرف أيضاً الكود:
كود :
Dim bmp As[SIZE=4] New Bitmap(50, 50)[/SIZE]
Me.DrawTo[SIZE=4]Bitmap(bmp, New Rectangle(0, 0, 50, 50)
[/SIZE]
[/SIZE]لكن هذا يرسم الـForm بالـControls التي فوقها

فهل من حل لرسم الـForm بالتأثيرات التي عليها [SIZE=4]و بدون [SIZE=4]رسم الـControls التي عليها[/SIZE][/SIZE][/SIZE][/SIZE]
على كائن من ن[SIZE=4]وع System.Drawing.Image ؟[/SIZE]



كيف أحول System.Drawing.Graphics إلى System.Drawing.Image ؟ - Sajad - 29-11-12

السلام عليكم

لتحويل كائن الBitmap الى كائن الImage استخدم هذا الكود:

Dim img As Image
Dim bmp As Bitmap
img = bmp


كيف أحول System.Drawing.Graphics إلى System.Drawing.Image ؟ - SaLoOoMX - 29-11-12

كود :
Dim bound As Rectangle              
        Dim screenshot As Bitmap
        Dim gravic As Graphics

        bound = Screen.PrimaryScreen.Bounds
        screenshot = New Bitmap(bound.Width, bound.Height, System.Drawing.Imaging.PixelFormat.Format64bppArgb)
        gravic = gravic.FromImage(screenshot)
        gravic.CopyFromScreen(bound.X, bound.Y, 0, 0, bound.Size, CopyPixelOperation.SourceCopy)

        PictureBox1.Image = screenshot



كيف أحول System.Drawing.Graphics إلى System.Drawing.Image ؟ - Aly El-Haddad - 29-11-12

sajad كتب :السلام عليكم

لتحويل كائن الBitmap الى كائن الImage استخدم هذا الكود:

Dim img As Image
Dim bmp As Bitmap
img = bmp
عفواً أخي، لم أرد تحويل Bitmap إلى Image
SaLoOoMX كتب :
كود :
Dim bound As Rectangle              
        Dim screenshot As Bitmap
        Dim gravic As Graphics

        bound = Screen.PrimaryScreen.Bounds
        screenshot = New Bitmap(bound.Width, bound.Height, System.Drawing.Imaging.PixelFormat.Format64bppArgb)
        gravic = gravic.FromImage(screenshot)
        gravic.CopyFromScreen(bound.X, bound.Y, 0, 0, bound.Size, CopyPixelOperation.SourceCopy)

        PictureBox1.Image = screenshot
عفواً أخي، لم أرد تصوير الشاشة


كيف أحول System.Drawing.Graphics إلى System.Drawing.Image ؟ - sooriaty03 - 29-11-12

أخي الكريم
جرب هذه الطريقة
فهي أولا ستلغي الـ CONTROLS من أعلى الإطار
ثم يخفي الأدوات الموجودة على الفورم
وبعدها يقوم بأخذ صورة للفورم ثم يعيد كل شيء كما كان

كود :
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
        For Each A In Me.Controls
            A.visible = False
        Next
        Dim bmp As New Bitmap(Me.Size.Width, Me.Size.Height)
        Me.DrawToBitmap(bmp, New Rectangle(0, 0, Me.Size.Width, Me.Size.Height))
        PictureBox1.Image = bmp
        Me.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable
        For Each A In Me.Controls
            A.visible = True
        Next


أرجو لك التوفيق


كيف أحول System.Drawing.Graphics إلى System.Drawing.Image ؟ - Aly El-Haddad - 29-11-12

sooriaty03 كتب :أخي الكريم
جرب هذه الطريقة
فهي أولا ستلغي الـ CONTROLS من أعلى الإطار
ثم يخفي الأدوات الموجودة على الفورم
وبعدها يقوم بأخذ صورة للفورم ثم يعيد كل شيء كما كان

كود :
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
        For Each A In Me.Controls
            A.visible = False
        Next
        Dim bmp As New Bitmap(Me.Size.Width, Me.Size.Height)
        Me.DrawToBitmap(bmp, New Rectangle(0, 0, Me.Size.Width, Me.Size.Height))
        PictureBox1.Image = bmp
        Me.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable
        For Each A In Me.Controls
            A.visible = True
        Next


أرجو لك التوفيق

شكراً لك أخي، لكن ماذا لو أردت تحويل كائن الـGraphics الناتج عن Me.CreateGraphics() إلى صورة؟


كيف أحول System.Drawing.Graphics إلى System.Drawing.Image ؟ - oneyemenweb2 - 29-11-12

سؤلك غامض اخي
هل تقصد الكائنات مثل المربع والمثلث المنشاء تريد تحفظة على اساس صورة ولكن ليس الى ملف بل الى البرنامج وضح لنا اكثر


كيف أحول System.Drawing.Graphics إلى System.Drawing.Image ؟ - silverlight - 30-11-12

كود :
Imports System.Drawing.Drawing2D

Public Class Form1

    Private Sub Form1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint

        ' تعريف الصورة
        Dim bmp As New Bitmap(150, 150)

        ' تعريف متغيرات للجرافكس
        Using gr As Graphics = Graphics.FromImage(bmp)

            Dim rect As Rectangle = New Rectangle(0, 0, 150, 150)
            Dim lgb As New LinearGradientBrush(rect, Color.Blue, Color.Azure, 90)
            ' إرسم شيئا علي الصورة
            gr.FillRectangle(lgb, rect)
        End Using

        'إرسم الصورة علي سطح الفورم
        Using g As Graphics = Me.CreateGraphics
            g.DrawImage(bmp, 10, 10)
        End Using

    End Sub

End Class



كيف أحول System.Drawing.Graphics إلى System.Drawing.Image ؟ - Aly El-Haddad - 30-11-12

silverlight كتب :
كود :
Imports System.Drawing.Drawing2D

Public Class Form1

    Private Sub Form1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint

        ' تعريف الصورة
        Dim bmp As New Bitmap(150, 150)

        ' تعريف متغيرات للجرافكس
        Using gr As Graphics = Graphics.FromImage(bmp)

            Dim rect As Rectangle = New Rectangle(0, 0, 150, 150)
            Dim lgb As New LinearGradientBrush(rect, Color.Blue, Color.Azure, 90)
            ' إرسم شيئا علي الصورة
            gr.FillRectangle(lgb, rect)
        End Using

        'إرسم الصورة علي سطح الفورم
        Using g As Graphics = Me.CreateGraphics
            g.DrawImage(bmp, 10, 10)
        End Using

    End Sub

End Class

شكراً لك أخي، و لكل من حاول مساعدتي Smile