PDA

View Full Version : سوال: ساخت کارت عضویت در سی شارپ



amin_sltny
شنبه 26 بهمن 1392, 11:38 صبح
سلام من برای برنامه ام دارم سیستم ساخت کارت عضویت می سازم. به پیشنهاد بعضی از دوستان من این کار را با خود سی شارپ انجام دادم و از ابزرا های گزارش گیری استفاده نکردم

من یه پنل درست کردم که یه بک گراند داره و چند لیبل که اطلاعات روی اون ها نشان داده میشه بعد امدم از پنلم یه پرینت گرفتم. حالا یه مشکلی دارم که اولا سایز این کار متناسب با سایزی که من می خواستم نیست و دوم اینکه درصورتی که با سی شارپ اونا تغییر ساز بدم (عکس پنا را) کیفیت اون پایین میاد و کلا درست چاپ نمی شه به نظرتون بهتره چه کار کنم.

116755

اینم کد هام


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Printing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;

namespace Server
{
public partial class frmCreateMemberCard : Form
{
//declare event handler for printing in constructor

//Rest of the code
Bitmap MemoryImage;
public frmCreateMemberCard()
{
InitializeComponent();
}

private void frmCreateMemberCard_Load(object sender, EventArgs e)
{
printdoc1.PrintPage += new PrintPageEventHandler(printdoc1_PrintPage);
}

private void btn_Print_Click(object sender, EventArgs e)
{
Print(this.CardPanel);
}

public void GetPrintArea(Panel pnl)
{
Bitmap bmp = new Bitmap(pnl.Width, pnl.Height);
pnl.DrawToBitmap(bmp, new Rectangle(0, 0, pnl.Width, pnl.Height));
MemoryImage = new Bitmap(1039, 638);
MemoryImage = resizeImage(bmp, 1039, 638, 1000);
}
protected override void OnPaint(PaintEventArgs e)
{
if (MemoryImage != null)
{
e.Graphics.DrawImage(MemoryImage, 0, 0);
base.OnPaint(e);
}
}
void printdoc1_PrintPage(object sender, PrintPageEventArgs e)
{
Rectangle pagearea = e.PageBounds;
e.Graphics.DrawImage(MemoryImage, (pagearea.Width / 2) - (this.CardPanel.Width / 2), this.CardPanel.Location.Y);
}
public void Print(Panel pnl)
{
GetPrintArea(pnl);
// if (printDialog1.ShowDialog() == DialogResult.OK)
// {
printdoc1.PrinterSettings = printDialog1.PrinterSettings;
printdoc1.PrinterSettings.DefaultPageSettings.Pape rSize = new System.Drawing.Printing.PaperSize("CardPaper", 1039, 638);
printdoc1.PrinterSettings.DefaultPageSettings.Marg ins = new System.Drawing.Printing.Margins(0,0,0,0);
printPreviewDialog1.ShowDialog();
//printdoc1.Print();
// }
}


public Bitmap resizeImage(Bitmap image, int maxWidth, int maxHeight, int quality)
{
// Get the image's original width and height
int originalWidth = image.Width;
int originalHeight = image.Height;

// To preserve the aspect ratio
float ratioX = (float)maxWidth / (float)originalWidth;
float ratioY = (float)maxHeight / (float)originalHeight;
float ratio = Math.Min(ratioX, ratioY);

// New width and height based on aspect ratio
int newWidth = (int)(originalWidth * ratio);
int newHeight = (int)(originalHeight * ratio);

// Convert other formats (including CMYK) to RGB.
Bitmap newImage = new Bitmap(newWidth, newHeight, PixelFormat.Format24bppRgb);

// Draws the image in the specified size with quality mode set to HighQuality
using (Graphics graphics = Graphics.FromImage(newImage))
{
graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.DrawImage(image, 0, 0, newWidth, newHeight);
}

// Get an ImageCodecInfo object that represents the JPEG codec.
ImageCodecInfo imageCodecInfo = this.GetEncoderInfo(ImageFormat.Jpeg);

// Create an Encoder object for the Quality parameter.
var encoder = System.Drawing.Imaging.Encoder.Quality;

// Create an EncoderParameters object.
EncoderParameters encoderParameters = new EncoderParameters(1);

// Save the image as a JPEG file with quality level.
EncoderParameter encoderParameter = new EncoderParameter(encoder, quality);
encoderParameters.Param[0] = encoderParameter;
newImage.Save(AppDomain.CurrentDomain.BaseDirector y + "//1.jpg", imageCodecInfo, encoderParameters);
return newImage;
}

private ImageCodecInfo GetEncoderInfo(ImageFormat format)
{
return ImageCodecInfo.GetImageDecoders().SingleOrDefault( c => c.FormatID == format.Guid);
}

}
}

shahryari
شنبه 26 بهمن 1392, 16:16 عصر
شما میتونید عین همون کارت رو در استیمول ریپورت پیاده سازی کنید با کفیت بالا

amin_sltny
شنبه 26 بهمن 1392, 19:25 عصر
پس چه طور میشه بکگرانت و یه سری تنظیمات را در استیمول ریپورت پیاده سازی کرد و اشیا را کنترل کرد؟