hubert
Junior Member
Posts: 10
|
Post by hubert on Oct 2, 2015 5:22:13 GMT -8
Hello people, I want to use some (480x272) JPG files on my SD card as backgrounds for a GUI. I found on another Thread that it should work with the BitmapHandle(). My problem is that when I load the first Screen (second is bypassed with // ) the screen is offset (like on the picture) and if I do this with the second pic, the screen stays white! How could this happen? Please help me... Here is the code: #include <EEPROM.h> #include <SPI.h> #include <GD2.h>
void setup() { GD.begin();
// load image 1 GD.BitmapHandle(0); GD.cmd_loadimage(0, 0); GD.load("home1.jpg"); // load image 2 GD.BitmapHandle(1); GD.cmd_loadimage(-1, 0); GD.load("settings.jpg"); } void loop() { GD.Clear(); GD.Begin(BITMAPS);
GD.Vertex2ii(0, 0, 0); //image 1 //GD.Vertex2ii(0, 0, 1); //image 2
GD.swap(); }
Attachments:
|
|
|
Post by jamesbowman on Oct 2, 2015 6:26:08 GMT -8
From the sound of it the first image is taking almost all of memory, and the second image is overflowing.
GD2 video memory is 262144 bytes, and a 480x272 16-bit image is 261120 bytes. This leaves just 1024 bytes spare.
A quick way to check is to give the load commands the monochrome option. This means that they load with 1-byte per pixel:
GD.cmd_loadimage(0, OPT_MONO); obviously this will mean no color, but you should see the bitmaps you expect.
|
|
hubert
Junior Member
Posts: 10
|
Post by hubert on Oct 2, 2015 9:03:33 GMT -8
Thank you, it works with mono.
What can I do to build my GUI? Do you have an advise for me?
Thank you very much
|
|
|
Post by jamesbowman on Oct 2, 2015 12:31:11 GMT -8
Hmm, easy way is to use a smaller JPG for the background.
If you make a half resolution JPG (240x136) called "home1-s.jpg" then the code to draw it is:
#include <EEPROM.h> #include <SPI.h> #include <GD2.h>
void setup() { GD.begin();
// load image 1 GD.BitmapHandle(0); GD.cmd_loadimage(0, 0); GD.load("home1-s.jpg"); // 240x136 version GD.BitmapSize(BILINEAR, BORDER, BORDER, 480, 272); // fill the screen // load image 2 GD.BitmapHandle(1); GD.cmd_loadimage(-1, 0); GD.load("settings.jpg"); } void loop() { GD.Clear(); GD.Begin(BITMAPS);
GD.cmd_scale(F16(2),F16(2)); // image 1 double size GD.cmd_setmatrix(); GD.Vertex2ii(0, 0, 0); GD.cmd_loadidentity(); GD.cmd_setmatrix();
GD.Vertex2ii(0, 0, 1); // image 2 normal size
GD.swap(); }
|
|
hubert
Junior Member
Posts: 10
|
Post by hubert on Oct 2, 2015 22:14:00 GMT -8
Hello,
Great, thank you! I will try it now with the half size and in the worst case when I run out of memory, I use 40x40px widgets and align it seperatly on the screen.
Thank you very much for your help!!! :-)
|
|
hubert
Junior Member
Posts: 10
|
Post by hubert on Oct 4, 2015 4:33:25 GMT -8
Hello again. As reported in my last answer, I tried it now with 40x40 and 60x40px pictures and I aligned it. But when I load it in the void setup(), it stays black. I can only load maximum 4 pics. When I load a 5th one, the screen goes black! Why does that happen? Please help me.
#include <EEPROM.h> #include <SPI.h> #include <GD2.h>
void setup() { GD.begin();
// load images GD.BitmapHandle(0); GD.cmd_loadimage(0, OPT_MONO); GD.load("oneblack.jpg");
GD.BitmapHandle(1); GD.cmd_loadimage(-1, 0); GD.load("onered.jpg");
GD.BitmapHandle(2); GD.cmd_loadimage(-2, OPT_MONO); GD.load("twoblack.jpg");
GD.BitmapHandle(3); GD.cmd_loadimage(-3, 0); GD.load("twored.jpg");
GD.BitmapHandle(4); GD.cmd_loadimage(-4, OPT_MONO); GD.load("threeblack.jpg");
GD.BitmapHandle(5); GD.cmd_loadimage(-5, 0); GD.load("threered.jpg");
GD.BitmapHandle(6); GD.cmd_loadimage(-6, OPT_MONO); GD.load("moneyblack.jpg");
GD.BitmapHandle(7); GD.cmd_loadimage(-7, 0); GD.load("moneyred.jpg");
GD.BitmapHandle(8); GD.cmd_loadimage(-8, OPT_MONO); GD.load("settingsblack.jpg");
GD.BitmapHandle(9); GD.cmd_loadimage(-9, 0); GD.load("settingsred.jpg"); } void loop() { GD.Clear(); GD.Begin(BITMAPS);
GD.Vertex2ii(7, 5, 0); GD.Vertex2ii(7, 60, 1); GD.Vertex2ii(7, 115, 2); GD.Vertex2ii(7, 170, 3); GD.Vertex2ii(7, 200, 4);
GD.swap(); }
|
|
|
Post by jamesbowman on Oct 4, 2015 6:47:17 GMT -8
The address needs to be -1, which tells the FT800 to append the image. Other negative numbers don't do anything. So for each loadimage, do:
GD.cmd_loadimage(-1, 0);
|
|
hubert
Junior Member
Posts: 10
|
Post by hubert on Oct 4, 2015 7:12:54 GMT -8
Hello, Ok thank you, I changed everything, but it has still the same problem... Do you maybe know how I can get it running?
Thats my code right now:
#include <EEPROM.h> #include <SPI.h> #include <GD2.h>
void setup() { GD.begin(); // load images GD.BitmapHandle(0); GD.cmd_loadimage(0, OPT_MONO); GD.load("oneblack.jpg");
GD.BitmapHandle(1); GD.cmd_loadimage(-1, 0); GD.load("onered.jpg");
GD.BitmapHandle(2); GD.cmd_loadimage(-1, OPT_MONO); GD.load("twoblack.jpg");
GD.BitmapHandle(3); GD.cmd_loadimage(-1, 0); GD.load("twored.jpg");
GD.BitmapHandle(4); GD.cmd_loadimage(-1, OPT_MONO); GD.load("threeblack.jpg");
GD.BitmapHandle(5); GD.cmd_loadimage(-1, 0); GD.load("threered.jpg");
GD.BitmapHandle(6); GD.cmd_loadimage(-1, OPT_MONO); GD.load("moneyblack.jpg");
GD.BitmapHandle(7); GD.cmd_loadimage(-1, 0); GD.load("moneyred.jpg");
GD.BitmapHandle(8); GD.cmd_loadimage(-1, OPT_MONO); GD.load("settingsblack.jpg");
GD.BitmapHandle(9); GD.cmd_loadimage(-1, 0); GD.load("settingsred.jpg"); } void loop() { settings(); }
void settings() { GD.Clear(); GD.Begin(BITMAPS);
GD.Vertex2ii(7, 5, 0); GD.Vertex2ii(7, 60, 1); GD.Vertex2ii(7, 115, 2); GD.Vertex2ii(7, 170, 3); GD.Vertex2ii(7, 200, 4);
GD.swap(); }
|
|
|
Post by jamesbowman on Oct 4, 2015 9:01:15 GMT -8
That looks like it should work. Please can you upload your .jpg images so I can try it?
|
|
hubert
Junior Member
Posts: 10
|
Post by hubert on Oct 4, 2015 21:27:25 GMT -8
Hello, sure here are the pics. Attachments:pictures.zip (21.66 KB)
|
|
|
Post by tftlcdcyg on Nov 17, 2015 0:17:44 GMT -8
Flying bills! #include <SPI.h> #include <GD2.h>
#include "money.h"
void setup() { GD.begin(); LOAD_ASSETS(); GD.wr(REG_GPIO, 0x82); GD.wr(REG_PWM_DUTY, 95); //0-128 backlight
// Load the JPG into handle 11, *above* the assets in memory GD.BitmapHandle(11); GD.cmd_loadimage(ASSETS_END, 0); GD.load("sunrise.jpg"); }
void loop() { GD.Clear(); GD.Begin(BITMAPS); GD.Vertex2ii(0, 0, 11); GD.ColorA(140); int x, y;
for (int i = 0; i < 10; i++) { x = random(0,432); y = random(0,224); GD.Vertex2ii(x, y, i); }
delay(100); GD.swap(); } Attachments:money.rar (22.84 KB)
|
|
|
Post by tftlcdcyg on Nov 17, 2015 0:42:39 GMT -8
Try with short jpg-names, under 8 characters #include <SPI.h> #include <GD2.h>
void setup() { GD.begin(); // load images GD.BitmapHandle(0); GD.cmd_loadimage(0, 0); GD.load("oneblack.jpg");
GD.BitmapHandle(1); GD.cmd_loadimage(-1, 0); GD.load("onered.jpg");
GD.BitmapHandle(2); GD.cmd_loadimage(-1, 0); GD.load("moneyred.jpg");
GD.BitmapHandle(3); GD.cmd_loadimage(-1, 0); GD.load("moneyb~1.jpg");
GD.BitmapHandle(4); GD.cmd_loadimage(-1, 0); GD.load("setred.jpg");
GD.BitmapHandle(5); GD.cmd_loadimage(-1, 0); GD.load("setblack.jpg");
GD.BitmapHandle(6); GD.cmd_loadimage(-1, 0); GD.load("threered.jpg");
GD.BitmapHandle(7); GD.cmd_loadimage(-1, 0); GD.load("threeb~1.jpg");
GD.BitmapHandle(8); GD.cmd_loadimage(-1, 0); GD.load("twoblack.jpg");
GD.BitmapHandle(9); GD.cmd_loadimage(-1, 0); GD.load("twored.jpg"); }
void loop() { GD.Clear(); GD.Begin(BITMAPS);
GD.Vertex2ii(7, 5, 0); GD.Vertex2ii(7, 60, 1); GD.Vertex2ii(107, 5, 2); GD.Vertex2ii(107, 60, 3); GD.Vertex2ii(207, 5, 4); GD.Vertex2ii(207, 60, 5); GD.Vertex2ii(307, 5, 6); GD.Vertex2ii(307, 60, 7); GD.Vertex2ii(407, 5, 8); GD.Vertex2ii(407, 60, 9);
GD.swap(); }
|
|