Programmatically resize an image in a report - c#

My C# application generates a Crystal Report that contains many images with varying size, orientation, and aspect ratio. To make them appear correctly in the report, I use a white Square Canvas and center the image inside. This makes lot of wasted space:
Is it possible to resize each picture in the report to the appropriate size from C#? I have found a way to resize the images here, but I don't know if I can perform these steps from c#, especially when it comes to "Calculating and setting Width and Height to the proper number of twips."
I know the size of my image in C#, but can it be passed to and implemented in the report? Images are inside an xml file in base64 format.
Designer View:

Okay, i don't have a working solution but an idea that might help you ( and i hope it will )
I searched a programmatically way to do what you want, and i don't find anything. Unless the fact that you can manipulate your FieldObject with C#, it can't be used in your report.
So, i'll try to guide you with some screenshoots, but i am French and my screens will be in french, so sorry for the bad translations !
You can write a formula to change the display of your BinaryImage in your subreport. I just found a way to change the width of you data, not the height.
So, assuming my image is stored in "ARTICLE" table, and the name of the column is "ART_IMAGE". I put my data in the detail section and create a new formula, ignore the created formula, you need to access to the "formatting formulas" :
Here in my screen it is called "Formules de mise en forme". In the left you can see my simple report and on the right the formula panel, i clicked on my details section and i can see my only field.
Now right click on this field and create a new formatting formula :
A pop up is displayed, you'll need to choose something like that in english "
Adjusting the width" :
Now, you have to return the new width of your current image, a way to know what is the current width is to store it in a field in your database.
So if in your database you have a field for your image, and a field like image_width. In my example i have a field name ART_DIMENSION and i store the width of the image.
The tricky part is that this formula accept twips not inch or cm. For you information 1 inch = 1440 twips.
So in my example here is the formula :
So for each image to display, the width of my image will be the width stored in "ART_DIMENSIONS" ( with the good convert : inch to twips )
In your report design, with a formula like this which set the width dynamically for your image, you can set the section and your image object with a very small width. In this case your images will be displayed one by another because the section width will be edited for each image to display.
I tried to be very clear, hope it will help you, ask me any questions if you don't understand something.
Regards,

Related

WPF - Convert Rich text box contents to a bitmap image

Is there any way I can convert the contents of a rich text box to a bitmap in WPF?
I tried the solution mentioned in the following post: Saving RichTextBox FlowDocument to image
But my dilemma is I am unable to figure out how to calculate the required size of the bitmap before hand that would cover the entire flow document.
Please help. Thanks in advance.
FlowDocuments don't have a rigid size, that's the point:
Flow Document Overview:
Flow documents are designed to optimize viewing and readability. Rather than being set to one predefined layout, flow documents dynamically adjust and reflow their content based on run-time variables such as window size, device resolution, and optional user preferences.
You need to set either a height or a width restraint, or both. If you set only one, width for example, the FlowDocument will update to stretch vertically until all the content has been displayed. After you set the constraint(s), you can check the actual size of the document and that will give you the required size of your image.

Dynamic sized multi line TextBox field in a PDF

I have created a document in an open office with a multi-line form field:
The issue I am having is when the dynamic content exceeds the initial size of the multi-line text box:
Sure I can re-size the Text Box in the original template but the dynamic content may be from 1 to 50 lines and I want the text after the Text Box to be close to the last line of dynamic content.
Can someone suggest a way to solve this?
I have once coded a solution to set the width and height of a textbox programmatically based on the characters supplied. I think this was a school assignment a long time ago.
This can be done with both VBA in a code behind or probably with a macro even. Or with VB.net.
I don't have the code I used way back when, but basically determine the maximum width you are able to provide in character width, the preferred width. Determine the pixel requirement per character for that width. This becomes the textbox width.
Divide your total string character count by your preferred width character count. Round up, calculate the pixel height per character. And use this value times the rounded result for the textbox height. Dirty but it should work.
Any chance you can change to a label and set AutoSize to True? You can fix the width and let the height auto adjust. This should be done before converting to a pdf. In fact all of the sizing should be resovled before pdf conversion.
Another Down voter without a comment, should not be allowed.

