0

I have start to build my first software and i try to copy to clipboard a e.graphic draw in a panel but wen i try to copy the image are empty How can i copy my graphic to clipboard as a png image from paint event

This is my code.

Dim fileName = OpenFileDialog1.FileName

        Dim image1 = Image.FromFile(fileName, True)

        Dim texture As New TextureBrush(image1)
        texture.WrapMode = Drawing2D.WrapMode.Tile

        Dim font As New Font("Arial", 8, FontStyle.Bold)

        e.Graphics.DrawString(textoutline, FontDialog1.Font, texture, TextBox2.Text, TextBox3.Text)

And i try to copy to clipboard with this code

Dim graphicsImage = New Bitmap(Panel1.Width, Panel1.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb)
    Clipboard.SetImage(graphicsImage)

but i need to copy as png format how can i save it

  • As of now, you are sending to the ClipBoard a blank Image (there's nothing drawn on it, unless you're doing something else not shown here). Also, where is the `Paint` event? -- Since you have just started, do yourself a favor and set `Option Explicit On` and `Option Strict On` in all of your projects. Lots of headaches avoided (for example, you are passing `float` coordinates as strings in `e.Graphics.DrawString()`). – Jimi Jul 15 '18 at 05:34

1 Answers1

0

As far as I know, the image stored in memory is a bitmap. Why do you need it to be on the clipboard as a PNG? If it's just for the purpose of saving it to file, then you can use your already defined image object that you defined in this line ..

Dim image1 = Image.FromFile(fileName, True)

There is no need to store is as a PNG because you can save it in any of the supported formats .. Like so

    Image1.Save("filename", System.Drawing.Imaging.ImageFormat.Png)

However, if you want to send the image as an email attachment, you could do something like the answer on this Stack answer. Its in c#, but you get the idea.

David Wilson
  • 4,369
  • 3
  • 18
  • 31