# Pixel to String length

**URL:** <https://discourse.processing.org/t/pixel-to-string-length/12330>\
**Category:** Processing\
**Created:** [June 27, 2019, 9:08am UTC](https://discourse.processing.org/t/pixel-to-string-length/12330 "2019-06-27T09:08:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![The\_nish](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/the_nish/32/5634_2.png) [@The\_nish](https://discourse.processing.org/u/The_nish)\
**Post date:** [June 27, 2019, 9:08am UTC](https://discourse.processing.org/t/pixel-to-string-length/12330/1 "2019-06-27T09:08:57Z")

</div>

i am converting my image pixel as a string and print of its length then i get output is given in example image.  
what is wrong with it.

 ![p1](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/c/cb726dc90b122628804c6a383207fa90f630977c.png)

```auto

void function()
{
  for(int x=0; x<img.height;x++)
  {
       
    for(int y=0; y < img.width; y++)
    {
       int i = y+x*img.width;
        
         s = str(i);
     print(s.length());
          
 }          
   
  }
    
}

```

and please tell how to formatting it in 100\*100 digit. without using “\n” or “\r” ;

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [June 27, 2019, 9:45am UTC](https://discourse.processing.org/t/pixel-to-string-length/12330/2 "2019-06-27T09:45:36Z")

</div>

```auto
int i = y * img.width + x;

```

---

<div class="post-metadata">

**Author:** ![The\_nish](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/the_nish/32/5634_2.png) [@The\_nish](https://discourse.processing.org/u/The_nish)\
**Post date:** [June 27, 2019, 9:49am UTC](https://discourse.processing.org/t/pixel-to-string-length/12330/3 "2019-06-27T09:49:17Z")

</div>

problem is remain same.

---

<div class="post-metadata">

**Author:** ![InferNova](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/infernova/32/6009_2.png) [@InferNova](https://discourse.processing.org/u/InferNova)\
**Post date:** [June 27, 2019, 10:59am UTC](https://discourse.processing.org/t/pixel-to-string-length/12330/4 "2019-06-27T10:59:31Z")

</div>

Hey there !

It a bit unclear what the problem is. Could you give a more in-depth example ?

---

<div class="post-metadata">

**Author:** ![hotfooted](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hotfooted/32/3670_2.png) [@hotfooted](https://discourse.processing.org/u/hotfooted)\
**Post date:** [June 27, 2019, 11:25am UTC](https://discourse.processing.org/t/pixel-to-string-length/12330/5 "2019-06-27T11:25:50Z")

</div>

if you actually want to print the string lengths in a 100x100 grid  
in the console just build a string equivalent to a row of the image  
then output it with println instead of print. it probably won’t line  
up but you could pad the numbers (something [like](https://processing.org/reference/nf_.html)) you get to some length to give you  
an even print out

```auto
void function()
{
  String s;  
  for(int x = 0; x < img.height;x++)
  {
	s = "";//this is terrible should use something like a string builder or whatever processing has
	for(int y = 0; y < img.width; y++)
    {
       s += y + x * img.width;
	}
	println(s.length());
  }   
}

```
