Set image to RepositoryItemPictureEdit in XtraGrid - repository

I have XtraGrid, I've added a new column and set its ColumnEdit property to RepositoryItemPictureEdit.
I have tried to set an image to it using RepositoryItemPictureEdit1.Appearance.Image but it does not populate after the form's load, any thoughts why?
I have 2011 version

As i guess you are not assigning image to control in correct way. You can go through this DevExpress KB thread - Why do I get the "No image data" text in the GridColumn with the PictureEdit in-place editor?
Source : Assigning an image to a RepositoryItemPictureEdit
you can use this approach also:
1) Set the column's FieldName property to the "Image" ,as your DataTable contains this Field
2) Set the Image DataColumn type to the Image value
3) Change the code and do not convert an image to a byte array.
Just set it as below:
RepositoryItemPictureEdit pictureEdit = gridControl1.RepositoryItems.Add("PictureEdit") as RepositoryItemPictureEdit;
pictureEdit.SizeMode = PictureSizeMode.Zoom;
pictureEdit.NullText = " ";
gridView1.Columns["Picture"].ColumnEdit = pictureEdit;
To make the editor load images, the underlying data type should correspond to the RepositoryItemPictureEdit.PictureStoreMode property value
If you want to display image in cell then you can use CustomDrawCell Event
Here ImageStream is a property that store image.
public Stream ImageStream { get; set; }
you can use it as below:
if (profile != null)
{
imageStream = MyObj.ImageStream; // this image saved as stream
}
}
if (imageStream != null)
{
e.Graphics.DrawImage(System.Drawing.Image.FromStream(imageStream), e.Bounds);
if (cellValue.Condition== "XXXX")
{
e.Graphics.DrawRectangle(e.Cache.GetPen(Color.Red), e.Bounds);
}
e.DisplayText = text;
Rectangle r = e.Bounds;
Rectangle w = new Rectangle(r.X, r.Y - 5, r.Width, r.Height);
//Draw the cell value
e.Appearance.DrawString(e.Cache, e.DisplayText, w);
e.Bounds.Inflate(-2, -2);
}
More References:
How to put icons in grid cells
How to display external images in grid columns if the data source only contains links to the images
RepositoryItemPictureEdit Load Image
How to load a picture into the repositoryitemPictureEdit
RepositoryItemPictureEdit default empty image

Related

CKEditor - Set default cell properties in CKEditor in Hybris Backoffice

I want to set the default value of the 'Vertical Alignment' to 'Top' property present in the Cell Properties dialogbox of the CKEditor in the hybris backoffice. Such that when the user open up the dailog box the value 'Top' get automatically pre-populated in the Vertical Alignment field. (added screenshot).
DialogBox
I'm using the below code: (This works for setting defaults for normal textbox fields. but not working for select dropdowns).
CKEDITOR.on('dialogDefinition', function(ev) {
var dialogName = ev.data.name;
var dialogDefinition = ev.data.definition;
if (dialogName === 'cellProperties') {
var infoTab = dialogDefinition.getContents('info');
var vAlign = infoTab.get('vAlign'); //attached the screenshot of the object that I get here.
vAlign.selectedIndex = 1;
infoTab.get('vAlign')['default'] = 'Top';
}
});
This is the image of the vAlign object select object that i extract from the defination :
vAlign object
I'm able to set the table properties like 'txtBorder', 'txtWidth'(which are texbox input) successfully, but not able to change the default in the dropdown.

Winforms Itext Ghost Script Rectangular coordinates selection

