|
-
Aug 6th, 2010, 12:52 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] Layer rendering (image program)
Hello all 
I'm working on my second project; a layered image displayer.
It works like this:
- The user adds a new "image layer"
- The user can set the texture, image, size, rotation and color
- This all can be done using a selection square and some dialogs
It all works fine, but I found that there is one thing still unclear to me:
- Can you render layers without totally starting over (refresh) on every change?
As example, I have 200 image layers. I change one image layer somewhere in between them, and the program has to refresh all those images. (1 - 200)
This takes awfully long.
Now I found a small solution; I gave all layers a "finalimage" so it can render a single layer. Next I used, in the program, a back, active and fore layer.
This way the program only has to render 3 images when chaging the "active" layer. When you select another layer, all 3 layers will refresh. (with all those 200 layers).
here is the code to get an idea:
Code:
Dim OLDINDEX As Integer = -1
Dim BackLayer As New Bitmap(800, 600)
Dim ActiveLayer As New Bitmap(800, 600)
Dim FrontLayer As New Bitmap(800, 600)
Public CurrentIndex As Integer = -1
Public PerformGlobalUpdate As Boolean = False
Public Sub Render(ByRef g As Graphics)
'Get the layer modified types
Dim UpdateActiveLayer As Boolean = False
Dim UpdateBackLayer As Boolean = False
Dim UpdateFrontLayer As Boolean = False
If OLDINDEX = CurrentIndex And PerformGlobalUpdate = False Then
For i As Integer = 0 To Layers.Count - 1
If Layers(i).Changed = True And i < CurrentIndex Then UpdateBackLayer = True
If Layers(i).Changed = True And i > CurrentIndex Then UpdateFrontLayer = True
If Layers(i).Changed = True And i = CurrentIndex Then UpdateActiveLayer = True
Next
Else
PerformGlobalUpdate = False
UpdateBackLayer = True
UpdateActiveLayer = True
UpdateFrontLayer = True
End If
If UpdateActiveLayer = True Then ActiveLayer = New Bitmap(800, 600)
If UpdateFrontLayer = True Then FrontLayer = New Bitmap(800, 600)
If UpdateBackLayer = True Then BackLayer = New Bitmap(800, 600)
If UpdateBackLayer = True Or UpdateFrontLayer = True Or UpdateActiveLayer = True Then
Dim e As Integer = Layers.Count - 1
Dim s As Integer = 1
If UpdateBackLayer = False Then s = CurrentIndex
If UpdateFrontLayer = False Then e = CurrentIndex
For i As Integer = s To e
If i < Layers.Count And i > 0 And ((UpdateBackLayer = True And i < CurrentIndex) Or (UpdateFrontLayer = True And i > CurrentIndex) Or (UpdateActiveLayer = True And i = CurrentIndex)) Then
If i < CurrentIndex Then Layers(i).ApplyToImage(BackLayer)
If i > CurrentIndex Then Layers(i).ApplyToImage(FrontLayer)
If i = CurrentIndex Then Layers(i).ApplyToImage(ActiveLayer)
End If
Next
End If
'Render all 3 the layers
If CurrentIndex <> 0 Then g.DrawImage(BackLayer, New Point(0, 0))
If CurrentIndex <> -1 Then g.DrawImage(ActiveLayer, New Point(0, 0))
If CurrentIndex <> Layers.Count - 1 Then g.DrawImage(FrontLayer, New Point(0, 0))
OLDINDEX = CurrentIndex
End Sub
It all works fine, but the only problem now is that it takes ages to select a different layer.
Anyone knows of an alternative solution to render different layers?
Tags for this Thread
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
|