# Help with block field editors - large image grid picker?

**URL:** https://forum.makecode.com/t/help-with-block-field-editors-large-image-grid-picker/1769
**Category:** micro:bit
**Created:** [April 22, 2020, 12:04am UTC](https://forum.makecode.com/t/help-with-block-field-editors-large-image-grid-picker/1769 "2020-04-22T00:04:12Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![mkilpatr](https://avatars.discourse-cdn.com/v4/letter/m/ccd318/32.png) [@mkilpatr](https://forum.makecode.com/u/mkilpatr)
#### Post date: [April 22, 2020, 12:04am UTC](https://forum.makecode.com/t/help-with-block-field-editors-large-image-grid-picker/1769/1 "2020-04-22T00:04:12Z")

</div>

Can anyone please help me work out how to define a function withinmy custom extension whic can replicate for me the LED image creator functionsuch as the images.createBigImage()? In Makecode blocks for the Microbit, this function appears as a grid of tick-boxes for the pixels in an image. This is twice the width of the standard 5x5 image as in images.createImag().

I want to reproduce this for a larger image or indeed for images of various sizes (for displaying on larger LED matrix displays) but I can’t work out the appropriate annotations and functions for the field editor. Has anyone got some in-depth knowledge here?

Michael

---

<div class="post-metadata">

### Author: ![peli](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/peli/32/12_2.png) [@peli](https://forum.makecode.com/u/peli)
#### Post date: [April 22, 2020, 12:25am UTC](https://forum.makecode.com/t/help-with-block-field-editors-large-image-grid-picker/1769/2 "2020-04-22T00:25:37Z")

</div>

This is only supported in beta ([https://makecode.microbit.com/beta](https://makecode.microbit.com/beta)). Use `imageLiteralColumns` and `imageLiteralRows`.

For legacy reasons, the parameter should be a string; but it is really an Image runtime object.

```auto
    /**
     * TODO: describe your function here
     */
    //% block="foo"
    //% imageLiteral=1
    //% imageLiteralColumns=12
    //% imageLiteralRows=3
    export function foo(i: string): void {
        // this is not pretty but basically, i is an Image
        let im = <Image><any>i;
        im.showImage(0)
    }

```

Open this in beta: [https://makecode.microbit.org/beta#pub:\_Fm582taEK8Ww](https://makecode.microbit.org/beta#pub:_Fm582taEK8Ww)

---

<div class="post-metadata">

### Author: ![mkilpatr](https://avatars.discourse-cdn.com/v4/letter/m/ccd318/32.png) [@mkilpatr](https://forum.makecode.com/u/mkilpatr)
#### Post date: [April 22, 2020, 10:08am UTC](https://forum.makecode.com/t/help-with-block-field-editors-large-image-grid-picker/1769/3 "2020-04-22T10:08:48Z")

</div>

Thank you for helping but unfortunately that doesn’t seem to achieve what I want. The MakeCode block for “foo” appears to be constrained only to a multiple of a standard image, in other words always 5 rows and any multiple of 5 columns depending on the value of “imageLiterals” but irrespective of the “imageLiteralRows” or columns.

What I want to do is to work out how the image editor works in Blocks and create one that lets me input an image of say 17,7 pixels- for use with a particular LED matrix display that is can be attached to a Microbit - and returned as an image/string which can be assigned to a variable and then at some point delivered to an LED matrix display.

I tried looking through lots of the core code for the Microbit platform but couldn’t work out where the definition was for the block (the “grid picker” type element) was defined such that I could alter it for a custom size.

---

<div class="post-metadata">

### Author: ![peli](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/peli/32/12_2.png) [@peli](https://forum.makecode.com/u/peli)
#### Post date: [April 22, 2020, 2:16pm UTC](https://forum.makecode.com/t/help-with-block-field-editors-large-image-grid-picker/1769/4 "2020-04-22T14:16:42Z")

</div>

Do you need colors as well?

---

<div class="post-metadata">

### Author: ![mkilpatr](https://avatars.discourse-cdn.com/v4/letter/m/ccd318/32.png) [@mkilpatr](https://forum.makecode.com/u/mkilpatr)
#### Post date: [April 22, 2020, 3:04pm UTC](https://forum.makecode.com/t/help-with-block-field-editors-large-image-grid-picker/1769/5 "2020-04-22T15:04:52Z")

</div>

No, I just need something dead simple. On/Off for an array of 17x7 pixels. It would be nice to have a Block for it so I want an editor which is like the standard image.createImage() editor. But possibly a smaller rendition as 17x7 would take up a lot of space in the Makecode editor screen.

However, in relation to the extension for the Scroll:bit I’m using, there’s also the possibility that a simple monochrome pixel editor for a larger array would be useful to apply to the larger windowing system I’m trying to make for it. In which it would be of any size the user requested.

In the other thread you mentioned the Arcade pixel editor? I haven’t looked at any of that yet but I can see a whole forum category for it. Is there an editor I could adapt and simplify?

---

<div class="post-metadata">

### Author: ![peli](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/peli/32/12_2.png) [@peli](https://forum.makecode.com/u/peli)
#### Post date: [April 22, 2020, 4:41pm UTC](https://forum.makecode.com/t/help-with-block-field-editors-large-image-grid-picker/1769/6 "2020-04-22T16:41:53Z")

</div>

Indeed row is ignored, i’ll look into that.

---

<div class="post-metadata">

### Author: ![peli](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/peli/32/12_2.png) [@peli](https://forum.makecode.com/u/peli)
#### Post date: [April 22, 2020, 4:57pm UTC](https://forum.makecode.com/t/help-with-block-field-editors-large-image-grid-picker/1769/7 "2020-04-22T16:57:07Z")

</div>

Demo that does not work yet:

> **[Microsoft MakeCode for micro:bit](https://makecode.microbit.org/beta#pub:_Fm582taEK8Ww)**
>
> A Blocks / JavaScript code editor for the micro:bit powered by Microsoft MakeCode.

---

<div class="post-metadata">

### Author: ![mkilpatr](https://avatars.discourse-cdn.com/v4/letter/m/ccd318/32.png) [@mkilpatr](https://forum.makecode.com/u/mkilpatr)
#### Post date: [April 22, 2020, 5:35pm UTC](https://forum.makecode.com/t/help-with-block-field-editors-large-image-grid-picker/1769/8 "2020-04-22T17:35:26Z")

</div>

Ah, thanks.But that does work if you do the following:

//% block=“make image”  
//% blockId=myscrollbit\_make\_image  
//% imageLiteral=1  
//% imageLiteralColumns=17  
//% imageLiteralRows=7  
export function makeImage(i: string): Image {  
// this is not pretty but basically, i is an Image  
let im = i;  
console.logValue(“width”, im.width())  
console.logValue(“height”, im.height())  
im.scrollImage(1, 200)  
return im  
}

although I’d really like to know how to rebuild this in a different design and make the pixels more compact in the editor.

---

<div class="post-metadata">

### Author: ![mkilpatr](https://avatars.discourse-cdn.com/v4/letter/m/ccd318/32.png) [@mkilpatr](https://forum.makecode.com/u/mkilpatr)
#### Post date: [April 22, 2020, 5:37pm UTC](https://forum.makecode.com/t/help-with-block-field-editors-large-image-grid-picker/1769/9 "2020-04-22T17:37:16Z")

</div>

However, it works only in the beta makecode editor. Any idea why?

---

<div class="post-metadata">

### Author: ![peli](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/peli/32/12_2.png) [@peli](https://forum.makecode.com/u/peli)
#### Post date: [April 22, 2020, 6:58pm UTC](https://forum.makecode.com/t/help-with-block-field-editors-large-image-grid-picker/1769/10 "2020-04-22T18:58:20Z")

</div>

This PR needs to go in. [https://github.com/microsoft/pxt-microbit/pull/2879](https://github.com/microsoft/pxt-microbit/pull/2879)

Also you need to set the shim on this function:

```
//% shim=images::createImage
```

---

<div class="post-metadata">

### Author: ![peli](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/peli/32/12_2.png) [@peli](https://forum.makecode.com/u/peli)
#### Post date: [April 22, 2020, 6:58pm UTC](https://forum.makecode.com/t/help-with-block-field-editors-large-image-grid-picker/1769/11 "2020-04-22T18:58:50Z")

</div>

Tested on browser/hw:

> **[Microsoft MakeCode for micro:bit](https://makecode.microbit.org/beta#pub:_eKePUaCzcHsz)**
>
> A Blocks / JavaScript code editor for the micro:bit powered by Microsoft MakeCode.

---

<div class="post-metadata">

### Author: ![mkilpatr](https://avatars.discourse-cdn.com/v4/letter/m/ccd318/32.png) [@mkilpatr](https://forum.makecode.com/u/mkilpatr)
#### Post date: [April 22, 2020, 7:32pm UTC](https://forum.makecode.com/t/help-with-block-field-editors-large-image-grid-picker/1769/12 "2020-04-22T19:32:44Z")

</div>

Ah, thank you very much. I have got the code successfully creating an image into a variable and then displaying it on the 17x7 display, so that’s brilliant.

I don’t quite understand all the ins and outs of shims yet. Here it maps the function “foo” to the creatImage() C++ function, yes? Why is im declared as a const here?

I see you’ve requested a pull on this and I’m looking at your comments. I’m pretty new to github so I’m still learning how everything fits together. Maybe following a trail from the code referred to in your PR will help me understand how the createImage() pixel editor is constructed. I’d happily copy the entire construction and play with it to see if I can edit its appearance for using with larger images if I can find all of the relevant code.

I also had a look at the sprite editor for Arcade. Very impressive and useful. However, there’s no way I can work out how to extract the editor from the rest of Arcade and make a dead simple monochrome version of it to create a pixel image of any give size. It would be handy, though.

---

<div class="post-metadata">

### Author: ![peli](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/peli/32/12_2.png) [@peli](https://forum.makecode.com/u/peli)
#### Post date: [April 22, 2020, 8:08pm UTC](https://forum.makecode.com/t/help-with-block-field-editors-large-image-grid-picker/1769/13 "2020-04-22T20:08:05Z")

</div>

The fix is now in the latest beta (v2.3.21 and up).

> Here it maps the function “foo” to the creatImage() C++ function, yes?

The “shim” notation is telling our linker to use the C++ imagers::createImage function for C++ instead of the TypeScript. Docs at [https://makecode.com/simshim](https://makecode.com/simshim)

> Why is im declared as a const here?

That’s just a typescript habit. It makes the variable reference readonly – eg you cannot assign into that variable again. It could have been `let`. as well.

The “image” feature in micro:bit is kind of a legacy feature - which explains why it’s using a string and not a string literal like in Arcade.

---

<div class="post-metadata">

### Author: ![peli](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/peli/32/12_2.png) [@peli](https://forum.makecode.com/u/peli)
#### Post date: [April 22, 2020, 8:08pm UTC](https://forum.makecode.com/t/help-with-block-field-editors-large-image-grid-picker/1769/14 "2020-04-22T20:08:31Z")

</div>

If you’re working on an extension, feel free to post it here on the forums so that we can give you feedback.

---

<div class="post-metadata">

### Author: ![mkilpatr](https://avatars.discourse-cdn.com/v4/letter/m/ccd318/32.png) [@mkilpatr](https://forum.makecode.com/u/mkilpatr)
#### Post date: [April 22, 2020, 8:22pm UTC](https://forum.makecode.com/t/help-with-block-field-editors-large-image-grid-picker/1769/15 "2020-04-22T20:22:42Z")

</div>

I certainly will do. In what form can it be posted on the forum?

Err, but if the Microbit pxt has just been updated after your PR, does that explain why my function below suddenly shows an error in the MakeCode editor? It is complaining about the if (im.pixel(x,y)==1) statement! it worked an hour or so ago. I’ve just changed it to if (im.pixel(x,y)) as a boolean, and now it works.

```
export function displayImage(im: Image): void {
        for(let y = 0; y < im.height(); ++y) {
            for(let x = 0; x < im.width(); ++x) {
                if (im.pixel(x, y) == 1) {
                    setPixel(x,y)
                }
            }
        }
    }
```

---

<div class="post-metadata">

### Author: ![peli](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/peli/32/12_2.png) [@peli](https://forum.makecode.com/u/peli)
#### Post date: [April 22, 2020, 8:36pm UTC](https://forum.makecode.com/t/help-with-block-field-editors-large-image-grid-picker/1769/16 "2020-04-22T20:36:35Z")

</div>

Let me investigate what changed…

---

<div class="post-metadata">

### Author: ![peli](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/peli/32/12_2.png) [@peli](https://forum.makecode.com/u/peli)
#### Post date: [April 22, 2020, 8:41pm UTC](https://forum.makecode.com/t/help-with-block-field-editors-large-image-grid-picker/1769/17 "2020-04-22T20:41:15Z")

</div>

Looks like pixel was always returning a boolean; not sure why it worked for you previously.

---

<div class="post-metadata">

### Author: ![peli](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/peli/32/12_2.png) [@peli](https://forum.makecode.com/u/peli)
#### Post date: [April 22, 2020, 8:41pm UTC](https://forum.makecode.com/t/help-with-block-field-editors-large-image-grid-picker/1769/18 "2020-04-22T20:41:36Z")

</div>

> [@mkilpatr](#):
>
> I certainly will do. In what form can it be posted on the forum?

A new thread for that extension for do it.

---

<div class="post-metadata">

### Author: ![mkilpatr](https://avatars.discourse-cdn.com/v4/letter/m/ccd318/32.png) [@mkilpatr](https://forum.makecode.com/u/mkilpatr)
#### Post date: [April 22, 2020, 8:53pm UTC](https://forum.makecode.com/t/help-with-block-field-editors-large-image-grid-picker/1769/19 "2020-04-22T20:53:00Z")

</div>

Hey! You appear to have done something that causes a crash when this is called:

`basic.showIcon(Icon.Sad)`

Oops!

---

<div class="post-metadata">

### Author: ![mkilpatr](https://avatars.discourse-cdn.com/v4/letter/m/ccd318/32.png) [@mkilpatr](https://forum.makecode.com/u/mkilpatr)
#### Post date: [April 22, 2020, 8:53pm UTC](https://forum.makecode.com/t/help-with-block-field-editors-large-image-grid-picker/1769/20 "2020-04-22T20:53:15Z")

</div>

Oh, or maybe not. It’s broken if I use the stable version not the beta. I think I’ve got a memory leak somewhere. I must be abusing a buffer somewhere in my code (it’s a worm chasing game on the scrollbit and it worked a few hours ago).

[Next page](https://forum.makecode.com/t/help-with-block-field-editors-large-image-grid-picker/1769.md?page=2)
