dynamically change an image via c# script in Xamarin forms - image

I have a cross platform app which I need to show a set of images when the user clic in a button, so, I put these image files named as "img000.png" to "img029.png" in a folder in the PCL solution and make al these images as "EmbeddedResource", after,I fill a List with all these images and its work fine at now, i.e. the image is shown like I want, but when I click in the button to show the next image in the list the image don't go to the next.
I have this:
//...
public class ImageSetPage : BasePage
// BasePage encapsule a ContentPage...
{
private string directory = "MyApp.Assets.";
private int idx = 0;
protected StackLayout _mainLayout;
protected StackLayout _buttonStack;
protected Image _btnPrevI;
protected Label _displayName;
protected Image _btnNestI;
protected Image _image;
protected List<Image> _Images;
public ImageSetPage()
{
this._Images = getImages();
var prevI_Tap = new TapGestureRecognizer();
prevI_Tap.Tapped += (s, e) =>
{
onClick("pvi");
};
var nextI_Tap = new TapGestureRecognizer();
nextI_Tap.Tapped += (s, e) =>
{
onClick("nti");
};
/// begin layout
base.Title = "set of Images";
this._mainLayout = new StackLayout()
{
Orientation = StackOrientation.Vertical,
BackgroundColor = Color.Black,
Padding = new Thickness(0, 10, 0, 0)
};
this._btnPrevI = new Image()
{
Aspect = Aspect.AspectFill,
Source = ImageSource.FromResource(directory+"prevbtn.png")
};
_btnPrevI.GestureRecognizers.Add(prevI_Tap);
this._displayName = new Label()
{
Style = Device.Styles.SubtitleStyle,
HorizontalOptions = LayoutOptions.CenterAndExpand,
VerticalOptions = LayoutOptions.CenterAndExpand,
TextColor = Color.White,
};
this._btnNextI = new Image()
{
Aspect = Aspect.AspectFill,
Source = ImageSource.FromResource(directory + "nextbtn.png")
};
_btnNextI.GestureRecognizers.Add(nextI_Tap);
this._buttonStack.Children.Add(_btnPrevI);
this._buttonStack.Children.Add(_displayName);
this._buttonStack.Children.Add(_btnNextI);
this._mainLayout.Children.Add(_buttonStack);
FillImage(idx);
this._mainLayout.Children.Add(this._image);
this.Content = this._mainLayout;
}
private void FillImage(int i)
{
this._displayName.Text = "Image n# " + FillWithZeroes(i);
// [EDIT 1] cemented these lines ...
// this._image = null;
// mi = _images[i];
// this._image = mi;
// [EDIT 2] the new try
string f = directory + "imgs.img0" + FillWithZeroes(i) + ".png";
this._image = new Image() {
VerticalOptions = LayoutOptions.Center,
Soruce = ImageSource.FromResource(f)
};
// In this way the image show and don't change when click
// this Fking* code is a big S_OF_THE_B*
// The Xamarin and the C# is brothers of this FKing* code
}
private void onClick(string v)
{
string vw = v;
if (vw.Equals("pvi")) idx--;
if (vw.Equals("nti")) idx++;
if (idx <= 0) idx = 29;
if (idx >= 29) idx = 0;
FillImage(idx);
vw = "";
}
private string FillWithZeroes(int v)
{
string s = v.ToString();
string r = "";
if (s.Length == 1) { r = "0" + s; } else { r = s; }
return r;
}
// to fill a list of Images with files in a PCL folder
private List<Image> getImages()
{
string directory = "MyApp.Assets.";
List<Image> imgCards = new List<Image>();
int c = 0;
for (c = 0; c < 30;c++) {
string f = directory + "imgs.img0" + FillWithZeroes(c) + ".png";
Image img = new Image();
img.Source = ImageSource.FromResource(f);
imgCards.Add(img);
}
return imgCards;
}
// ...
}
but the image don't change, i.e. change, like I see in debug, but don't show in the Layout when I click in the buttons.
Maybe I'm doing it wrong.
Can someone here help me?
thanks in advance

Related

Add Image in Word Open SDK + dotnet core

