Brother Label printer printing Dark image - image-processing

I am using Label printer QL-700 from Brother and trying to print a label with image on it.
I am using the following test code :
string templatePath = TEMPLATE_DIRECTORY;
// None decoration frame
if (cmbTemplate.SelectedIndex == 0)
{
templatePath += TEMPLATE_SIMPLE;
}
// Decoration frame
else
{
templatePath += TEMPLATE_FRAME;
}
bpac.DocumentClass doc = new DocumentClass();
if (doc.Open(templatePath) != false)
{
try
{
//doc.GetObject("objCompany").Text = txtCompany.Text;
//doc.GetObject("objName").Text = txtName.Text;
// doc.SetMediaById(doc.Printer.GetMediaId(), true);
doc.SetPrinter("Brother QL-700", true);
bpac.Object ob = doc.GetObject("Photo");
//ob.SetData(0, #"C:\Photo\635466380534236711.png", 4);
doc.StartPrint("", PrintOptionConstants.bpoDefault);
doc.PrintOut(1, PrintOptionConstants.bpoDefault);
doc.EndPrint();
doc.Close();
}
catch(Exception ex)
{
}
}
I have a template and at the runtime I set the image. But the thing is its printing the image too dark. Can anybody suggest how can I fix it ?
I tried
- Changing the brightness of the Printer Properties
- Tried changing the Brightness of the image in the Default image on the Template.
Nothing worked.
Anybody, anything - please suggest.

Related

Images shown rotated in Codename One

I'm developing a Codename One app for iOS.
I gave the user the option to take pictures or to load them from the gallery of the device. After that, the app shows pictures in labels (encapsulated in a BoxLayout).
When I take pictures in portrait mode, everything perfectly works, but when I take pictures in landscape mode, that picture is shown rotated (a 90° rotation).
Here is the code:
String filePath = Capture.capturePhoto();
if (filePath != null) {
try {
Image img = Image.createImage(filePath);
if (img != null){
setImageToContainer(img);
}
}
catch (IOException err) {
ToastBar.showErrorMessage("Problemi con le immagini: " + err.getMessage());
completeImageName = null;
fileImageName = null;
}
}
private void setImageToContainer(Image img){
Label imgLbl = new Label();
Style s = UIManager.getInstance().getComponentStyle("Button");
FontImage p = FontImage.createMaterial(FontImage.MATERIAL_PORTRAIT, s);
EncodedImage placeholder = EncodedImage.createFromImage(p.scaled(p.getWidth() * 3, p.getHeight() * 4), false);
imgLbl.setIcon(placeholder);
list.add(imgLbl);
//Scalo l'immagine
if(img.getWidth() > imgLbl.getParent().getWidth())
img = img.scaledWidth(imgLbl.getParent().getWidth());
if(img.getHeight()> imgLbl.getParent().getHeight())
img = img.scaledHeight(imgLbl.getParent().getHeight());
imgLbl.setIcon(img);
list.repaint();
}
Reading that answer, I understood Image.createImage(filePathToImage) method takes in account EXIF data, in order to properly rotate the image.
How can I solve my problem? Is there a way to get EXIF data?

JFX Print API, printing to a Brother QL 720NW

