473,507 Members | 2,447 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with Bitmaps and Graphics

4 New Member
I'm new to C#, so please forgive the ~407,000 coding sins I'm probably making.
The purpose of this function is to take a bitmap and return a bitmap of double the height, with two of the images stacked on top of each other.



Expand|Select|Wrap|Line Numbers
  1. private Bitmap ProcessBitmap(Bitmap sourceBitmap)
  2.         {
  3.  
  4.  
  5.             int w = sourceBitmap.Width;
  6.             int h = sourceBitmap.Height;
  7.             int targetHeight = (h*2);
  8.  
  9.  
  10.  
  11.             Bitmap targetBitmap = new Bitmap(w, targetHeight);
  12.  
  13.             Rectangle sourceRect = new Rectangle(0, 0, w, h);
  14.  
  15.             Graphics sourceGraphics; 
  16.             sourceGraphics = Graphics.FromImage(sourceBitmap);
  17.             Graphics targetGraphics;
  18.             targetGraphics = Graphics.FromImage(targetBitmap);
  19.  
  20.             // Begin implementation code
  21.  
  22.             targetGraphics.DrawImage(sourceBitmap, 0, 0);
  23.             targetGraphics.DrawImage(sourceBitmap, 0, h);
  24.  
  25.             Bitmap returnBitmap = new Bitmap(w, targetHeight, targetGraphics);
  26.             targetGraphics.Dispose();
  27.  
  28.  
  29.  
  30.             return returnBitmap;
  31.         }
But it seems to return an empty bitmap. Please help, I am at my wit's end. :-)
Jan 17 '10 #1
4 1848
Dataflashsabot
4 New Member
Nevermind, I'm an idiot. The problem was in the code that was taking the return value. On the plus side, I rewrote the whole function trying to solve this, and it's now much neater and cleaner.
Jan 18 '10 #2
Plater
7,872 Recognized Expert Expert
Maybe like this:
Expand|Select|Wrap|Line Numbers
  1. private Bitmap ProcessBitmap(Bitmap sourceBitmap) 
  2.    int h = sourceBitmap.Height;
  3.    Bitmap returnBitmap = new Bitmap(sourceBitmap.Width, h*2); 
  4.  
  5.    Graphics targetGraphics = Graphics.FromImage(targetBitmap);
  6.  
  7.    targetGraphics.DrawImageUnscaled(sourceBitmap, 0, 0);
  8.    targetGraphics.DrawImageUnscaled(sourceBitmap, 0, h);
  9.  
  10.    return returnBitmap; 
  11.  
Jan 18 '10 #3
akshaymahajan
12 New Member
Please forgive me if I sound rude ... but u don't need int h in your code. Just replace h by sourceBitmap.Height ... Just trying to save some memory space for the application :) .. Hope u don't mind.
Jan 21 '10 #4
Plater
7,872 Recognized Expert Expert
You could collapse the code a lot more then just getting rid of the h. Its just there so you can follow along
Jan 22 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
13388
by: Phil | last post by:
is there anyway to connect to bitmaps together? basically, I have a program that generates a graph as it runs, and I can capture an image of the graph, but is there a way to take two captures, and...
3
4396
by: James Dean | last post by:
I have 2 1bppindexed bitmaps and i want to combine both together. I converted both to 24bpp then tried to combine them but it didnt work. If possible i want to be able to draw one bitmap directly...
4
1293
by: Andrew Cook | last post by:
I am using Microsoft Visual Basic .net 2002 Standard. I am coding an application which loads in data from a compressed file. One of the items in the file is a raw RGB565 bitmap, at 800x600 pixels. In...
3
2546
by: Larry Serflaten | last post by:
I am taking a 256 color bitmap from a file and scaling it up X 16 to a 32bppPARGB bitmap in memory. I copy that image to the screen. After scaling, the edges of all the lines and colors are...
1
2225
by: John | last post by:
I have 76 bitmaps (640 x 480) and need to combine them together to form a big one (about 3840 x 2880). Those 76 bitmaps overlap each other with a small portion. Is there any way to do it? Thanks.
2
2054
by: Mike | last post by:
Hello everybody. I am drawing a country map that consists of 149 municipality bitmaps, each around 25 Kb. I draw it onto the in-memory bitmap, then draw it on the picture box. I use C++, but...
2
1256
by: **Developer** | last post by:
Stumbling through I find both of the following appear to work the same. I'm guessing there is a difference that I'm just not aware of. Can someone enlighten me? Thanks
6
1506
by: Paul | last post by:
I am developing a VB.net tool that requires editing to be done. I would like to use the same standard bitmaps for my command buttons as MS Word uses. Are these available anywhere?
4
2188
by: MarcuEusebiu | last post by:
Hello... I have to bmps (100X100) and 1`st has an A on the left side and the other has a B on the right side. I want to "sum" this bitmaps to obtain a bitmap that contains "AB". I thought to use...
1
8320
by: =?Utf-8?B?Sm9obg==?= | last post by:
Hi, I need to combine several bitmaps together to form a single bitmap. Can anyone show me some similar sample code? Thanks. AJ
0
7114
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7377
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7034
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5623
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5045
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1544
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
412
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.