TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
vineetha k
NA
3
0
Photo printing in C#
Mar 15 2011 10:54 AM
I have the following C# code to print 8x6 photos in a desktop application. It works on regular printer with regular letter size paper. But my client is using kodak printer with 8x6 paper, the photos are printing but their size is different, they are not printing in full 8x6 size, I'm doing something wrong. Can someone please guide me in right direction.
public void Print(List ListToBePrinted) {
PrintDialog SelectedPrinter = new PrintDialog();
if (SelectedPrinter.ShowDialog() == true) {
PrintCapabilities printerCapabilities = SelectedPrinter.PrintQueue. GetPrintCapabilities();
Size PageSize = new Size(printerCapabilities. PageImageableArea.ExtentWidth, printerCapabilities. PageImageableArea. ExtentHeight);
Size PrintableImageSize = new Size();
foreach (Uri aUri in ListToBePrinted) {
DrawingVisual drawVisual = new DrawingVisual();
ImageBrush imageBrush = new ImageBrush();
imageBrush.ImageSource = new BitmapImage(aUri);
imageBrush.Stretch = Stretch.Fill;
imageBrush.TileMode = TileMode.None;
imageBrush.AlignmentX = AlignmentX.Center;
imageBrush.AlignmentY = AlignmentY.Center;
if (imageBrush.ImageSource.Width > imageBrush.ImageSource.Height)
PrintableImageSize = new Size(768, 576); //8x6
else PrintableImageSize = new Size(576, 768); //6x8
double xcor = 0; double ycor = 0;
if (imageBrush.ImageSource.Width > imageBrush.ImageSource.Height) {
if((PageSize.Width - PrintableImageSize.Height) > 0)
xcor = (PageSize.Width - PrintableImageSize.Height) / 2;
if((PageSize.Height - PrintableImageSize.Width)>0)
ycor = (PageSize.Height - PrintableImageSize.Width) / 2; }
else {
if((PageSize.Width - PrintableImageSize.Width)>0)
xcor = (PageSize.Width - PrintableImageSize.Width) / 2;
if((PageSize.Height - PrintableImageSize.Height)>0)
ycor = (PageSize.Height - PrintableImageSize.Height) / 2; }
using (DrawingContext drawingContext = drawVisual.RenderOpen()) {
if (imageBrush.ImageSource.Width > imageBrush.ImageSource.Height) {
drawingContext.PushTransform( new RotateTransform(90, PrintableImageSize.Width / 2, PrintableImageSize.Height / 2)); }
drawingContext.DrawRectangle( imageBrush, null, new Rect(xcor, ycor, PrintableImageSize.Width, PrintableImageSize.Height)); }
SelectedPrinter.PrintVisual( drawVisual, "Print");
} } }
Reply
Answers (
2
)
sending Parameters in reportings
How to make Colour combination game in c#?