Not Yet Answered # how to store color image data in to 2d array

Discussion Starter sravs25 I am wondering if there would be any chance that someone could help me out with this, I am trying to teach myself c++ which i find it really interesting and I came accross this and would love to see how it works so i could do it and learn ...

0

```
//image.h
struct RGB
{
int Red;
int Green;
int Blue;
};
//image.cpp
int width,height;
RGB **data;
int bytesPerPixel = 8; //if RGB or 24 Bit image
int i,j;
int value=0;
Image::Image()
{
//constuctor declaration
}
Image::~Image()
{
// destructor declaration
}
char *ptr=(char*)(&data[0][0]);
//function to capture image
int Image::capture()
{
int i,j;
unsigned byte** array_2D=NULL;
std::cin>>height;
std::cin>>width;
array_2D = new unsigned byte*[height];
if(array_2D == NULL)
return 0; // return if memory not allocated
for(int j=0; j<height; j++)
{
array_2D[j] = new unsigned byte*[width];
if(array_2D[j] == NULL)
return 0; // return if memory not allocated
}
for(j=0; j<height; j++) // traverse height (or rows)
{
for(int i=0; i<width; i++) // traverse width (or columns)
{
array_2D[j][i] = value++;// update value at current (i, j)
}
value = 0;
}
}
```

here i want to read rgb values for the image in an array i am not getting that one. and u check the pointers in the program. thanq for replying.

This article has been dead for over six months. Start a new discussion instead.

Recommended Articles

Hi!

I have two tables, I will call them first-half and second-half (of the year)

```
Table: first
id jan feb mar apr
-----------------------
2 80 90 70 60
3 50 40 60 30
Table: second
id jan feb mar apr
-----------------------
2 50 70 60 90
3 80 60 50 ...
```

```
from turtle import *
import random
def allTriMedian (w=300):
speed (0)
vertices = []
point = turtle.Point(x,y)
for i in range (3):
x = random.randint(0,300)
y = random.randint(0,300)
vertices.append(trutle.Point(x,y))
point = turtle.Point(x,y)
triangle = turtle.Polygon(vertices)
a = triangle.side()
b = triangle.side()
c = triangle.side()
m1 = tirangle.median
m2 = triangle.median ...
```