Using C# and Winforms, I want to display a PDF, select a rectangular region, and then extract that area of text from a number of PDFs. For displaying the PDF, I have a number of options...
Use an "Adobe PDF Reader" control to display the PDF - However, I cant use mouseover events and according to https://forums.adobe.com/thread/1640606 its just not possible to select a region.
Use a "WebBrowser" control to display the PDF, but it appears I have the same issue with mouseover events and cannot select a region.
Convert the PDF to an image (using ghostscript in my case) and displaying it in a picturebox. I'm finding the most success here, as I can now generate and record the coordinates of a rectangular region. When I take these coordinates and apply them to the PDF using Itext, I don't think my rectangular region translates correctly.
My question is, How do I render the GhostScripted image in a picture box maintaining the same ratios so that my coordinates will line up with the PDF?
Thank you in advance for the down votes!!
Here is the current state of my code... Everything works with the exception that my units are off in space somewhere. The action DOES return text, but it's never the text I selected. Im sure its a combination of the coordinate system / units and I will continue to try to understand this.
---- update
With a PDF at 0 deg rotation (portrait), I think the following holds true, or is at least working for me right now... User Units having not been changed, the coordinates taken from selecting in the picturebox need adjusting. The Y coordinates need to be subtracted from the overall height while the X coordinate remains the same.
iTextSharp.text.Rectangle rect = new iTextSharp.text.Rectangle(first.X, 3024-first.Y, last.X, 3024-last.Y);
This is picking text up exactly as expected on 0 deg rotated PDFs. On 90 deg rotated PDFs, the X and Y coordinates just need to be swapped.I am updating the code snippet below to show my working example.
using System;
using System.Drawing;
using System.Windows.Forms;
using Ghostscript.NET.Rasterizer;
using iTextSharp.text.pdf;
using iTextSharp.text.pdf.parser;
namespace formPdf
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string fileName; // The filename of the pdf
float width; // The width of the PDF in pixels
float hight; // the Height of the PDF in pixels
float rotation; // the Rotation of the PDF 0 or 90
float llx = 0; // The Lower Left X value for applying to the PDF
float lly = 0; // the Lower Left Y value for applying to the PDF
float urx = 0; // the Upper Right X value for applying to the PDF
float ury = 0; // the Upper Right Y value for applying to the PDF
// OnCLick event to open the file browser and select a file... The Width, Height and rotation values are set and the program
// is directed to render the First page of the pdf by calling the setPicture function
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
try
{
fileName = openFileDialog1.FileName;
PdfReader reader = new PdfReader(fileName);
iTextSharp.text.Rectangle dim = reader.GetPageSizeWithRotation(1);
width = dim.Width;
hight = dim.Height;
rotation = dim.Rotation;
setPicture(openFileDialog1.FileName);
} catch
{
// do nothing for now
}
}
}
// Using Ghostscript, the image is rendered to a picturebox. DPIs are set assuming the PDF default value is used
private void setPicture(string fileName)
{
GhostscriptRasterizer rasterizer = new GhostscriptRasterizer();
rasterizer.Open(fileName);
Image img = rasterizer.GetPage(72, 72, 1);
pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
pictureBox1.Image = img;
}
// Declare point variables for the user defined rectangle indicating the locatoin of the PDF to be searched...
Point first = new Point();
Point last = new Point();
// The first point is collected on the MouseDown event
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
first = e.Location;
}
// The second point is collected on the mouse down event. Points to be applied to the PDF are adjusted based on the rotation of the PDF.
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
last = e.Location;
if (rotation == 0)
{
llx = first.X;
lly = hight - first.Y;
urx = last.X;
ury = hight - last.Y;
} else if(rotation == 90) {
llx = first.Y;
lly = first.X;
urx = last.Y;
ury = last.X;
}
gettext();
}
// the original PDF is opened with Itext and the text is extracted from t he defined location...
private void gettext()
{
PdfReader reader = new PdfReader(fileName);
iTextSharp.text.Rectangle rect = new iTextSharp.text.Rectangle(llx, lly, urx, ury);
RenderFilter[] renderfilter = new RenderFilter[1];
renderfilter[0] = new RegionTextRenderFilter(rect);
ITextExtractionStrategy textExtractionStrategy = new FilteredTextRenderListener(new LocationTextExtractionStrategy(), renderfilter);
string text = PdfTextExtractor.GetTextFromPage(reader, 1, textExtractionStrategy);
iTextSharp.text.Rectangle mediabox = reader.GetPageSizeWithRotation(1);
MessageBox.Show("", text+" "+mediabox+" "+first+" "+last);
}
// Image Controls....
}
}

How do I change the font size of JFace table data

