LoadByteArray:Byte[]
BlitzMax Forums/BlitzMax Beginners Area/LoadByteArray:Byte[]
| ||
Hi, can someone please demonstrate how to use this. Array[100000] "data.dat" I'm currently using readbyte but it's a bit slow for the size of file. Thanks, Jim. |
| ||
LoadByteArray loads the contents of a file into a Byte array.Local data:Byte[] = LoadByteArray("data.dat") Print data.length ' should be equal to the size of the file. |
| ||
Thanks Brucey edit I'm getting some strange effects here. When I do it a byte at a time - works perfect. When loadbytearray the data seems to change every so often Is there a size limit? 170Mb? Jim |
| ||
Rather than load a byte at a time I've loaded an int and separated to bytes. Definitely not working as expected with the loadbytearray. Jim |
| ||
When loadbytearray the data seems to change every so often I've never had a problem with it. The source is in brl.mod/stream.mod/stream.bmx. As you can see, it's not doing anything strange - just reading in from the buffer into an array. |
| ||
That's useful to know, Brucey ! Question. Is there some single command to transfer all the pixels from either a Timage or TPixmap to a similar single byte array ? |
| ||
You don't need to copy a pixmap pixels to a byte array in order to modify them. TPixmap.pixels is a Byte Ptr. You can access the pixels directly using array-style access (with square brackets). Local pix:TPixmap = LoadPixmap("some_image.png") For local i:int = 0 until pix.Capacity pix.pixels[i] = 255 Next |
| ||
Yes, the pixels, I forgot about that. Okay, Brucey, I hope this is still the beginner's question. How can you tell how many bytes are used per pixel for a Pixmap or Timage ? This would make ".pixels" give the right values as I know they can change from 3 or 4. Other question, BONUS POINTS ! Is it possible to build and display a Pixmap or Timage that uses a 256-color palette where one-pixel represents one byte - and you can still use drawimage() or drawpixmap() to display it ? I suspect reading and writing pixels would be very fast w this method. |
| ||
How can you tell how many bytes are used per pixel for a Pixmap or Timage ? This would make ".pixels" give the right values as I know they can change from 3 or 4. Local pixmap:TPixmap = CreatePixmap(64,64,PF_RGB888) Print BytesPerPixel[pixmap.format] note: BytesPerPixel[] is an "internal" array. A BlitzMax update could potentially break it. Is it possible to build and display a Pixmap or Timage that uses a 256-color palette where one-pixel represents one byte - and you can still use drawimage() or drawpixmap() to display it ? Pixmaps can be created 1 byte per pixel, but it will act on a single color channel, not a pallet, so you get shades of grey, red, green, or blue. Any image loaded as a TImage will be converted to a format that works best with the GPU. Most likely PF_RGBA8888. |
| ||
You know ... brain spinning ... I think it would be possible to have a 256-color palette after all. I was just thinking of a way to do it, and to maintain the image array of pic=CreatePixmap(512,384,pf_i8) Let me finish this new Carryall function and I'll make that my next program after this. |
| ||
FWIW, I'm pretty sure that Blitzmax stores all images in 32-bit color in video RAM, regardless of what format the pixmap was before it was displayed. |