Link to home
Start Free TrialLog in
Avatar of zimmer9
zimmer9Flag for United States of America

asked on

Using C# with VS2015 do you know how I can reconfigure the 2 images that appear horizontally to make them instead appear vertical and enlarge the images to the max?

I am developing a C# application and I create 2 check images as follows:

Currently using the code below, the images appear horizontally and are small.

Do you know how I could make them appear vertically (have the 1st image appear on the top half of the screen and the 2nd image appear on the bottom half
of the screen) and have them both take up the full half of the screen (enlarge the images)?

I have attached an example of the 2 check images that are displayed on the screen so that you can see their size and placement on the screen.

MemoryStream ms = new MemoryStream(bytesFrImg, 0, bytesFrImg.Length);
ms.Write(bytesFrImg, 0, bytesFrImg.Length);
System.Drawing.Image image = System.Drawing.Image.FromStream(ms, true);
                                                   
MemoryStream ms1 = new MemoryStream(bytesBkImg, 0, bytesBkImg.Length);
ms1.Write(bytesBkImg, 0, bytesBkImg.Length);
System.Drawing.Image image1 = System.Drawing.Image.FromStream(ms1, true);

int width = image.Width + image1.Width;
int height = Math.Max(image.Height, image1.Height);

Bitmap img3 = new Bitmap(width, height);
Graphics g = Graphics.FromImage(img3);

g.Clear(Color.Black);
g.DrawImage(image, new Point(0, 0));
g.DrawImage(image1, new Point(image.Width, 0));

g.Dispose();
image.Dispose();
image1.Dispose();

img3.Save("L:\\FINSYS\\FSMain\\C\\S\\B1.tiff", System.Drawing.Imaging.ImageFormat.Tiff);
img3.Dispose();
checkimageoutput.jpg
ASKER CERTIFIED SOLUTION
Avatar of Daniel Van Der Werken
Daniel Van Der Werken
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of zimmer9

ASKER

Using this revised code, the good news is that the 2 check images are vertical.
The bad news is that the front check image is taking up about 1/4 of the top of the screen and the back check image is taking up about 1/4 of the bottom half of the screen, which makes their contents hard to read. I have attached a display of the size and position of the 2 check images on the screen.


                                                    MemoryStream ms = new MemoryStream(bytesFrImg, 0, bytesFrImg.Length);
                                                    ms.Write(bytesFrImg, 0, bytesFrImg.Length);
                                                    System.Drawing.Image image = System.Drawing.Image.FromStream(ms, true);
                                                   
                                                    MemoryStream ms1 = new MemoryStream(bytesBkImg, 0, bytesBkImg.Length);
                                                    ms1.Write(bytesBkImg, 0, bytesBkImg.Length);
                                                    System.Drawing.Image image1 = System.Drawing.Image.FromStream(ms1, true);
                                               
                                                    string combinedTif = @"L:\\FINSYS\\FSMain\\C\\Source\\B1.tiff";
                                                    Bitmap combinedBitmap = new Bitmap(Math.Max(image.Width, image1.Width), image.Height + image1.Height);
                                           
                                                        using (Graphics combinedGraphics = Graphics.FromImage(combinedBitmap))
                                                        {
                                                            combinedGraphics.Clear(Color.Black);
                                                            combinedGraphics.DrawImage(image, new Point(0, 0));
                                                            combinedGraphics.DrawImage(image1, new PointF(0, image.Height));

                                                            if (File.Exists(combinedTif))
                                                            {
                                                                File.Delete(combinedTif);
                                                            }

                                                            combinedBitmap.Save(combinedTif);
                                                        }
B.tiff
My guess is that your images are originally wonky. I am posting the tif I created with my code. As you can see, I don't have that problem. Test your code with another set of images like the ones I used. I will include them.

These aren't even the same check or same size, but you can see it did okay.
CombinedTif.tif
Al_Barlick_Autographed_Cancelled_Che.jpg
Subcheck_BACK_shadow.gif
Avatar of zimmer9

ASKER

using (Graphics combinedGraphics = Graphics.FromImage(combinedBitmap))
                                                        {
                                                            combinedGraphics.Clear(Color.Black);
                                                            combinedGraphics.DrawImage(image, 0, 0, image.Width, image.Height);
                                                            combinedGraphics.DrawImage(image1, 0, image.Height, image1.Width, image1.Height);

                                                            if (File.Exists(combinedTif))
                                                            {
                                                                File.Delete(combinedTif);
                                                            }

                                                            combinedBitmap.Save(combinedTif);
                                                        }