I am using a Jface table viewer with OwnerDrawLabelProvider for multiline rows, how do I change the font style/size?
Basically you just need to get the font you want to use and set in the event GC in the measure and paint methods.
This might be something like:
private static final int TEXT_MARGIN = 3;
#Override
protected void measure(Event event, Object element)
{
String text = ... get the text
Font font = JFaceResources.getFont(JFaceResources.HEADER_FONT);
event.gc.setFont(font);
Point size = event.gc.textExtent(text);
event.width = size.x + 2 * TEXT_MARGIN;
event.height = Math.max(event.height, size.y + 2 * TEXT_MARGIN);
}
#Override
protected void paint(Event event, Object element)
{
String text = ... get the text
Font font = JFaceResources.getFont(JFaceResources.HEADER_FONT);
event.gc.setFont(font);
event.gc.drawText(text, event.x + TEXT_MARGIN, event.y + TEXT_MARGIN, true);
}
Here I am using JFaceResources.getFont to get one of the existing JFace fonts. You can also create your own font - but be sure to do this only once do not create it every time measure or paint is called.

How to get the path of an Image Field in a pdf form, in Adobe?

I am creating a PDF form using adobe reader. I have added an image field and a text box. The text box is read-only and I want to populate the text box with the path of the image selected by the end-user, in the image field. Following is my code:
var one = this.getField("Image1");
var two = this.getField("Text1");
two.value='The Path';
The above code runs normally but I can't figure out as to what to write instead of 'The Path', to get the actual path of the image selected by the end-user.
P.S.
On the Image1 button there are 2 actions:
Mouse Up(execute Js)
event.target.buttonImportIcon();
On Blur(execute Js)
var one = this.getField("Image1");
var two = this.getField("Text1");
two.value='The Path';
If I am understanding your request correctly... Assuming that Image1 is a button field and Text1 is a text field and you want the selected image file to appear as the button icon, the code would be as follows...
var one = this.getField("Image1");
var two = this.getField("Text1");
var doc = app.browseForDoc(); // Allows the user to browse for a file
var docPath = doc.cPath; // gets the file path of the selected file
one.buttonImportIcon(docPath); // uses the selected path to import the image as the "normal" or "up" button icon
two.value = docPath; // set the value of the text field to the selected device independent path

Accessing saved image on a Windows Phone

I am creating a camera app for the Windows Phone but when I want to retrieve my saved photo as a BitmapImage, nothing seems to work. I am using IsolatedStorageSettings to save the path of the images as shown below:
Picture p = mediaLibrary.SavePictureToCameraRoll(fileName, e.ImageStream);
if (!settings.Contains("lastImageTaken"))
{
//GetPath() requires using Microsoft.Xna.Framework.Media.PhoneExtensions;
settings.Add("lastImageTaken", p.GetPath());
}
else
{
settings["lastImageTaken"] = p.GetPath();
}
settings.Save();
then once the app starts up, I try to retrieve that last photo taken as shown below:
lastImageTaken = IsolatedStorageSettings.ApplicationSettings["lastImageTaken"] as string;
Uri uri = new System.Uri(lastImageTaken, UriKind.RelativeOrAbsolute);
BitmapImage image = new BitmapImage(uri);
previouseImage.Source = image;
if (image.PixelWidth < 1)
debugText.Text += " FAILED";
I have also tried something like this:
Uri uri = new System.Uri("file:///" + lastImageTaken.Replace("\\", "/"), UriKind.RelativeOrAbsolute);
BitmapImage image = new BitmapImage(uri);
but nothing seems to display the image. The width of to image always is shown as 0 which displays a "FAILED" text on a debug text. lastImageTaken is shown as C:\Data\Users\Public\Camera Roll\SMCA_jpg.jpg
I have also added the capabilities of ID_CAP_MEDIALIB_PHOTO
It seems that you are saving the image to CameraRoll, but trying to retrieve image from IsolatedStorage. Those are two different storage areas, and they are accessed differently.
In order to save an image to IsolatedStorage you need to replace this :
library.SavePictureToCameraRoll(fileName, e.ImageStream);
with this :
using (IsolatedStorageFile isStore = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream targetStream = isStore.OpenFile(fileName, FileMode.Create, FileAccess.Write))
{
// Initialize the buffer for 4KB disk pages.
byte[] readBuffer = new byte[4096];
int bytesRead = -1;
// Copy the image to the local folder.
while ((bytesRead = e.ImageStream.Read(readBuffer, 0, readBuffer.Length)) > 0)
{
targetStream.Write(readBuffer, 0, bytesRead);
}
}
}
Then access the image the same way you've described in your original post.
Source : http://msdn.microsoft.com/en-us/library/windows/apps/hh202956(v=vs.105).aspx#BKMK_SavingToTheMediaLibraryAndIsolatedStorage