Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

Drawing on Custom image control

Code
Dim img As Image = Image.FromFile(location)
    Dim image1 As Image = New Bitmap(img.Width, img.Height)
    Dim G As Graphics = Graphics.FromImage(image1)
    G.DrawImage(img, New Rectangle(0, 0, image1.Width, image1.Height), 0, 0, image1.Width, image1.Height, GraphicsUnit.Pixel)
    img.Dispose()
    G.DrawString(Str, New Font("Arial", 20, FontStyle.Bold, GraphicsUnit.Pixel), New SolidBrush(Color.FromArgb(75, 0, 0, 0)), New Point(x, y))
    G.Dispose()
Perhaps you can just use the paint event instead of the custom one?
(Jul 14, 2013 06:44 AM)Doomsapian Wrote:  If you mean just adding a handler to the custom control for paint, that doesn't work. I tried it but I think (specifically because it says Protected Overrides) because of the one in the control, it screws it up.

If you mean putting my code inside the paint event in the control class, I would have to make about a billion variables and functions public which would cause all kinds of problems.

I meant just using the paint event like this:
[Image: Z5SufSb.png]

It should work as the paint event (as shown above) is calledafter drawing everything inside the control.
You can just draw on the Image that is inside the Image property? (From the top of my head:)
Code
Dim G as graphics = Graphics.FromImage(PicBox.Image)
G.DrawStuff
(Jul 15, 2013 10:53 PM)Doomsapian Wrote:  Mava. What would I do without you, you magnificent beast. My only problem is that every thing that I draw looks like total shit.

[Image: B9IxB84.jpg]

vs Original

[Image: DnnV3jS.jpg]

Two very different images. The original has transparency in it and I think thats getting destroyed. Not sure whats going on with the sizing though.

And I've just gone back to my old problem of the image drawing itself a million times because the Imagebox is constantly invalidated. Like the idea is the image is meant to move, but not create a million copies of itself.

Working with graphics is just not fun in anyway.

Ah, I think you're drawing the image many times on top of itself. That's why it looks so weird.
Perhaps you can just "refresh" the image every time you draw on it? (G.Clear(), G.DrawImage("Original image"), G.DrawImage("the transparent thingy"))
Try double buffering your control and see if that helps at all.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by ZettabitMar 5, 2023 12:30 AM 7 1,162 Mar 5, 2023 12:30 AM
Last Post: NULL STERN
[C#] by C++Dec 29, 2019 06:16 PM 16 830 Dec 29, 2019 06:16 PM
Last Post: DNA
[Python] by DistrictApr 7, 2019 03:14 AM 4 229 Apr 7, 2019 03:14 AM
Last Post: lockhead