|
-
Feb 27th, 2004, 12:28 PM
#1
Thread Starter
New Member
Drawing TGA on Vb.net
Ok, I have a problem. I wanted to show TGA files on my application. So I manage to code up something that does this. I have the TGA file loaded up in an array and decoded properly. But when I use a simple looping to go through the array at each pixel I set a brushcolor then use a fillrectangle, not the most efficient way. But just to get something quick and simple to 1st try.
The problem is that when I try to draw the image on a picture box control for even a 256x256 image, it is very slow. Even slower then I would expect for the way I did it. It looks like the brush color setting and draw routines are very slow. The loops themselves doesnt take much time which i wouldnt expect them to. The question is, is there some way to have the image rendered quickly, once I have it loaded into memory? I tried using bitmap class and that wasnt much help either.
The second problem is that I am trying to draw the image on a picturebox control. The image is selected by other controls on the form, which also places different buttons depending on what has been selected (which may include the picturebox). The problem is that the picture box seems to be rendered firstly out of sequence, which isnt a big problem in itself, just wierd. But the main problem is that the picturebox resets to the background after the other controls are placed on the form.
also what is strange is that even though i put the rendering code in the picturebox's paint event. it doesnt refresh the screen properly either. like when i cover up part of it. it refreshes but NOT that region that was blocked.
also the image seems to revert back to the background or image (that is default in the property and is a solid grayish color) just after it exits the paint event handler for the picturebox. so its like if the painting initially on the picturebox is happening before it does its default action and the image isnt being actually put into the picturebox's image or background property. cause when i try painting directly on the form with the same rendering routine instead the image doesnt dissappear.
here is what i am doing in the rendering routine:
public sub renderTGAImage(pb as picturebox, image as TGAimage)
Dim pbGraphics As System.Drawing.Graphics
pbGraphics = pb.CreateGraphics
for y = 0 to (height - 1)
for x = 0 to (width - 1)
ialpha = TGAimage.A(j)
ired = TGAimage.R(j)
igreen = TGAimage.G(j)
iblue = TGAimage.B(j)
Dim PenColor As New Pen(Color.FromArgb(ialpha, ired, igreen, iblue))
PPGraphics.DrawLine(PenColor, x, y, x+1, y+1)
j +=1
next
next
Private Sub pbPreviewpane_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles pbPreviewPane.Paint
Dim obj As PictureBox = CType(sender, PictureBox)
RenderTGAImage(obj, ImageArray)
End Sub <= break point here is when the image reverts back to background
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|