繁体   English   中英

从WCF Web服务中的对象数组创建图像数组

[英]Create array of images from array of objects in WCF web service

我有这样的2D椅子阵列: chairs[][]这也是我的椅子类:

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

每个类别的对象都代表剧院中的一个座位(状态表示座位状态; 0表示空位,1表示保留,编号表示座位号)。

假设我具有以下值:

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

我想创建这样的图像数组:

在此处输入图片说明

最后将其转换为字节数组,并将其作为Web服务输出返回。 长话短说,我想将chair[][]数组转换为图像。 我的Web服务输入将为chairs[][]而输出将为byte[]

这可能吗?

更新

在这里,我在Windows桌面应用程序中创建了一些东西。 我只需要在wcf中创建它即可。 我现在已经知道如何在wcf中创建PictureboxLabal !!!

{
    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;
    }

首先-https: //msdn.microsoft.com/zh-cn/library/vstudio/ms734712(v=vs.100).aspx

然后

// 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 
    }
}
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 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM