0

note uses .net3.5 framework. no i cannot use any class from System.Windows.Media

Overview

I've found the need to take 4 screenshots of content on my screen.

The content is spread across an area larger then my screen area which is 1618px wide and 696px high.

I automate the process of taking screenshots of the 4 areas then i encode the pixels i read from the screen to a byte array with .png data.

I then use System.IO.File.WriteAllBytes to output actual png images to a folder at "Path"

The problem

i do get all my png images output in an folder and i can successfully view all 4 images . However i need the images to be one large image.

i.e a 3236 x by 1392px image as shown here.

in the image you just saw four 1618px by and 696px squares labeled 1 to 4. this represent the screenshots and order in which they were taken.

Its this same exact order in which i wish the images to be combines and output as a single 3236 x by 1392px image.

in this class. lets assume that the byte data for image 1 ,2,3 and 4 are already assigned to their respective byte arrays.

class SimplePseudoExample
{
 private byte[] bytes1;
 private byte[] bytes2;
 private byte[] bytes3;
 private byte[] bytes4;

private byte FinalByes[];

void CreateTheSingleLargeImage()
{
 System.IO.File.WriteAllBytes("Path"+".png",FinalByes);
}

}

How can i get my single large image output ?

0

1 Answer 1

1

One way is to turn them into textures, then use getPixels and setPixels to do the merging.

 tex1 = new Texture2D(2, 2);
 ImageConversion.LoadImage(tex1, bytes1);
 tex2 = new Texture2D(2, 2);
 ImageConversion.LoadImage(tex2, bytes2);
 tex3 = new Texture2D(2, 2);
 ImageConversion.LoadImage(tex3, bytes3);
 tex4 = new Texture2D(2, 2);
 ImageConversion.LoadImage(tex4, bytes4);


 outTex = new Texture2D(tex1.width * 2, tex1.height * 2);

 // we could use tex1.width,tex1.height for everything but this is easier to read

 // setPixels bottom-left is 0,0
 // bottom-left
 outTex.setPixels(0,0,
                  tex3.width,tex3.height,
                  tex3.getPixels());
 // bottom-right
 outTex.setPixels(tex3.width,0,
                  tex4.width,tex4.height,
                  tex4.getPixels());
 // top-left
 outTex.setPixels(0,tex3.height,
                  tex1.width,tex1.height,
                  tex1.getPixels());
 // top-right
 outTex.setPixels(tex3.width, tex3.height,
                  tex2.width,tex2.height,
                  tex2.getPixels());

 byte[] outBytes = outTex.EncodeToPNG();
Sign up to request clarification or add additional context in comments.

1 Comment

this looks good. I'll test as soon as i cab turn on my overheated conputer.

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.