Dynamically change an image in a Crystal Report at runtime - image

I'm using the Crystal Reports included with VisualStudio 2005. I would like to change the image that is displayed on the report at runtime ideally by building a path to the image file and then have that image displayed on the report.
Has anyone been able to accomplish this with this version of Crystal Reports?

At work we do this by pushing the image(s) into the report as fields of a datatable. It's not pretty, but it gets the job done. Of course, this solution requires that you push data into the reports via a DataSet. I've always felt this was a hack at best. I really wish that image parameters were a possibility with CR.
Edit: It's worth noting, if you are binding your crystal report to plain old objects you want to expose a byte[] property for the report to treat that as an image.

I finally reached a solution using the byte[] tip posted here by Josh.
This solution applies if you are using a plain old C# Object to populate your Crystal Reports (see http://www.aspfree.com/c/a/C-Sharp/Crystal-Reports-for-Visual-Studio-2005-in-CSharp/ for info on this approach).
In your C# class, insert the following code:
private static byte[] m_Bitmap = null;
public byte[] Bitmap
{
get
{
FileStream fs = new FileStream(bitmapPath, FileMode.Open);
BinaryReader br = new BinaryReader(fs);
int length = (int)br.BaseStream.Length;
m_Bitmap = new byte[length];
m_Bitmap = br.ReadBytes(length);
br.Close();
fs.Close();
return m_Bitmap;
}
}
Now, update your C# Object Mapping in CR using the "Verify Database" option. You should then see the Bitmap property as a CR field. Just drag it onto the form. It will be of type IBlobFieldObject. When you run, you should see your image.

[I have since found a solution using a byte array via a C# Object property - see separate Answer. Leaving this answer here for reference...]
Here's what I have seen suggested (but I tried and failed in both C#-2005 and C#-2008).
Choose a directory and place a BMP there (e.g., "C:\Temp\image.bmp").
From the CR-Designer a) Right-click->Insert->OLE Object... b) Select "Create from File" c) Check the "Link" checkbox d) Browse and pick the bmp defined in step 1 e) Click OK f) Place the image on the form.
Overwrite/update the image at runtime in your C# code. In theory, since you inserted a Link to an image file, it will be updated when the form is refreshed.
I had no luck with this approach. The image appears when I first design the form (step 2). But at runtime, the image does not update for me. From this point forward, things get really odd. It seems that CR caches some sort of image that just won't go away. I can delete the OLE object link in CR-Designer, but if I recreate it, I always get a black box the same size as the original image (even if I change the size of image.bmp).

You can also use a conditional formula to set an image's location. See Crystal Reports: Dynamic Images.

Try using a combination of using a parameter containing the path of the image and the tutorial on this page: http://www.idautomation.com/crystal/streaming_crystal.html
Then in step #8, use the parameter instead of a hard-coded path.

Another option that I've found useful is inserting the pictures you would like to use. Position the graphic accordingly, then right-click the graphic and go to Format Graphic > Common. Check the Suppress box, then click the formula button, shown as x-2. Once in the formula window, simply add the code for determining whether the graphic should be suppressed or not.
In my case, I was building one invoice template for multiple entities. In the formula window, I simply wrote COMPANY <> 1100 which meant that every time the invoice was run for a company other than 1100, the 1100 graphic would be suppressed.
Hopefully this makes life easier...

