1

I have a 2D array of chairs like this: chairs[][] also here is my chair class:

public class Chair
{
    public int State;
    public int number;
}

Each object of class represent a seat in a theater (state indicates the seat status; 0 means empty, 1 means reserved and number indicates the seat number).

Let's assume that I have these values:

    0   0   0   1
    1   1   1   0
    0   1   0   1

I want to create array of images like this:

enter image description here

and finally convert it to array of bytes and return it as web service output. long story short i want to convert array of chair[][] to the images. my web service input will be chairs[][] and output will be byte[].

Is this possible?

UPDATE:

here i created something in windows desktop application. i just need create it in wcf. i have now idea how can create Picturebox or Labal in wcf!!!

{
    AutoScroll = true;
    int x = 10, y = 10;

    Chair[][] chairs = new Chair[3][];
    chairs[0] = new Chair[4] { new Chair { number = 1, State = 0 }, new Chair { number = 2, State = 0 }, new Chair { number = 3, State = 0 }, new Chair { number = 4, State = 1 } };
    chairs[1] = new Chair[4] { new Chair { number = 5, State = 1 }, new Chair { number = 6, State = 1 }, new Chair { number = 7, State = 1 }, new Chair { number = 8, State = 0 } };
    chairs[2] = new Chair[4] { new Chair { number = 9, State = 0 }, new Chair { number = 10, State = 1 }, new Chair { number = 11, State = 0 }, new Chair { number = 12, State = 1 } };

    Label[][] label = new Label[chairs.Length][];
    PictureBox[][] picturebox = new PictureBox[chairs.Length][];

    for (int i = 0; i < chairs.Length; i++)
    {
        label[i] = new Label[chairs[i].Length];
        picturebox[i] = new PictureBox[chairs[i].Length];


        for (int j = 0; j < chairs[i].Length; j++)
        {
            label[i][j] = new Label();
            picturebox[i][j] = new PictureBox();

            Controls.Add(label[i][j]);
            Controls.Add(picturebox[i][j]);

            label[i][j].Location = new Point(x, y + 50);
            picturebox[i][j].Location = new Point(x, y);

            label[i][j].Size = new Size(100, 20);
            picturebox[i][j].Size = new Size(50, 50);

            label[i][j].Text = i + "*" + j + "(" + chairs[i][j].number + ")";
            if (chairs[i][j].State == 0) picturebox[i][j].Image = Image.FromFile(@"C:\Users\Admin\Desktop\1\1.png");
            else picturebox[i][j].Image = Image.FromFile(@"C:\Users\Admin\Desktop\1\2.png");

            x = x + 100;
        }
        x = 10;
        y = y + 100;
    }
6
  • 1
    Is it ok for you if chairs are serialized over the network, being passed to a web service or returned from a web service ? Commented Nov 3, 2015 at 13:05
  • dear @Emmanuel honestly i didn't get it what you asking. but long story short i want convert array of class to the images. my web service input is chairs[][] and output is byte[]. i hope i could explain it. Commented Nov 3, 2015 at 13:13
  • 1
    You can edit and remove the sentence about silly questions (they don't exist). But it 's important that we understand ! What do you expect to be in the byte [] ? ... Some png picture ... ? Commented Nov 3, 2015 at 13:21
  • done :). let me put it this way: i have a string of 0101... and i want to create array of images from 01 string. if string[i]=0 replace it with image1.png else replace it with image2.png. Ive also done it in a windows form application. so sorry. I'm doing my best to explain it but its really hard to explain. Commented Nov 3, 2015 at 13:26
  • 1
    if I understand well you want to receive the image in PNG format as a byte[] - a single image for all the theater, right ? Commented Nov 3, 2015 at 13:35

2 Answers 2

1
string firstText = "Hello";
string secondText = "World";

PointF firstLocation = new PointF(10f, 10f);
PointF secondLocation = new PointF(10f, 50f);

string imageFilePath = @"path\picture.bmp"
Bitmap bitmap = (Bitmap)Image.FromFile(imageFilePath);//load the image file

using(Graphics graphics = Graphics.FromImage(bitmap))
{
   using (Font arialFont =  new Font("Arial", 10))
   {
       graphics.DrawString(firstText, arialFont,Brushes.Blue,firstLocation);
       graphics.DrawString(secondText,arialFont,Brushes.Red,secondLocation);
    }
}

bitmap.Save(imageFilePath);//save the image 
Sign up to request clarification or add additional context in comments.

3 Comments

Try this, u can create 2 templates - with "R" end empty Chair, leave the place for numbers empty and try this code
thank you. its sort of my answer. but how can put array of this images in one image? like my image in my question?
u can just create a big empty image/bitmap with height = sum of heigths of your array images in one column(for e.g. 3 rows in column with each image height = 200 pixels, so big image height = 3*200 = 600 and do the same with width) then just use Graphics class to draw each of yours images on this bitmap
1

First - https://msdn.microsoft.com/en-us/library/vstudio/ms734712(v=vs.100).aspx

then

// Service side
[ServiceContract(Name = "chairs-image-generator")]
public interface IChairsImageArrayGenerator
{
    // insted byte[] paste desirable type of image
    [OperationContract(Name = "generate-images")]
    IEnumerable<byte[]> GenerateImage(IEnumerable<byte[][]> chairs);
}

// Client side
[ServiceContract(Name = "chairs-image-generator")]
public interface IChairsImageArrayGeneratorClient
{
    [OperationContract(Name = "generate-images")]
    IEnumerable<byte[]> GenerateImages(IEnumerable<byte[][]> chairs);
}

public class ChairsImageGenerator : IChairsImageArrayGenerator
{
    public IEnumerable<byte[]> GenerateImages(IEnumerable<byte[][]> chairs)
    {
        // put here your realization 
    }
}

3 Comments

thank you dear @android_dev_123. but its not what i want!! i guess i clearly explained what exactly i want.
tell me more exactly what troubles u have - 1) creating a WCF service 2) creating an image from Chair class? or with smth else?
thank you so much, creating an image from Chair class is my concern.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.