Saving images into an array
BlitzMax Forums/BlitzMax Beginners Area/Saving images into an array
| ||
Currently working on my vectortext project to save the A..Z to an array called VecChar[], That way each letter is stored in the array as an image so if I want to draw an A I would just use VecChar[0] and so on and so forth. Problem is when I'm saving the drawn letters into images I get an error. here's the code Global VecChar:Int[36] Local N:Int For Local Grab_X:Byte = 0 To 313 Step 13 VecChar[N] = CreateImage(Grab_X, 12, 1, DYNAMICIMAGE | MASKEDIMAGE) GrabImage VecFont[N], 0, 0 N:+1 Next Here's the ERROR: Compile Error: Expression of type 'Int' cannot be indexed Build Error: failed to compile C:/BlitzMax/projects/VectorText.bmx |
| ||
That array is useless the way I was telling you about.global font_1:TImage=createimage(character_width,character_height,total_num_characters, DYNAMICIMAGE|MASKEDIMAGE) for local i:int =0 to total_num_characters-1 cls ' clear the buffer ' draw character here ensure it follows ascii order!!! flip ' set up font_1.frames[i] =GrabImage( image:TImage,x,y,frame=0 ) next This should do the following to convert your vector letters. 1 clear the buffer 2 draw the single letter 3 copy that chunk of back buffer to one of the frames in your Timage When you want to draw a letter you simply call drawimage with the correct subimage. |
| ||
Shouldn't VecChar be TImage[36], not Int[36]? Plus Byte goes up to 255 only, yet your for loop wants to go to 313. (I told you they were more trouble than they were worth ;) ) Even though N is set to 0 by default, it's good practice to "manually" set it to 0 (as opposed to leaving it blank) so that its use as a counting variable is clear. |
| ||
Hey guys, thanks for helping me: @ Ryan: Thanks, although I didnt do it that way because I couldn't draw the character there because they are drawn by functions. Instead I can draw all of the characters then parse through the screen and just dump each drawn character into their respective places. I fully intend on following the ascii order. In fact I will probably add a few more characters to the vecfont! BUT FIRST!!! I just want to make sure I even know how to save the images etc and thats where I'm Failing! image.frames[] doesnt exist either. I would do it your way but I can't iterate through the alphabet in a for next loop because the function to draw an A is "VecDrawLetter_A" and so on and so fourth, so that's just not possible the way it is set up. SO. I have to draw all the letters on the screen, then I can just do a for next loop that writes EACH letter at a time into an array and save the images inside. If I could code the drawing functions better I would, but I can't figure out how so this is what I'm working with (there is another thread about it where I'm asking for help, please let's just focus on saving images into an array here) That is what I'm doing here: Cls Local Sep:Float = S * 1 SetColor 255, 255, 255 DrawLetter_A 0, 0, S DrawLetter_B Sep, 0, S DrawLetter_C Sep * 2, 0, S DrawLetter_D Sep * 3, 0, S DrawLetter_E Sep * 4, 0, S DrawLetter_F Sep * 5, 0, S DrawLetter_G Sep * 6, 0, S DrawLetter_H Sep * 7, 0, S DrawLetter_I Sep * 8, 0, S DrawLetter_J Sep * 9, 0, S DrawLetter_K Sep * 10, 0, S DrawLetter_L Sep * 11, 0, S DrawLetter_M Sep * 12, 0, S DrawLetter_N Sep * 13, 0, S DrawLetter_O Sep * 14, 0, S DrawLetter_P Sep * 15, 0, S drawletter_Q Sep * 16, 0, S drawletter_R Sep * 17, 0, S DrawLetter_S Sep * 18, 0, S DrawLetter_T Sep * 19, 0, S DrawLetter_U Sep * 20, 0, S DrawLetter_V Sep * 21, 0, S DrawLetter_W Sep * 22, 0, S DrawLetter_X Sep * 23, 0, S DrawLetter_Y Sep * 24, 0, S DrawLetter_Z Sep * 25, 0, S DrawNumber_0 0, 20, S DrawNumber_1 Sep, 20, S DrawNumber_2 Sep * 2, 20, S DrawNumber_3 Sep * 3, 20, S DrawNumber_4 Sep * 4, 20, S DrawNumber_5 Sep * 5, 20, S DrawNumber_6 Sep * 6, 20, S DrawNumber_7 Sep * 7, 20, S DrawNumber_8 Sep * 8, 20, S DrawNumber_9 Sep * 9, 20, S Flip Global VecChar:TImage[36] Local N:Int = 0 For Local Grab_X:Int = 0 To 313 Step 13 VecChar[N] = CreateImage(Grab_X, 12, 1, DYNAMICIMAGE | MASKEDIMAGE) VecChar[N] = GrabImage VecChar[N], 0, 0 N:+1 Next The Grab_X jumps 13 steps to grab EACH letter. The N incriments by one so I can put it in each respective part of the array. HOWEVER, I'm getting syntax errors with the VecChar[N] = stuff and can't figure out how to fix them. |
| ||
You are Creating images wich get mor and more wider, but always grab from 0|0. Makes no sense. Try VecChar[n] = createimage(12,12,1,DYNAMICIMAGE | MASKEDIMAGE) Grabimage vecchar[n],grab_x,0 Your Syntax Error is a result of trying to assign the result of grabimage (which is an Integer containing True oder False) to a TImage. |
| ||
Your Syntax Error is a result of trying to assign the result of grabimage (which is an Integer containing True oder False) to a TImage. I tried grabimage vecchar[n] and got the same error. I do see the logical error I had (making wider and wider) and I thank you for pointing that one out but I'd get a runtime error if it went out of scope or I'd see the images looking wonky. Instead I'm getting a SYNTAX error. |
| ||
The immediate problem is you're calling GrabImage VecFont[N]. Which, as you've earlier called that array VecChar[N], VecFont is still undefined, and therefore an Integer. So what you're trying to do is call GrabImage, and put the result into an array of integers that has not even been defined as an array. You should at least use Strict mode - that'd avoid problems like this arising in future. Oh, as a side-note to this, in early versions of Blitzmax, you could load an image into an Int but it played merry hell with the garbage collector. I don't know if that behavious is still allowed but when loading images, always load them into a TImage. And *always* use Strict mode. :) |
| ||
Actually I use SuperStrict! Thanks for your help, I've got GrabImage working perfectly and am using it in my latest version of Shape Invaderz. :) |