I am trying to add an image to the word document using dotnet core and Open SDK library. Followed the exact same instruction as per the MSDN article. The code runs ok, but while trying to open document its says the document is corrupted.
Microsoft Doc
Used the OpenSDK Productivity tool and validated the document. Showing this error
Have confirmed that the Image Type are same. Not able to understand whats wrong.
private const string RefrenceKeyWord = "rId";
static void Main(string[] args)
{
InsertAPicture(document, fileName);
}
public static void InsertAPicture(string document, string fileName)
{
Int64Value imageWidth = 5731510L;
Int64Value imageHeight = 3820795L;
//using (var image = new Bitmap(fileName))
//{
// imageWidth = image.GetWidthInEMUs() / 10;
// imageHeight = image.GetHeightInEMUs() / 10;
//}
using (WordprocessingDocument wordprocessingDocument =
WordprocessingDocument.Open(document, true))
{
MainDocumentPart mainPart = wordprocessingDocument.MainDocumentPart;
ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Png);
using (FileStream stream = new FileStream(fileName, FileMode.Open))
{
imagePart.FeedData(stream);
}
//## start of new Code ##
var maxId = mainPart.Parts
.Where(p => p.RelationshipId.StartsWith(RefrenceKeyWord))
.Select(p =>
Convert.ToInt32(p.RelationshipId.Replace(RefrenceKeyWord,
"")))
.Max();
mainPart.ChangeIdOfPart(imagePart, $"{RefrenceKeyWord}{maxId + 1}");
//## end of new Code ##
AddImageToBody(wordprocessingDocument, mainPart.GetIdOfPart(imagePart), imageWidth, imageHeight);
}
}
private static void AddImageToBody(WordprocessingDocument wordDoc, string relationshipId, Int64Value width, Int64Value height)
{
// Define the reference of the image.
var element =
new Drawing(
new DW.Inline(
new DW.Extent() { Cx = width, Cy = height },
new DW.EffectExtent()
{
LeftEdge = 0L,
TopEdge = 0L,
RightEdge = 2540L,
BottomEdge = 8255L
},
new DW.DocProperties()
{
Id = (UInt32Value)1U,
Name = "Picture 1",
},
new DW.NonVisualGraphicFrameDrawingProperties(
new A.GraphicFrameLocks() { NoChangeAspect = true }),
new A.Graphic(
new A.GraphicData(
new PIC.Picture(
new PIC.NonVisualPictureProperties(
new PIC.NonVisualDrawingProperties()
{
Id = (UInt32Value)0U,
Name = "Picture 1"
},
new PIC.NonVisualPictureDrawingProperties(new A.PictureLocks() { NoChangeAspect = true, NoChangeArrowheads = true })),
new PIC.BlipFill(
new A.Blip(
new A.BlipExtensionList(
new A.BlipExtension()
{
Uri = "{28A0092B-C50C-407E-A947-70E740481C1C}",
})
)
{
Embed = relationshipId,
//CompressionState =
//A.BlipCompressionValues.Print
},
new A.Stretch(
new A.FillRectangle())),
new PIC.ShapeProperties(
new A.Transform2D(
new A.Offset() { X = 0L, Y = 0L },
new A.Extents() { Cx = width, Cy = height }),
new A.PresetGeometry(
new A.AdjustValueList()
)
{ Preset = A.ShapeTypeValues.Rectangle }))
)
{ Uri = "https://schemas.openxmlformats.org/drawingml/2006/picture" })
)
{
DistanceFromTop = (UInt32Value)0U,
DistanceFromBottom = (UInt32Value)0U,
DistanceFromLeft = (UInt32Value)0U,
DistanceFromRight = (UInt32Value)0U,
EditId = "50D07946"
});
SectionProperties sectPr = (SectionProperties)wordDoc.MainDocumentPart.Document.Body.ChildElements.Last();
// var p = wordDoc.MainDocumentPart.RootElement;
// var p1 = wordDoc.MainDocumentPart.Document.Body.FirstChild;
var p1 = new Paragaph(new Run(element));
// Append the reference to body, the element should be in a Run.
wordDoc.MainDocumentPart.Document.Body.InsertBefore(p1, sectPr);
}

What is the function of Message sender in xamarin.forms