The current version of Crystal Reports (for Visual Studio 2012+) that I use with Visual Studio 2015 supports this function. Follow the following steps:
Insert a picture into your report. This will serve as your
placeholder.'
Right click your picture and choose Format Object
Select the Picture tab and the press the formula button
A formula window will open. Enter a formula that will find your pictures as links.
if({#isDonor}="1")
then "http://www.ny.org/images/aaf/picture1.jpg"
else "http://www.ny.org/images/aaf/picture2.jpg"
And you're done!

Just like Josh said.. You will have to push the image with a dataset. Or, put the image into a database table once and pull it in many times with a subreport.

Related

Issue with Oracle Reports 6i to PDF

everyone.
I am working with Oracle Reports 6i to generate a report that includeds text in the form of paragraphs. Everything looks fine from the Real Time Viewer however when the report is run to generate a PDF, some, of the paragraphs would change from Justified to Filled.
This doesn't happen for every text container. In a full page I will have two paragraphs that are filled instead of justified.
Here is the details.
Each paragraph is within their own container.
The alignment for all containers is set to Justified(Flush)
Paragraphs have the same font type and font size.
I have already try the size of the output but it didn't make a difference. Is there any configuration parameter or any format function I can use to fix this?
Thank you all!!
If some paragraphs are OK and some are not, I'd suggest you to use good, old copy/paste principle:
delete wrong ones
copy correct one
paste it
edit its contents - hopefully, it'll look OK (as all properties the "correct" one had are now "inherited")

Check if an image contains another image

Im trying to check if a screenshot contains an image that is saved in the project resources, I need to find a 100% match only and would like to not use any extra libraries, now with that being said, I have no idea how to do so.
heres a few questions:,
do I compare the two buffered images together? do I change them into something else?
Il have to compare it atleast once a second or so. (just as general information)
I have a resource folder under my project in eclipse and the .png files are shown as text, is there a way to change that? I tried tinkering with the settings, no luck yet.
public static BufferedImage screenshot(){
BufferedImage capture = robot.createScreenCapture(screenSize);
return capture;
}
this is my screenshot, another bufferedimage is for example "compare", where the size of the compared image is smaller than the screenshot. how will I be able to check if the image contain the second image?
*For those who wondering, im trying to make a simple program that clicks a certain image once it pops up.

MS Visio 2010: Saving as .svg sets values to 0

I want to save my Visio shapes as an .svg file to incorporate into a XML document. However, when i save it ALL the values in my shape are set to 0. I've quadruple checked the shape data and all the values are there and the formulas are returning the correct values. The strange thing is, saving as a .svg works in Visio 2007 and all values are correct, but in Visio 2010 all the values are 0. Why is this? Unfortunately this is my first post, so I can't add screenshots as i don't have 10 rep.
The shape is 4 individual rows grouped together. The data is stored in the "Main" shape, i.e all rows grouped together. The cell in the individual shape then references its value from the main shape.
Example of 1 of the 4 main shape row forumlas:
ShapeData Property - Value = Sheet.1!Prop.Row_2 (references main shape rows, stores value)
Text Field Property - Value = Prop.Row_1 (references its single row, containing value of main shape)
The real kick here is I fixed this problem 4 months ago, but my colleagues had more shapes with the same issue. I cannot remember how i fixed it, and the shape that I fixed is identical in terms of structure and data handling.
Something strange that I also noticed is that when i type ".Value" after the Value field text in either the Text Fields or Shape Data properties, the ".Value" gets automatically omitted after I press enter, but then the field produces the right .svg output. However, this does not work when I make that change in the master shape. So effectively, I'd have to go into every single value field and manually type ".Value" and press enter for it to work. I've also tried turning off all shape protection, no joy.
I'm currently in the process of writing a macro to "refresh" all the value fields by adding ".Value" after them to mimic me manually typing that in.
Any help or feedback would be greatly appreciated!
I believe this is upgrade issue (2007->2010). Have seen this a few times. To fix try:
Open the diagram in Visio 2003 (or 2007), but not in Visio 2010
Save it as .VDX (Visio XML Drawing) file
Close it
Open the VDX file again in the same Visio
Save it back as normal VSD file. This should fix the broken VSD file.
Delete the VDX file, it is not needed
If this doesn't work then try sharing the source file (dropbox or whatever).
The problem was that the rows Text Fields were Data Object types. When I removed the Text shape protection and inserted a Shape Data field, the correct values were shown on the .svg output file.

How to see image data using opencv in visual studio?

I wrote an OPENCV project in VS2010 and the results were not the ones as I expected so I ran the debugger to see where is the problem. When I wanted to see the data inside the image loaded I didn't know how to do it so if I want to see the data inside my images what should I do?
It is pretty simple in matlab for seeing different channel of an image i.e.
a=imread('test.jpg');
p1 = a(:,:,1)
p2 = b(:,:,2)
.
.
In opencv I wrote the same thing but I don't know how to see all the element at once just like Matlab.
a= imread("test.jpg")
split(a,planes);
vector<Mat> T1;
T1 = planes[0];
// How can I see the data inside T1 when debugging the code ?
I think this is what you are looking for - it's a great Visual Studio add-on
https://bitbucket.org/sergiu/opencv-visualizers
Just download the installer, make sure VS is closed, run it, re-open VS and voila! Now, when you point to an OpenCV data structure, all kinds of nice info is showed.
Limitations: I saw some problems with multichannel images (it only shows the first channel) and it also has trouble displaying large matrices. If you want to see raw data in a big matrix, you can use the old good VS trick with debug variables: Stop at a breakpoint, go to Watch tab, and write there
((float*)myMat.data) ,10
Where float is the matrix type, myMat is your matrix, and 10 is the number of values you want to print. It will display the first 10 values at the memory location of myMat.data. If you do not correctly choose the data type, you'll see garbage. In my example, myMat is of type cv::Mat.
And never forget the power of visualizers:
imshow("Image", myMat);
If your data fits into an image. You can use the contrib module's colormap to enhance your visualizers.
I can't actually believe that nobody suggested Image Watch yet. It's the most amazing add-in ever. It shows you a view with all your Mat variables (images (gray and color), matrices) while debugging, there's useful stuff like zooming or contrast-stretching and you can even apply more complex functions directly in the plugin in real-time. It makes debugging of any kind of image operations a breeze and it's immensely helpful if you do calculations and linear algebra stuff with your cv::Mat matrices.
I recommend to use a NativeViewer extension. It actually displays the content of an image in a preview window, not only the properly formatted info.
If you don't want to use a plug-in or extension to Visual Studio, you can access the elements one by one in the debugging watch tab by typing this:
T1.data[T1.step.buf[0]*i + T1.step.buf[1]*j];
where i is the row you want to look at and j is the column.
after downloading imagewatch use the command in watch window
(imagesLoc._Myfirst)[0]
index of image in the vector
You can use the immediate window and the extenshion method like this one
/// <summary>
/// Displays image
/// </summary>
public static void Display (this Mat m, Rect rect = default, string windowName = "")
{
if (string.IsNullOrEmpty(windowName))
{
windowName = m.ToString();
}
var img = rect == default ? m : m.Crop(rect);
double coef = Math.Min(1600d / img.Width, 800d / img.Height);
Cv2.ImShow(windowName, img.Resize(new Size(coef * img.Width, (coef * img.Height) > 1 ? coef * img.Height : 1)));
Cv2.WaitKey();
}
Then you stop at a breakpoint and call yourImage.Display() in the immediate window.
If you can use CLion you can utilize the OpenCV Image Viewer plugin, which displays matrices while debugging just on click.
https://plugins.jetbrains.com/plugin/14371-opencv-image-viewer
Disclaimer: I'm an author of this plugin

placeholder image is displaying in place of first image while loading dynamic image in crystal report

I am trying to insert the images in one of my crystal sub reports. I have tried the following steps:
Insert a placeholder image.
right-click the graphic -> 'Format Graphic' -> 'Picture' tab -> Add a formula under 'Graphic Location'(basically given path of the images from the table).
Run the report.
I all my images get loaded as expected except for the first one. In place of first image, the place holder image is displaying only (which is undesired). I am unable to understand where I am committing a mistake. I am new in crystal report any help this regards will highly appreciated. I am basically developing a Windows application with Visual Studio 2010 and I have CR runtime version CR13_3_0_3.
There may be a number of causes for this problem.
Please try to do the following:
Right-click the graphic -> 'Format Graphic' -> 'Common' tab -> Make sure "Can Grow" is ticked and "Lock Position And Size" is unticked.
Try enlarging the section size so the picture could fit.
Make sure whether the formula that brings the picture from the table is 0-based or not.
You can try switching between a picture that does show and the one that doesn't in order to understand whether the problem occurs due to the picture itself or is it something with your report configuration.

Resources