Copying Bitmap onto Another Bitmap - Small ratio problem
Copying Bitmap onto Another Bitmap - Small ratio problem
Copying Bitmap onto Another Bitmap - Small ratio problem
Copying Bitmap onto Another Bitmap - Small ratio problem
Copying Bitmap onto Another Bitmap - Small ratio problem
Copying Bitmap onto Another Bitmap - Small ratio problem Copying Bitmap onto Another Bitmap - Small ratio problem Copying Bitmap onto Another Bitmap - Small ratio problem Copying Bitmap onto Another Bitmap - Small ratio problem Copying Bitmap onto Another Bitmap - Small ratio problem Copying Bitmap onto Another Bitmap - Small ratio problem Copying Bitmap onto Another Bitmap - Small ratio problem Copying Bitmap onto Another Bitmap - Small ratio problem
Copying Bitmap onto Another Bitmap - Small ratio problem Copying Bitmap onto Another Bitmap - Small ratio problem
Copying Bitmap onto Another Bitmap - Small ratio problem
Go Back  Xtreme Visual Basic Talk > > > Copying Bitmap onto Another Bitmap - Small ratio problem


Reply
 
Thread Tools Display Modes
  #1  
Old 02-23-2013, 07:21 PM
Ninth Wave Ninth Wave is offline
Freshman
 
Join Date: Nov 2005
Location: Australia
Posts: 35
Default Copying Bitmap onto Another Bitmap - Small ratio problem


I am copying part of one Bitmap onto another Bitmap, however when I do this, it prints the bitmap in a large size and at a higher position.

It looks like a ratio difference between the two objects is causing this to happen.

How do I make it print the same size and position without it changing the size?




Code:
            Dim fr_bm As New Bitmap(ImagePath & "\tiles.bmp")
            Dim gr As Graphics = Graphics.FromImage(FullBackground)

            Dim fr_rect As New Rectangle(TileX, TileY, TileWidth, TileWidth)
            Dim to_rect As New Rectangle(WorldX, WorldY, TileWidth, TileWidth)

            gr.DrawImage(fr_bm, to_rect, fr_rect, GraphicsUnit.Pixel)
[/CODE]

Last edited by Ninth Wave; 02-23-2013 at 07:27 PM.
Reply With Quote
  #2  
Old 02-23-2013, 11:33 PM
passel's Avatar
passelCopying Bitmap onto Another Bitmap - Small ratio problem passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,026
Default

Most likely the DPI settings of the two bitmaps differ and since GDI+ is supposed to be designed to be device independent, the image is scaled to maintain "physical" size.
You would need to post code with samples of bitmaps that demonstrate the problem for others to analyze, as the code snippet alone doesn't give enough information to demonstrate the problem or test possible solutions.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #3  
Old 02-24-2013, 01:54 AM
hDC_0Copying Bitmap onto Another Bitmap - Small ratio problem hDC_0 is offline
Contributor

* Expert *
 
Join Date: Feb 2004
Posts: 559
Default DPI (Dots per inch) and resolution

Quote:
Originally Posted by Ninth Wave
It looks like a ratio difference between the two objects is causing this to happen.
I believe the correct term is resolution not ratio.
The term "ratio" is more closely aligned with the term "aspect ratio" which is a term designed to be descriptive of proportionality.

But passel is right about not having enough information to fully answer your question.

The topic of DIBs (Device Independent Bitmaps) versus DDBs (Device dependent Bitmaps) is a large one.

I'll just throw in:
MSDN Bitmap.SetResolution method

This page has a "hint" for its use:
Quote:
For an image (Bitmap) you can use the SetResolution method.
This will not resample the image however.
To do this you can create an image of the correct resolution and pixel size, obtain a Graphics object using Graphics.FromImage,
using the new image as a parameter then draw the original image onto the new one.
The interpolation mode will control the resample quality.
Typical dpi usage ranges:
72 dpi -96 dpi is for screen resolution
150 dpi-200 dpi is a good scan dpi for not-to-large (but still decent looking) web graphics
300 dpi - 4800 dpi typical printer resolution range

One not-always-ideal "fudge" that I've seen (when resizing for printing) is to use matrix scaling / transforms
along the lines of this vbHelper print drawing to fit code.

Last edited by hDC_0; 02-24-2013 at 02:13 AM.
Reply With Quote
  #4  
Old 02-24-2013, 07:24 AM
AtmaWeapon's Avatar
AtmaWeaponCopying Bitmap onto Another Bitmap - Small ratio problem AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

This is also the appropriate use of the DrawImageUnscaled() function. It ignores the adjustments necessary to maintain physical size and puts the pictures you give it in the location you tell it.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #5  
Old 02-24-2013, 07:56 AM
snarfblam's Avatar
snarfblamCopying Bitmap onto Another Bitmap - Small ratio problem snarfblam is offline
Senior Contributor

Forum Leader
* Expert *
 
Join Date: Apr 2005
Location: USA
Posts: 896
Default

Quote:
Originally Posted by AtmaWeapon View Post
This is also the appropriate use of the DrawImageUnscaled() function. It ignores the adjustments necessary to maintain physical size and puts the pictures you give it in the location you tell it.
This is a common point of confusion that I found very frustrating when learning GDI+. With DrawImageUnscaled, "unscaled" means the image will be drawn at 1:1 physical scale, not 1:1 pixel scale. In other words, it does the exact opposite of what it sounds like and will force scaling the the source and target have different DPI settings.

Quote:
Originally Posted by MSDN
The DrawImageUnscaled method draws an image using its physical size, so the image will have its correct size in inches regardless of the resolution (dots per inch) of the display device.
The correct way to draw an image without scaling is to provide source and destination rectangles with the same size. In other words, it looks like you're doing it correctly, Ninth Wave. Have you applied any kind of transformation or changed interpolation settings?
__________________
C# _VB.NET _
Reply With Quote
  #6  
Old 02-24-2013, 10:01 AM
AtmaWeapon's Avatar
AtmaWeaponCopying Bitmap onto Another Bitmap - Small ratio problem AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

Dang it did that method fool me again? That's what I get for posting before coffee.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Copying Bitmap onto Another Bitmap - Small ratio problem
Copying Bitmap onto Another Bitmap - Small ratio problem
Copying Bitmap onto Another Bitmap - Small ratio problem Copying Bitmap onto Another Bitmap - Small ratio problem
Copying Bitmap onto Another Bitmap - Small ratio problem
Copying Bitmap onto Another Bitmap - Small ratio problem
Copying Bitmap onto Another Bitmap - Small ratio problem Copying Bitmap onto Another Bitmap - Small ratio problem Copying Bitmap onto Another Bitmap - Small ratio problem Copying Bitmap onto Another Bitmap - Small ratio problem Copying Bitmap onto Another Bitmap - Small ratio problem Copying Bitmap onto Another Bitmap - Small ratio problem Copying Bitmap onto Another Bitmap - Small ratio problem
Copying Bitmap onto Another Bitmap - Small ratio problem
Copying Bitmap onto Another Bitmap - Small ratio problem
 
Copying Bitmap onto Another Bitmap - Small ratio problem
Copying Bitmap onto Another Bitmap - Small ratio problem
 
-->