What is the function of Message sender in xamarin.forms? In my app I have cart contain list view and a Grant Total label. Is it possible to update the label using message sender? I can get the total amount from my sqlite db I need to update it to the view.
This is my number picker index change event in view cell
numPicker.SelectedIndexChanged += (sender, args) =>
{
// var price = _cartQuery.GetSum();
sender = BindingContext;
// cm_items item = (cm_items)sender;
if(Int32.Parse(btn_NumBtn.Text)<=1)
{
lbl_Price.Text = ((numPicker.SelectedIndex + 1) * (Int32.Parse(lbl_Price.Text))).ToString();
btn_NumBtn.Text = (numPicker.SelectedIndex + 1).ToString();
}
else
{
int a = Int32.Parse(lbl_Price.Text);
int b = Int32.Parse(btn_NumBtn.Text);
int c = a / b;
lbl_Price.Text = ((numPicker.SelectedIndex + 1) * c).ToString();
btn_NumBtn.Text = (numPicker.SelectedIndex + 1).ToString();
}
_cartQuery.UpdatePicker((BindingContext as CartDB).Cart_Item_Id, numPicker.SelectedIndex + 1, Int32.Parse(lbl_Price.Text));
price = _cartQuery.GetSum();
// App.Instance.ViewModel.TotalAmount = price;
// _cartDB.total = App.Instance.ViewModel.TotalAmount;
Calculate_price();
numPicker.IsEnabled = false;
};
Calculate_price method
public double Calculate_price()
{
try
{
var price = 0;
price = _cartQuery.GetSum();
App.Instance.ViewModel.TotalAmount = price;
return price;
}
catch (Exception ex)
{
throw ex;
}
}
In my view i have a label named grant total, i need to update the total on e number picker change
Label lbl_amnt = new Label
{
// Text = viewModel.Price.ToString(),
// Text=CartCell.price.ToString(),
Text = price.ToString(),
FontSize = 18,
FontAttributes = FontAttributes.Bold,
TextColor = Color.FromRgb(102, 204, 102),
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.EndAndExpand,
};
lbl_amnt.SetBinding(Label.TextProperty, "TotalAmount");
update to my post as per the comment from #Grish
In my view model i have this TotalAmount as a property
public double _TotalAmount;
public double TotalAmount
{
get { return _TotalAmount; }
set { _TotalAmount = value; OnPropertyChanged("TotalAmount");}
}
I think the better solution is i notify but the thing is view is not binding
Binding is definitely the answer in your case. I think the problem is that you bind string (label's text) to property of type double.
You should specify IValueConverter or stringFormat parameters in your call to SetBinding.
Check this link:
https://forums.xamarin.com/discussion/19146/binding-to-integers

Inserting image in PPTX using OpenXML does not work

I am trying to generate a PowerPoint file containing a image using OpenXML. Unfortunately it does not work. The image is not being displayed. I've checked the file generated with the OpenXML productivity tool and I respectively unzipped the file contents. The file itself contains the image in /ppt/media/image.png and it should be displayed in the second slide.
Here's my code:
private void InsertSlide(string chartString, int position, string title, string text = "")
{
if (m_presentation == null || title == null || m_presentation.PresentationPart == null)
return;
var slide = new Slide(new CommonSlideData(new ShapeTree()));
var nonVisualProperties =
slide.CommonSlideData.ShapeTree.AppendChild(new NonVisualGroupShapeProperties());
nonVisualProperties.NonVisualDrawingProperties = new NonVisualDrawingProperties { Id = 1, Name = "" };
nonVisualProperties.NonVisualGroupShapeDrawingProperties = new NonVisualGroupShapeDrawingProperties();
nonVisualProperties.ApplicationNonVisualDrawingProperties = new ApplicationNonVisualDrawingProperties();
slide.CommonSlideData.ShapeTree.AppendChild(new GroupShapeProperties());
var slidePart = m_presentation.PresentationPart.AddNewPart<SlidePart>();
var imagePart = slidePart.AddImagePart(ImagePartType.Png, "irgendeinscheiss");
//var imageStream = new MemoryStream(Convert.FromBase64String(chartString));
using (var imageStream = new FileStream(#"C:\Users\DA\Desktop\Charts\1_Chart2_01.png", FileMode.Open))
{
imageStream.Position = 0;
imagePart.FeedData(imageStream);
}
slide.Save(slidePart);
var slideIdList = m_presentation.PresentationPart.Presentation.SlideIdList;
uint maxSlideId = 1;
SlideId prevSlideId = null;
foreach (SlideId slideId in slideIdList.ChildElements)
{
if (slideId.Id > maxSlideId)
maxSlideId = slideId.Id;
position--;
if (position == 0)
prevSlideId = slideId;
}
maxSlideId++;
SlidePart lastSlidePart;
if (prevSlideId != null)
lastSlidePart = (SlidePart)m_presentation.PresentationPart.GetPartById(prevSlideId.RelationshipId);
else
lastSlidePart = (SlidePart)m_presentation.PresentationPart.GetPartById(((SlideId)(slideIdList.ChildElements[0])).RelationshipId);
if (lastSlidePart.SlideLayoutPart != null)
slidePart.AddPart(lastSlidePart.SlideLayoutPart);
var newSlideId = slideIdList.InsertAfter(new SlideId(), prevSlideId);
newSlideId.Id = maxSlideId;
newSlideId.RelationshipId = m_presentation.PresentationPart.GetIdOfPart(slidePart);
m_presentation.PresentationPart.Presentation.Save();
}
Am I missing something? Maybe the relationships? After looking up 232243 thousand different examples, I am still stuck at this point. Thank you!
I think you need to add the image into the slide.CommonSlideData
public Slide InsertSlide(PresentationPart presentationPart, string layoutName)
{
UInt32 slideId = 256U;
// Get the Slide Id collection of the presentation document
var slideIdList = presentationPart.Presentation.SlideIdList;
if (slideIdList == null)
{
throw new NullReferenceException("The number of slide is empty, please select a ppt with a slide at least again");
}
slideId += Convert.ToUInt32(slideIdList.Count());
// Creates an Slide instance and adds its children.
Slide slide = new Slide(new CommonSlideData(new ShapeTree()));
SlidePart slidePart = presentationPart.AddNewPart<SlidePart>();
slide.Save(slidePart);
// Get SlideMasterPart and SlideLayoutPart from the existing Presentation Part
SlideMasterPart slideMasterPart = presentationPart.SlideMasterParts.First();
SlideLayoutPart slideLayoutPart = slideMasterPart.SlideLayoutParts.SingleOrDefault
(sl => sl.SlideLayout.CommonSlideData.Name.Value.Equals(layoutName, StringComparison.OrdinalIgnoreCase));
if (slideLayoutPart == null)
{
throw new Exception("The slide layout " + layoutName + " is not found");
}
slidePart.AddPart<SlideLayoutPart>(slideLayoutPart);
slidePart.Slide.CommonSlideData = (CommonSlideData)slideMasterPart.SlideLayoutParts.SingleOrDefault(
sl => sl.SlideLayout.CommonSlideData.Name.Value.Equals(layoutName)).SlideLayout.CommonSlideData.Clone();
// Create SlideId instance and Set property
SlideId newSlideId = presentationPart.Presentation.SlideIdList.AppendChild<SlideId>(new SlideId());
newSlideId.Id = slideId;
newSlideId.RelationshipId = presentationPart.GetIdOfPart(slidePart);
return GetSlideByRelationShipId(presentationPart, newSlideId.RelationshipId);
}
/// <summary>
/// Get Slide By RelationShip ID
/// </summary>
/// <param name="presentationPart">Presentation Part</param>
/// <param name="relationshipId">Relationship ID</param>
/// <returns>Slide Object</returns>
private static Slide GetSlideByRelationShipId(PresentationPart presentationPart, StringValue relationshipId)
{
// Get Slide object by Relationship ID
SlidePart slidePart = presentationPart.GetPartById(relationshipId) as SlidePart;
if (slidePart != null)
{
return slidePart.Slide;
}
else
{
return null;
}
}
Public void InsertImageInLastSlide(Slide slide, string imagePath, string imageExt)
{
// Creates an Picture instance and adds its children.
P.Picture picture = new P.Picture();
string embedId = string.Empty;
embedId = "rId" + (slide.Elements().Count() + 915).ToString();
P.NonVisualPictureProperties nonVisualPictureProperties = new P.NonVisualPictureProperties(
new P.NonVisualDrawingProperties() { Id = (UInt32Value)4U, Name = "Picture 5" },
new P.NonVisualPictureDrawingProperties(new A.PictureLocks() { NoChangeAspect = true }),
new ApplicationNonVisualDrawingProperties());
P.BlipFill blipFill = new P.BlipFill();
Blip blip = new Blip() { Embed = embedId };
// Creates an BlipExtensionList instance and adds its children
BlipExtensionList blipExtensionList = new BlipExtensionList();
BlipExtension blipExtension = new BlipExtension() { Uri = "{28A0092B-C50C-407E-A947-70E740481C1C}" };
UseLocalDpi useLocalDpi = new UseLocalDpi() { Val = false };
useLocalDpi.AddNamespaceDeclaration("a14",
"http://schemas.microsoft.com/office/drawing/2010/main");
blipExtension.Append(useLocalDpi);
blipExtensionList.Append(blipExtension);
blip.Append(blipExtensionList);
Stretch stretch = new Stretch();
FillRectangle fillRectangle = new FillRectangle();
stretch.Append(fillRectangle);
blipFill.Append(blip);
blipFill.Append(stretch);
// Creates an ShapeProperties instance and adds its children.
P.ShapeProperties shapeProperties = new P.ShapeProperties();
A.Transform2D transform2D = new A.Transform2D();
A.Offset offset = new A.Offset() { X = 457200L, Y = 1524000L };
A.Extents extents = new A.Extents() { Cx = 8229600L, Cy = 5029200L };
transform2D.Append(offset);
transform2D.Append(extents);
A.PresetGeometry presetGeometry = new A.PresetGeometry() { Preset = A.ShapeTypeValues.Rectangle };
A.AdjustValueList adjustValueList = new A.AdjustValueList();
presetGeometry.Append(adjustValueList);
shapeProperties.Append(transform2D);
shapeProperties.Append(presetGeometry);
picture.Append(nonVisualPictureProperties);
picture.Append(blipFill);
picture.Append(shapeProperties);
slide.CommonSlideData.ShapeTree.AppendChild(picture);
// Generates content of imagePart.
ImagePart imagePart = slide.SlidePart.AddNewPart<ImagePart>(imageExt, embedId);
FileStream fileStream = new FileStream(imagePath, FileMode.Open);
imagePart.FeedData(fileStream);
fileStream.Close();
}
Source Code

When I Deploy my gwt application on tomcat and run it in IE all the images from the resource bundle appear on the screen

Hi I am developing a project where I need to produce a time line sort of a thing where in I need to place images dynamically in a horizontal line depending on the condition. The image instance would differ based on the condition from the data base and the number of instances also would differ. I used an absolute panel to do so and placed the images at a difference of 40 between the horizontal axis keeping the y-axis constant. The images come from a class which extends Client Bundle as follows.
public interface TimeLineWidgetResources extends ClientBundle {
TimeLineWidgetResources INSTANCE = GWT
.create(TimeLineWidgetResources.class);
#Source("application-connection-point_big.png")
ImageResource getApplicationConnectionPointImage();
#Source("business-connection-point_big.png")
ImageResource getBusinessConnectionPointImage();
#Source("monitor_small.png")
ImageResource getMonitorImage();
}
I have placed only 3 here but in my resource file i have almost 15 images.
The time line looked perfect on the jetty server in IE, Chrome and Safari. But when i create a war and deploy it in tomcat it looks perfect in Chrome and safari but all the images come and get displayed on the screen in IE. if i create 5 instances of it then it is creating 5*15 = 75 instances of those images. Can anybody help me with this. What am I doing wrong here? Let me post the absolute panel code as well here.
/** The method to build Time Line using an absolute Panel */
public void buildNewTimeLine(GWTTimeLine timeLine) {
absolutePanel.setPixelSize((Window.getClientWidth() * 3) / 4, 200);
absolutePanel.getElement().getStyle().setOverflow(Overflow.AUTO);
String startDate = timeLine.getStartDate();
String endDate = timeLine.getEndDate();
List<GWTTimeLineComponent> timeLineComponents = new ArrayList<GWTTimeLineComponent>();
timeLineComponents = timeLine.getComponents();
buildTimeLineEvents(timeLineComponents);
int i = 0;
for (i = 0; i < timeLineComponents.size(); i++) {
if (i == 0) {
Image startImage = new Image();
startImage
.setUrl(resources.getVerticalLineImage().getSafeUri());
absolutePanel.add(startImage, 48, 70);
}
if (i == (timeLineComponents.size() - 1)) {
Image continueImage = new Image();
continueImage
.setUrl(resources.getLineArrowImage().getSafeUri());
absolutePanel.add(continueImage, horizontalImageXAxis + 80, 70);
}
GWTTimeLineComponent timeLineComponent = new GWTTimeLineComponent();
timeLineComponent = timeLineComponents.get(i);
String icon = timeLineComponent.getIcon();
int id = timeLineComponent.getId();
String logicalId = timeLineComponent.getLogicalId();
List<GWTTimeLineEvent> timeLineEvents = new ArrayList<GWTTimeLineEvent>();
timeLineEvents = timeLineComponent.getEvents();
if (icon.startsWith("infor.engine.monitor")) {
if (isAbove == true) {
isAbove = false;
isBelow = true;
Image monitorImage = new Image();
monitorImage.setUrl(resources.getMonitorImage()
.getSafeUri());
monitorImage.setTitle(timeLineComponent.getLogicalId());
String downOrUpOrBiDirectionalArrow = "up";
buildTimeLineComponents(downOrUpOrBiDirectionalArrow,
monitorImage, id, logicalId);
}
else if (isBelow == true) {
isAbove = true;
isBelow = false;
Image monitorImage = new Image();
monitorImage.setUrl(resources.getMonitorImage()
.getSafeUri());
monitorImage.setTitle(timeLineComponent.getLogicalId());
String downOrUpOrBiDirectionalArrow = "down";
buildTimeLineComponents(downOrUpOrBiDirectionalArrow,
monitorImage, id, logicalId);
}
} else if (icon.startsWith("infor.database")) {
if (isAbove == true) {
isAbove = false;
isBelow = true;
Image databaseImage = new Image();
databaseImage.setUrl(resources
.getDatabaseConnectionPointImage().getSafeUri());
databaseImage.setTitle(timeLineComponent.getLogicalId());
String downOrUpOrBiDirectionalArrow = "up";
buildTimeLineComponents(downOrUpOrBiDirectionalArrow,
databaseImage, id, logicalId);
}
else if (isBelow == true) {
isAbove = true;
isBelow = false;
Image databaseImage = new Image();
databaseImage.setUrl(resources
.getDatabaseConnectionPointImage().getSafeUri());
databaseImage.setTitle(timeLineComponent.getLogicalId());
String downOrUpOrBiDirectionalArrow = "down";
buildTimeLineComponents(downOrUpOrBiDirectionalArrow,
databaseImage, id, logicalId);
}
} else if (icon.startsWith("infor.jms")) {
if (isAbove == true) {
isAbove = false;
isBelow = true;
Image jmsImage = new Image();
jmsImage.setUrl(resources.getJmsQueueConnectionPointImage()
.getSafeUri());
jmsImage.setTitle(timeLineComponent.getLogicalId());
String downOrUpOrBiDirectionalArrow = "up";
buildTimeLineComponents(downOrUpOrBiDirectionalArrow,
jmsImage, id, logicalId);
}
else if (isBelow == true) {
isAbove = true;
isBelow = false;
Image jmsImage = new Image();
jmsImage.setUrl(resources.getJmsQueueConnectionPointImage()
.getSafeUri());
jmsImage.setTitle(timeLineComponent.getLogicalId());
String downOrUpOrBiDirectionalArrow = "down";
buildTimeLineComponents(downOrUpOrBiDirectionalArrow,
jmsImage, id, logicalId);
}
} else if (icon.startsWith("infor.ws")) {
if (isAbove == true) {
isAbove = false;
isBelow = true;
Image webServiceImage = new Image();
webServiceImage.setUrl(resources
.getWebServiceConnectionPointImage().getSafeUri());
webServiceImage.setTitle(timeLineComponent.getLogicalId());
String downOrUpOrBiDirectionalArrow = "up";
buildTimeLineComponents(downOrUpOrBiDirectionalArrow,
webServiceImage, id, logicalId);
}
else if (isBelow == true) {
isAbove = true;
isBelow = false;
Image webServiceImage = new Image();
webServiceImage.setUrl(resources
.getWebServiceConnectionPointImage().getSafeUri());
webServiceImage.setTitle(timeLineComponent.getLogicalId());
String downOrUpOrBiDirectionalArrow = "down";
buildTimeLineComponents(downOrUpOrBiDirectionalArrow,
webServiceImage, id, logicalId);
}
} else if (icon.startsWith("infor.sap")) {
if (isAbove == true) {
isAbove = false;
isBelow = true;
Image sapImage = new Image();
sapImage.setUrl(resources.getBusinessConnectionPointImage()
.getSafeUri());
sapImage.setTitle(timeLineComponent.getLogicalId());
String downOrUpOrBiDirectionalArrow = "up";
buildTimeLineComponents(downOrUpOrBiDirectionalArrow,
sapImage, id, logicalId);
}
else if (isBelow == true) {
isAbove = true;
isBelow = false;
Image sapImage = new Image();
sapImage.setUrl(resources.getBusinessConnectionPointImage()
.getSafeUri());
sapImage.setTitle(timeLineComponent.getLogicalId());
String downOrUpOrBiDirectionalArrow = "down";
buildTimeLineComponents(downOrUpOrBiDirectionalArrow,
sapImage, id, logicalId);
}
}
else if (icon.startsWith("infor.bod")) {
Image horizontalLine = new Image();
horizontalLine.setUrl(resources.getHorizontalLineImage()
.getSafeUri());
Image bodImage = new Image();
bodImage.setUrl(resources.getBodImage().getSafeUri());
addBodImageClickHandlers(bodImage,
searchEvent.getSelectedMessageId());
bodImageXAxis = horizontalImageXAxis + 40;
horizontalImageXAxis = horizontalImageXAxis + 20;
bodImageYAxis = 65;
absolutePanel.add(bodImage, bodImageXAxis, bodImageYAxis);
}
}
}
/** The method to build Time Line components */
public void buildTimeLineComponents(String downOrUpOrBiDirectionalArrow,
Image connectionPointImage, int id, String logicalId) {
Image horizontalLine = new Image();
horizontalLine.setUrl(resources.getHorizontalLineImage().getSafeUri());
Image arrow = new Image();
if (downOrUpOrBiDirectionalArrow.equals("down")) {
arrow.setUrl(resources.getDownArrowImage().getSafeUri());
connectionPointImageYAxis = 95;
arrowImageYAxis = 72;
}
if (downOrUpOrBiDirectionalArrow.equals("up")) {
arrow.setUrl(resources.getUpArrowImage().getSafeUri());
connectionPointImageYAxis = 10;
arrowImageYAxis = 46;
}
addConnectionPointImageClickHandlers(connectionPointImage, id,
logicalId);
horizontalImageXAxis = horizontalImageXAxis + widthBetweenTImages;
absolutePanel.add(horizontalLine, horizontalImageXAxis,
horizontalImageYAxis);
connectionPointImageXAxis = horizontalImageXAxis + 7;
arrowImageXAxis = horizontalImageXAxis + 15;
absolutePanel.add(connectionPointImage, connectionPointImageXAxis,
connectionPointImageYAxis);
absolutePanel.add(arrow, arrowImageXAxis, arrowImageYAxis);
}
Please Help.
You're doing it wrong.
In IE 6-7 (or equivalent document modes in IE8+), getSafeUri() returns the URL of a composite image (aka sprited image), as explained in the Javadoc: http://google-web-toolkit.googlecode.com/svn/javadoc/latest/com/google/gwt/resources/client/ImageResource.html#getSafeUri%28%29
Use Image#setResource instead of Image#setUrl.
I had the same problem with IE8 and higher which was set to compatibility mode.
To ensure your sprites being rendered correctly in IE set it to IE8 mode by adding <meta http-equiv="X-UA-Compatible" content="IE=8" /> to the header section of your project html.

Add table to powerpoint slide using Open XML

I got the code for the Table in the powerpoint using the code generator, but I am not able to add the table to an existing powerpoint document.
I tried adding another table to the intended slide and doing the following:
Table table = slidePart.Slide.Descendants<Table>().First();
table.RemoveAllChildren();
Table createdTable = CreateTable();
foreach (OpenXmlElement childElement in createdTable.ChildElements)
{
table.AppendChild(childElement.CloneNode(true));
}
But that didn't work.
I am out of ideas on this issue.
My original target is to add a table with dynamic number of columns and fixed number of row to my presentation.
I know its been very long since this question is posted, but just in case if some one needs a working code to create table in pptx.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Presentation;
using A = DocumentFormat.OpenXml.Drawing;
using System.IO;
namespace ANF.Slides.TestEngine
{
class Program
{
static int index = 1;
static void Main(string[] args)
{
Console.WriteLine("Preparing Presentation");
PopulateData();
// GeneratedClass cls=new GeneratedClass();
//cls.CreatePackage(#"E:\output.pptx");
Console.WriteLine("Completed Presentation");
Console.ReadLine();
}
private static void PopulateData()
{
var overflow = false;
const int pageBorder = 3000000;
var db = new AdventureWorksEntities();
var products = db.Products;//.Take(5);
const string outputFile = #"E:\openxml\output.pptx";
File.Copy(#"E:\OpenXml\Template.pptx", outputFile, true);
using (var myPres = PresentationDocument.Open(outputFile, true))
{
var presPart = myPres.PresentationPart;
var slideIdList = presPart.Presentation.SlideIdList;
var list = slideIdList.ChildElements
.Cast<SlideId>()
.Select(x => presPart.GetPartById(x.RelationshipId))
.Cast<SlidePart>();
var tableSlidePart = (SlidePart)list.Last();
var current = tableSlidePart;
long totalHeight = 0;
foreach (var product in products)
{
if (overflow)
{
var newTablePart = CloneSlidePart(presPart, tableSlidePart);
current = newTablePart;
overflow = false;
totalHeight = 0;
}
var tbl = current.Slide.Descendants<A.Table>().First();
var tr = new A.TableRow();
tr.Height = 200000;
tr.Append(CreateTextCell(product.Name));
tr.Append(CreateTextCell(product.ProductNumber));
tr.Append(CreateTextCell(product.Size));
tr.Append(CreateTextCell(String.Format("{0:00}", product.ListPrice)));
tr.Append(CreateTextCell(product.SellStartDate.ToShortDateString()));
tbl.Append(tr);
totalHeight += tr.Height;
if (totalHeight > pageBorder)
overflow = true;
}
}
}
static SlidePart CloneSlidePart(PresentationPart presentationPart, SlidePart slideTemplate)
{
//Create a new slide part in the presentation
SlidePart newSlidePart = presentationPart.AddNewPart<SlidePart>("newSlide" + index);
index++;
//Add the slide template content into the new slide
newSlidePart.FeedData(slideTemplate.GetStream(FileMode.Open));
//make sure the new slide references the proper slide layout
newSlidePart.AddPart(slideTemplate.SlideLayoutPart);
//Get the list of slide ids
SlideIdList slideIdList = presentationPart.Presentation.SlideIdList;
//Figure out where to add the next slide (find max slide)
uint maxSlideId = 1;
SlideId prevSlideId = null;
foreach (SlideId slideId in slideIdList.ChildElements)
{
if (slideId.Id > maxSlideId)
{
maxSlideId = slideId.Id;
prevSlideId = slideId;
}
}
maxSlideId++;
//Add new slide at the end of the deck
SlideId newSlideId = slideIdList.InsertAfter(new SlideId(), prevSlideId);
//Make sure id and relid is set appropriately
newSlideId.Id = maxSlideId;
newSlideId.RelationshipId = presentationPart.GetIdOfPart(newSlidePart);
return newSlidePart;
}
private static A.TableCell CreateTextCell(string text)
{
var textCol = new string[2];
if (!string.IsNullOrEmpty(text))
{
if (text.Length > 25)
{
textCol[0] = text.Substring(0, 25);
textCol[1] = text.Substring(26);
}
else
{
textCol[0] = text;
}
}
else
{
textCol[0] = string.Empty;
}
A.TableCell tableCell3 = new A.TableCell();
A.TextBody textBody3 = new A.TextBody();
A.BodyProperties bodyProperties3 = new A.BodyProperties();
A.ListStyle listStyle3 = new A.ListStyle();
textBody3.Append(bodyProperties3);
textBody3.Append(listStyle3);
var nonNull = textCol.Where(t => !string.IsNullOrEmpty(t)).ToList();
foreach (var textVal in nonNull)
{
//if (!string.IsNullOrEmpty(textVal))
//{
A.Paragraph paragraph3 = new A.Paragraph();
A.Run run2 = new A.Run();
A.RunProperties runProperties2 = new A.RunProperties() { Language = "en-US", Dirty = false, SmartTagClean = false };
A.Text text2 = new A.Text();
text2.Text = textVal;
run2.Append(runProperties2);
run2.Append(text2);
paragraph3.Append(run2);
textBody3.Append(paragraph3);
//}
}
A.TableCellProperties tableCellProperties3 = new A.TableCellProperties();
tableCell3.Append(textBody3);
tableCell3.Append(tableCellProperties3);
//var tc = new A.TableCell(
// new A.TextBody(
// new A.BodyProperties(),
// new A.Paragraph(
// new A.Run(
// new A.Text(text)))),
// new A.TableCellProperties());
//return tc;
return tableCell3;
}
}
}

Resources