I am implementing the JFX Printing API using Brother QL720NW Printer with the 62mm Wide Paper size, for some reason I get the "Bad Margins" Exception. How do I go round this here is the code:
try
{
Printer printer = Printer.getDefaultPrinter();
Paper photo = PrintHelper.createPaper("LabelPrinter", 62.0, 89.8, Units.MM);
PageLayout pageLayout = printer.createPageLayout(photo, PageOrientation.LANDSCAPE, Printer.MarginType.HARDWARE_MINIMUM);
PrinterAttributes attr = printer.getPrinterAttributes();
PrinterJob job = PrinterJob.createPrinterJob();
double scaleX = pageLayout.getPrintableWidth() / node.getBoundsInParent().getWidth();
double scaleY = pageLayout.getPrintableHeight() / node.getBoundsInParent().getHeight();
Scale scale = new Scale(scaleX, scaleY);
node.getTransforms().add(scale);
JobSettings jobsettings = job.getJobSettings();
jobsettings.setPageLayout(pageLayout);
if (job != null) {
boolean success = job.printPage(node);
if (success) {
job.endJob();
}
}
node.getTransforms().remove(scale);
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
The Node used to Print is a simple Label that I am using for testing purposes. After I get a print out then I will implement a bigger node to print exact parameters required.
Let me know if this code is ok. or needs some refactoring.
thanks in advance
The Answer was in the printing settings of the actual printer for anyone seeking the answer here is a link for a solution:
https://forum.sambapos.com/t/how-to-change-the-printer-size-paper/10442/11

Android Attach Image between text with SpannableStringBuilder

Sory for my english. I want attach image from gallery and show in edit text with SpannableStringBuilder. I have success for get Image Path from Gallery. After picture selected, Picture Show. But, for the second attach image picture not show and first image attach became a text. any one give me solution ? big thanks.
this is my code:
private void IntentPict() {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select File"),MY_INTENT_CLICK);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK){
if (requestCode == MY_INTENT_CLICK){
if (null == data) return;
String selectedImagePath;
Uri selectedImageUri = data.getData();
//there is no problem with get path
selectedImagePath = ImageFilePath.getPath(getApplicationContext(), selectedImageUri);
//pathImag is ListArray<String>
pathImg.add(selectedImagePath);
addImageBetweentext(pathImg);
}
}
}
private void addImageBetweentext(ArrayList<String> listPath) {
SpannableStringBuilder ssb = new SpannableStringBuilder();
for(int i=0;i<listPath.size();i++){
String path = listPath.get(i);
Drawable drawable = Drawable.createFromPath(path);
drawable.setBounds(0, 0, 400, 400);
ssb.append(mBodyText+"\n");
ssb.setSpan(new ImageSpan(drawable), ssb.length()-(path.length()+1),
ssb.length()-1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
mBodyText.setText(ssb);
}
Here's something that should work. I am loading resource drawables instead, just because it was quicker for me to validate, but I tried to keep as mich as possible for your original flow and variable names:
Drawable[] drawables = new Drawable[2];
drawables[0] = getResources().getDrawable(R.drawable.img1);
drawables[1] = getResources().getDrawable(R.drawable.img2);
SpannableStringBuilder ssb = new SpannableStringBuilder();
for (int i = 0; i < drawables.length; i++) {
Drawable drawable = drawables[i];
drawable.setBounds(0, 0, 400, 400);
String newStr = drawable.toString() + "\n";
ssb.append(newStr);
ssb.setSpan(
new ImageSpan(drawable),
ssb.length() - newStr.length(),
ssb.length() - "\n".length(),
Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
}
mBodyText.setText(ssb);
Long story short: the start position for the incremental builder needs to be set to the current length of it, minus what you just added.

How to write to file (encode) modified camera frames in Windows Phone 8

I have custom an camera app in Windows Phone 8. I need add a watermark image to each frame from camera capture and then record to a video.
I can customise each frame from the preview using the following code:
int[] pixelData = new int[(int)(camera.PreviewResolution.Width * camera.PreviewResolution.Height)];
camera.GetPreviewBufferArgb32(pixelData);
return pixelData;
and write it back to the preview.
my problem is that while I can show the frames on the screen while the user is recording a movie using the camera I cant find a working solution for WP8 to encode the frames and audio to save to a file.
I already tried opencv,libav and others without success,
if anyone can point me to the right direction it would be greatly appreciated.
You can do it like this.
private void GetCameraPicture_Click(object sender, RoutedEventArgs e)
{
Microsoft.Phone.Tasks.CameraCaptureTask cameraCaptureTask = new Microsoft.Phone.Tasks.CameraCaptureTask();
cameraCaptureTask.Completed += cct_Completed;
cameraCaptureTask.Show();
}
try
{
if (e.TaskResult == Microsoft.Phone.Tasks.TaskResult.OK)
{
var imageStream = e.ChosenPhoto;
var name = e.OriginalFileName;
using (MemoryStream mem = new MemoryStream())
{
TextBlock tb = new TextBlock() { Text = DateTime.Now.ToString("dd MMM yyyy, HH:mm"), Foreground = new SolidColorBrush(Color.FromArgb(128, 0, 0, 0)), FontSize = 40 };
BitmapImage finalImage = new BitmapImage();
finalImage.SetSource(imageStream);
WriteableBitmap wbFinal = new WriteableBitmap(finalImage);
wbFinal.Render(tb, null);
wbFinal.Invalidate();
wbFinal.SaveJpeg(mem, wbFinal.PixelWidth, wbFinal.PixelHeight, 0, 100);
mem.Seek(0, System.IO.SeekOrigin.Begin);
MediaLibrary lib = new MediaLibrary();
lib.SavePictureToCameraRoll("Copy" + name, mem.ToArray());
}
}
}
catch (Exception exp) { MessageBox.Show(exp.Message); }
Hope it may help you.

How to get the image size of an image file in monotouch without loading it?

How to get the image size of an image file in monotouch without loading it in memory?
I tried to use CGImageSource from the MonoTouch.ImageIO namespace, as indicated in the Apple documentation and in this blog post:
oleb.net
But this code doesn't work:
public Size GetImageSizeFromImageFile (string image_file_path)
{
CGImageSource imageSource = CGImageSource.FromUrl (NSUrl.FromFilename (image_file_path));
if (imageSource == null) {
// Error loading image
Console.WriteLine ("Error loading image info for file: " + image_file_path);
return Size.Empty;
}
NSDictionary imageProperties = new NSDictionary ();
imageSource.CopyProperties (imageProperties, 0);
int width = (int)imageProperties.ValueForKey (new NSString ("kCGImagePropertyPixelWidth"));
int height = (int)imageProperties.ValueForKey (new NSString ("kCGImagePropertyPixelHeight"));
Console.WriteLine (#"Image " + image_file_path + " dimensions: " + width + " x " + height+" px");
imageProperties.Dispose ();
return new Size(width, height);
}
Casting to strings doesn't make any difference, the field returns empty.
Any help is appreciated, thanks!
The latest MonoTouch releases makes it a lot easier to get the image properties using the new GetProperties method. E.g.
using (var src = CGImageSource.FromUrl (NSUrl.FromFilename (filename))) {
CGImageOptions options = new CGImageOptions () { ShouldCache = false };
// do not forget the '0' image index or you won't get what you're looking for!
using (var p = src.GetProperties (options, 0)) {
Console.WriteLine ("{0}x{1}", p.PixelWidth, p.PixelHeight);
}
}
Looks like this is a bug in Mono Touch. I tested the code in XCode with the same image in Mono Touch and it worked in XCode.
In Mono Touch after calling the imageSource.CopyProperties(imageProperties,0) imageProperties.Keys Count is 0
So you should create a bug report at bugzilla.xamarin.com/

Resources