I'm trying to print multiple labels using UIPrintInteractionController.PrintingItems but when the image is loaded it fills the page, is it possible to have multiple images on one page using this method or is there another method that would offer me a better solution? Thanks.
void Print()
{
var printInfo = UIPrintInfo.PrintInfo;
printInfo.OutputType = UIPrintInfoOutputType.General;
printInfo.JobName = "Label Printing";
//UIPrintFormatter formatter = new UIPrintFormatter()
//{
// StartPage = 0,
// ContentInsets = new UIEdgeInsets(72, 72, 72, 72),
// MaximumContentWidth = 6 * 72,
//};
int labelAmount = 10;
int x;
NSObject[] labelItems = new NSObject[labelAmount];
for (x = 0; x < labelAmount; x++)
{
labelItems[x] = UIImage.FromFile("Images/BMcAzurri.png");
}
UIPrintInteractionController printer = UIPrintInteractionController.SharedPrintController;
printer.PrintInfo = printInfo;
//printer.PrintFormatter = formatter;
printer.PrintingItems = labelItems;
printer.ShowsPageRange = true;
printer.Present(true, (handler, completed, err) => {
if (!completed && err != null)
{
Console.WriteLine("error");
}
});
}
There are a few ways to do what you are asking, here is just one using a graphics context to do your print page rendering.
Load your image into a UIImage instance
You might want to pre-scale/re-scale that image
Create a UIView that is large enough to contain all your rows and columns of that image
Create a UIImageView that contains your image for each row/column on your "printed page" and place it at the correct location in this view
Using an Image render context, convert the UIView that contains your images to a UIImage and queue and print as many of those as you need...
Example:
var printInfo = UIPrintInfo.PrintInfo;
printInfo.OutputType = UIPrintInfoOutputType.General;
printInfo.JobName = "Label Printing";
var uiImage = UIImage.FromFile("BingWallpaper-2017-05-04.jpg");
var noColumns = 2;
var noRows = 2;
var gapBetweenImages = 25;
int noOfPages = 2;
NSObject[] labelItems = new NSObject[noOfPages];
for (int x = 0; x < noOfPages; x++)
{
var aPrintView = new UIView
{
Frame = new CGRect(0, 0, (uiImage.Size.Width * noColumns) + ((noColumns + 1) * gapBetweenImages), (uiImage.Size.Height) * noRows + ((noRows + 1) * gapBetweenImages))
};
for (int column = 0; column < noColumns; column++)
{
for (int row = 0; row < noRows; row++)
{
var printImage = new UIImageView(uiImage)
{
Frame = new CGRect((column * gapBetweenImages) + (column * uiImage.Size.Width), (row * gapBetweenImages) + (row * uiImage.Size.Height), uiImage.Size.Width, uiImage.Size.Height)
};
aPrintView.Add(printImage);
}
}
UIGraphics.BeginImageContext(aPrintView.Bounds.Size);
aPrintView.Layer.RenderInContext(UIGraphics.GetCurrentContext());
var aPageImage = UIGraphics.GetImageFromCurrentImageContext();
UIGraphics.EndImageContext();
labelItems[x] = aPageImage;
}
UIPrintInteractionController printer = UIPrintInteractionController.SharedPrintController;
printer.PrintInfo = printInfo;
printer.PrintingItems = labelItems;
printer.ShowsPageRange = true;
printer.Present(true, (handler, completed, err) =>
{
if (!completed && err != null)
{
Console.WriteLine("error");
}
});
Note: !!! This is not handling the clean up, make sure you Dispose of everything after you are done...
Note: This is just a quick example does not handle the aspect ratio of the image to the paper size, you would need to consider that depending upon what you are printing and to what type of printer/paper...
Note: If you were renderering a number of text fields vs. images, you might want to render to a PDF vs a UIImage and print that instead.
Related
I'm trying to convert a Java class to a C# one using EmguCV. It's for a class in Unsupervised Learning. The teacher made a program using OpenCV and Java. I have to convert it to C#.
The goal is to implement a simple Face Recognition algorithm.
The method I'm stuck at:
Mat sample = train.get(0).getData();
mean = Mat.zeros(/*6400*/sample.rows(), /*1*/sample.cols(), /*CvType.CV_64FC1*/sample.type());
// Calculating it by hand
train.forEach(person -> {
Mat data = person.getData();
for (int i = 0; i < mean.rows(); i++) {
double mv = mean.get(i, 0)[0]; // Gets the value of the cell in the first channel
double pv = data.get(i, 0)[0]; // Gets the value of the cell in the first channel
mv += pv;
mean.put(i, 0, mv); // *********** I'm stuck here ***********
}
});
So far, my C# equivalent is:
var sample = trainSet[0].Data;
mean = Mat.Zeros(sample.Rows, sample.Cols, sample.Depth, sample.NumberOfChannels);
foreach (var person in trainSet)
{
var data = person.Data;
for (int i = 0; i < mean.Rows; i++)
{
var meanValue = (double)mean.GetData().GetValue(i,0);
var personValue = (double)data.GetData().GetValue(i, 0);
meanValue += personValue;
}
}
And I am not finding the put equivalent in C#. But, if I'm being honest, I'm not even sure the previous two lines in my C# equivalent are correct.
Can someone help me figure this one out?
You can convert it like this:
Mat sample = trainSet[0].Data;
Mat mean = Mat.Zeros(sample.Rows, sample.Cols, sample.Depth, sample.NumberOfChannels);
foreach (var person in trainSet)
{
Mat data = person.Data;
for (int i = 0; i < mean.Rows; i++)
{
double meanValue = (double)mean.GetData().GetValue(i, 0);
double personValue = (double)data.GetData().GetValue(i, 0);
meanValue += personValue;
double[] mva = new double[] { meanValue };
Marshal.Copy(mva, 0, mean.DataPointer + i * mean.Cols * mean.ElementSize, 1);
}
}
I am trying to implement Variable Rate Shading in the app based on DirectX 11.
I am doing it this way:
UINT dwRtWidth = 2560;
UINT dwRtHeight = 1440;
D3D11_TEXTURE2D_DESC srcDesc;
ZeroMemory(&srcDesc, sizeof(srcDesc));
int sri_w = dwRtWidth / NV_VARIABLE_PIXEL_SHADING_TILE_WIDTH;
int sri_h = dwRtHeight / NV_VARIABLE_PIXEL_SHADING_TILE_HEIGHT;
srcDesc.Width = sri_w;
srcDesc.Height = sri_h;
srcDesc.ArraySize = 1;
srcDesc.Format = DXGI_FORMAT_R8_UINT;
srcDesc.SampleDesc.Count = 1;
srcDesc.SampleDesc.Quality = 0;
srcDesc.Usage = D3D11_USAGE_DEFAULT; //Optional
srcDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE; //Optional
srcDesc.CPUAccessFlags = 0;
srcDesc.MiscFlags = 0;
D3D11_SUBRESOURCE_DATA initialData;
UINT* data = (UINT*)malloc(sri_w * sri_h * sizeof(UINT));
for (int i = 0; i < sri_w * sri_h; i++)
data[i] = (UINT)0;
initialData.pSysMem = data;
initialData.SysMemPitch = sri_w;
//initialData.SysMemSlicePitch = 0;
HRESULT hr = s_device->CreateTexture2D(&srcDesc, &initialData, &pShadingRateSurface);
if (FAILED(hr))
{
LOG("Texture not created");
LOG(std::system_category().message(hr));
}
else
LOG("Texture created");
When I try to create texture with initial data, it is not being created and HRESULTS gives message: 'The parameter is incorrect'. Doesn't say which one.
When I create texture without initial data it's created successfully.
What's wrong with the initial data? I also tried to use unsigned char instead of UINT as it has 8 bits, but result was the same, texture was not created.
Please help.
Aftr some time I found a solution to the problem. I needed to add a line:
srcDesc.MipLevels = 1;
With this change the texture was finally created with initial data
let jsonResult1:NSDictionary = NSJSONSerialization.JSONObjectWithData(da!, options:NSJSONReadingOptions.MutableContainers , error: &error) as NSDictionary
println(jsonResult1)
getting below data in console
{
0 = {
"consulting_dr" = "DR.Appaji .";
"current_bed_nr" = 0;
"current_room_nr" = 0;
"discharge_date" = "03/03/2015 00:00";
"encounter_date" = "02/03/2015 12:45";
"encounter_nr" = 201503024000;
info = "";
"item_description" = "";
name = "Mrs. mythily S";
pdob = "01/08/1976";
pid = 100004;
psex = f;
pyear = "38 Years";
};
1 = {
dosage = 1;
drdate = "25/08/2014";
drnotes = "";
drugclass = Tablet;
duration = "5 day";
frequency = "";
medicine = "ACECLOFENAC+PARACETAMOL";
route = Oral;
tcomplients = "";
};
2 = {
BMI = "A:1:{s:4:\"SPO2\";s:1:\"1\";}";
BSA = "A:1:{s:4:\"SPO2\";s:1:\"1\";}";
"Dystolic_bp" = 29;
Height = 24;
Pulse = 26;
Respiration = 27;
"Systolic_bp" = 28;
Temp = 25;
Weight = 22;
dosage = 1;
drdate = "25/08/2014";
drnotes = "";
drugclass = Tablet;
duration = "5 day";
frequency = "";
medicine = RABEPRAZOLE;
route = Oral;
tcomplients = "";
};
}
how to store this in array
That is a Dictionary. It is easy to get just the data without the keys.
In Objective-C it would be :
NSArray *allData = [jsonResult1 allValues];
For swift it should be like: (not sure about syntax)
var allData = jsonResult1.allValues()
If you're up for it, you should give SwiftyJSON a try.
https://github.com/SwiftyJSON/SwiftyJSON
I've recently used it for an application that deals with a ton of JSON responses from a web service and SwiftyJSON has made it super easy for me to deal with JSON data in Swift. It will convert NSData to Dictionaries or Arrays seamlessly for you.
i am working on mvc4 project.I have having issue with export to excel code.I have employee id that is varchar field... and have leading zero ie : 0289707,2909878 etc..
So when i export data to excel it looses leading zero..
So how do i export data as it is ??
Controller code is as below :
public ActionResult ExportToExcel(string strStartDate, string strEndDate)
{
try
{
GridView gridView = new GridView();
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "EmployeeReport " + Helper.GetBrazilTime(DateTime.UtcNow).ToString() + ".xls"));
Response.ContentType = "application/ms-excel";
StringWriter stringWriter = new StringWriter();
HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);
gridView.AllowPaging = false;
DateTime startDate = Convert.ToDateTime(strStartDate);
DateTime endDate = Convert.ToDateTime(strEndDate);
if (Helper.CurrentCulture == "pt-BR")
{
startDate = new DateTime(startDate.Year, startDate.Month, startDate.Day, 0, 0, 0, DateTimeKind.Utc);
endDate = new DateTime(endDate.Year, startDate.Month, endDate.Day, 0, 0, 0, DateTimeKind.Utc);
}
gridView.DataSource = ReportExecutor.GetEmployeeReportExportData(startDate, endDate);
gridView.DataBind();
//This will change the header background color
gridView.HeaderRow.Style.Add("background-color", "#FFFFFF"); //
//This will apply style to gridview header cells
for (int index = 0; index < gridView.HeaderRow.Cells.Count; index++)
{
gridView.HeaderRow.Cells[index].Style.Add("background-color", "#778899"); //Light Slate Gray
gridView.HeaderRow.Cells[index].Style.Add("foreground-color", "#ffffff"); // White
}
gridView.HeaderRow.Cells[0].Text = #Resources.Resource.ShopName;
gridView.HeaderRow.Cells[1].Text = #Resources.Resource.MachineName;
gridView.HeaderRow.Cells[2].Text = #Resources.Resource.ProjectIDName;
gridView.HeaderRow.Cells[3].Text = #Resources.Resource.BaseActivity;
gridView.HeaderRow.Cells[4].Text = #Resources.Resource.EmployeeID;
gridView.HeaderRow.Cells[5].Text = #Resources.Resource.EmployeeName;
gridView.HeaderRow.Cells[6].Text = #Resources.Resource.RunTime;
gridView.HeaderRow.Cells[7].Text = #Resources.Resource.SetUp;
gridView.HeaderRow.Cells[8].Text = #Resources.Resource.TearDown;
gridView.HeaderRow.Cells[9].Text = #Resources.Resource.Work;
gridView.HeaderRow.Cells[10].Text = #Resources.Resource.Rework;
gridView.HeaderRow.Cells[11].Text = #Resources.Resource.LunchHours;
gridView.HeaderRow.Cells[12].Text = #Resources.Resource.MaintenanceHours;
gridView.HeaderRow.Cells[13].Text = #Resources.Resource.QualityProblemHours;
gridView.HeaderRow.Cells[14].Text = #Resources.Resource.LOMHours;
gridView.HeaderRow.Cells[15].Text = #Resources.Resource.UDCIdle;
gridView.HeaderRow.Cells[16].Text = #Resources.Resource.UDCOthers;
gridView.HeaderRow.Cells[17].Text = #Resources.Resource.ActualShiftHours;
gridView.HeaderRow.Cells[18].Text = #Resources.Resource.Overtime;
int index2 = 1;
//This will apply style to alternate rows
foreach (GridViewRow gridViewRow in gridView.Rows)
{
//gridViewRow.Attributes.Add("class", "textmode");
gridViewRow.BackColor = Color.White;
if (index2 <= gridView.Rows.Count)
{
if (index2 % 2 != 0)
{
for (int index3 = 0; index3 < gridViewRow.Cells.Count; index3++)
{
gridViewRow.Cells[index3].Style.Add("background-color", "#e6e6fa");// Lavender
//gridViewRow.Cells[index3].Style.Add("class", "textmode");// Apply text style to all rows
}
}
}
index2++;
}
gridView.RenderControl(htmlTextWriter);
Response.Write(stringWriter.ToString());
Response.End();
}
catch
{
}
return null;
}
For i As Integer = 0 To GridView1.Rows.Count - 1
//Apply text style to each Row.cell
//The attribute must be "text" not "textmode" and it must be applied to the cells
For j As Integer = 0 To GridView1.Rows(i).Cells.Count - 1
GridView1.Rows(i).Cells(j).Attributes.Add("class", "text");
Next
Next
I have problem with an embedded image in email. When receiving mail I show image in attachment instead of message body and I have add image dynamically in message body. And also I have set "cid" but I have not success. I have set ishtmlbody = true but not showing image in body. please solve my problem.
My code is here:
This is my body message:
const string to = "test#gmail.com";
msg.To.Add(to);
msg.From = new MailAddress("test#gmail.com");
msg.Subject = "test";
int count = 1;
int stratindex = 0;
//Create altenative view
AlternateView alternative = AlternateView.CreateAlternateViewFromString(strMailContent, null, MediaTypeNames.Text.Html);
while ((lastIndex = strMailContent.IndexOf(findStr, stratindex, StringComparison.Ordinal)) != -1)
{
int srcStartIndex =Convert.ToInt32(strMailContent.IndexOf("src", lastIndex, StringComparison.Ordinal)) + 5;
int srcEndIndex = strMailContent.IndexOf(#"'", srcStartIndex, StringComparison.Ordinal);
string imgSrc = strMailContent.Substring(srcStartIndex, srcEndIndex - srcStartIndex);
string path = imgSrc;
// Atteched resource
// set cid
var resource = new LinkedResource(path, "image/jpg");
string cid = "companylogo" + count;
//now add the AlternateView
resource.ContentId = cid;
alternative.LinkedResources.Add(resource);
msg.AlternateViews.Add(alternative);
//now append it to the body of the mail
strMailContent = strMailContent.Replace(strMailContent.Substring(srcStartIndex, srcEndIndex - srcStartIndex), "cid:" + cid);
stratindex = strMailContent.IndexOf("<br/>", lastIndex, StringComparison.Ordinal) + 5;
strMailContent = strMailContent.Remove(stratindex - 5, 5);
stratindex = stratindex - 5;
count++;
}
show in screen short red area show the attachment and yellow area show blank body.
how to solve this problem.
I don't see any problems in your code, you have to ensure the path file is correct