How to create an image with multiple tiles in the background?

I would like to know how I can create one image from many. I would like to create a tile in my windows phone application like in this image (specifically, the People tile):
(source: addictivetips.com)
I have nine pictures, and I would create an image, that I will add like tile to background. Does anybody know how can I create an image that looks like the one in that picture?
I have very little experience in this space, but have you considered creating a control that simply displays up to 9 pictures side by side in a grid like that? You then can bind each image independently & change them out however you want. This article touches on how to bind phontos in WP7 nicely:
http://msdn.microsoft.com/en-us/library/hh286418(v=vs.92).aspx
If you're talking about assembling an actual graphic image like a jpeg or bitmap, you'll need to look at the Image Class, Bitmap Class, and Graphics Class. Essentially you'll need to implement the following steps:
Load the relevant images with From method in Image, typically Image.FromFile.
Determine how many rows and columns you'll be using.
Calculate the total width and height for your layout using the widths and heights of the loaded images with appropriate padding added.
Create a new Bitmap of the appropriate size with the correct background color and iamge format.
Have variables for the current drawing location (x & y).
Have variables for the current row and column in your layout.
In a loop, Create your Graphics object.
Use Graphics.DrawImage to add your loaded image to the layout bitmap.
Increment your drawing row and or column as appropriate.
Calculate your new drawing location.
Repeat until done.
One of the options is to use WriteableBitmapEx
Also you can probably find an answer to your question here: How can I merge two images into one?

how to work with and draw resize images WPF C#

Hello I need to know how I can manage to resize and draw pictures in a given space and the top and left values ​​are stored in a database or XML. What elements need to use?
I put pictures of the software that works to perfection, really need to create something like what is shown in the following images:
Imagen 2
Imagen 3
Thanks!!
You probably want a canvas with a resizing adorner that tells the elements what size and placement to draw. Here is one such example.

iTextSharp self-expanding page width

I'm writing a web application to generate labels. The label printer that I'm targeting utilizes 12mm tape and the customer specified that they want to limit the labels to 3.25". I know that with iTextSharp I can specify the size of the document I want to create, however it appears that I have to specify both a width and height.
Document document = new Document(new iTextSharp.text.Rectangle(234f, 33.84f));
234 is 3.25" converted to points, and 33.84 is 12mm converted to points, so this sets the document to the maximum size allowed. Is there any way to set just the height and let the document auto-expand to the amount of content? With that, is there a way to determine if the expanded width of the document exceeds to maximum allowed by the customer? Thanks in advance for any help you can offer.
No, that is not possible in iText. It's not a particularly good idea anywhere else either. As Redman said, PDF is a print-based format. It's not HTML.
There are some tricks you can do to get around this to some extent:
Create your page with the maximum legal height. 200" * 72dpi = 14400 points.
Add a "generic tag" to your paragraphs.
create a tag event handler that tracks where the bottom of your last paragraph was drawn.
Save the PDF.
Open it again with a PDFStamper
Set the bottom of the page to match the location of that last paragraph. Remember that the bottom left starts off at 0,0, and the top right will be
Save the final PDF
This trick will only work if your total output is less that 200" high. If you go over that, you'll still get a second page, and your "where the bottom is" code had better be prepared for it.
PS: I don't see what's wrong with having a number of 12mm x 3.25" pages... won't that perfectly fit the labels they want printed?
As far as I know, because PDF is a print format, the document width and height must be set.
This is why reporting tools generally default page sizes to the default printer page size.
You best bet to try and calculate the size of the content and create the PDF accordingly.
Depending on the volume and nature of the workflow, you could provide a preview for the customer to check before printing.

Categories

Resources