libgdx assetmanager texture loading - loading

here is my code:-
manager = new AssetManager();
fps =new FPSLogger();
Resolution[] resolutions = {new Resolution(320, 480, ".320480"), new Resolution(480, 800, ".480800"),
new Resolution(480, 856, ".480854")};
ResolutionFileResolver resolver = new ResolutionFileResolver(new InternalFileHandleResolver(), resolutions);
manager.setLoader(Texture.class, new TextureLoader(resolver));
manager.load( "images/flash.png" , Texture.class);
Texture.setAssetManager(manager);
tex = manager.get("images/flash.png" ,Texture.class);
tex = new Texture(Gdx.files.internal("images/a.png"));
flsh = new Texture(Gdx.files.internal("images/flash.png"));
tex2 = new Texture(Gdx.files.internal("images/space.jpg"));
ear = new Texture(Gdx.files.internal("images/earth.png"));
newgame=new Texture(Gdx.files.internal("images/shockwave.png"));
and the error that shows up is
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Asset not loaded: images/flash.png
at com.badlogic.gdx.assets.AssetManager.get(AssetManager.java:119)
at main.assets.loading(assets.java:53)
at main.game.create(game.java:43)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:132)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:112)
my image layout is
/main(project name)/assets/images/a.png
please help me rectify this error

use manager.finishloading() in between manager.load() and manager.get statements.

Related

Urhosharp Material.FromImage not woking with some jpg files

I'm using Xamarin.Forms with Urhosharp in my project. I'm tring to set a matrial from an image on a sphere, everything is OK in my Android project but in iOS project, when I set material from some jpg files it doesn't work and all I get is a black screen.
Here is the jpg that works correctly:
And here is the other one that doesn't:
This is my code:
var scene = new Scene();
scene.CreateComponent<Octree>();
// Node (Rotation and Position)
var node = scene.CreateChild("room");
node.Position = new Vector3(0, 0, 0);
//node.Rotation = new Quaternion(10, 60, 10);
node.SetScale(1f);
// Model
var modelObject = node.CreateComponent<StaticModel>();
modelObject.Model = ResourceCache.GetModel("CustomModels/SmoothSphere.mdl");
var zoneNode = scene.CreateChild("Zone");
var zone = zoneNode.CreateComponent<Zone>();
zone.SetBoundingBox(new BoundingBox(-300.0f, 300.0f));
zone.AmbientColor = new Color(1f, 1f, 1f);
//get image from byte[]
//var url = "http://www.wsj.com/public/resources/media/0524yosemite_1300R.jpg";
//var wc = new WebClient() { Encoding = Encoding.UTF8 };
//var mb = new MemoryBuffer(wc.DownloadData(new Uri(url)));
var mb = new MemoryBuffer(PanoramaBuffer.PanoramaByteArray);
var image = new Image(Context) { Name = "MyImage" };
image.Load(mb);
//or from resource
//var image = ResourceCache.GetImage("Textures/grave.jpg");
var isFliped = image.FlipHorizontal();
if (!isFliped)
{
throw new Exception("Unsuccessful flip");
}
var m = Material.FromImage("1.jpg");
m.SetTechnique(0, CoreAssets.Techniques.DiffNormal, 0, 0);
m.CullMode = CullMode.Cw;
//m.SetUVTransform(Vector2.Zero, 0, 0);
modelObject.SetMaterial(m);
// Camera
var cameraNode = scene.CreateChild("camera");
_camera = cameraNode.CreateComponent<Camera>();
_camera.Fov = 75.8f;
_initialZoom = _camera.Zoom;
// Viewport
Renderer.SetViewport(0, new Viewport(scene, _camera, null));
I already tried to change compression level, ICCC profile and ...
I asked the same question in forums.xamarin.com and someone answered the question and I'll share it here :
In iOS every texture needs to have a power of two resolution, like 256 x 256 or 1024 x 512. Check if that is the issue. Additionally check that your using the latest UrhoSharp version.
Also make sure that the image is set as BundleResource in the iOS project.

Missing font resource dictionary after stamping text in iText 7 [duplicate]

This question already has an answer here:
Why font is not being embedded to the PDF using content stream before in Itext7?
(1 answer)
Closed 4 years ago.
I have an existing PDF that doesn't contain any fonts (image only). I want to stamp some additional text onto the first page using low level canvas operations. When I do this in iText 7, the resulting PDF is missing the Fonts resource dictionary entry (which results in an NPE when parsing the resulting file).
Do I have to do something besides canvas.setFontAndSize() to get the font resource to get added to the output?
Here's a unit test that recreates the issue:
public class CheckFontResourceInclusion {
#Test
public void test() throws Exception {
// create a document to stamp
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try(PdfDocument doc = new PdfDocument(new PdfWriter(baos))){
doc.addNewPage();
}
// stamp it
StampingProperties stampProps = new StampingProperties();
PdfFont font = PdfFontFactory.createFont();
ByteArrayOutputStream resultStream = new ByteArrayOutputStream();
try(PdfDocument doc = new PdfDocument(new PdfReader(new ByteArrayInputStream(baos.toByteArray())), new PdfWriter(resultStream), stampProps)){
PdfPage page = doc.getPage(1);
PdfCanvas canvas = new PdfCanvas(page.newContentStreamAfter(), new PdfResources(), doc);
canvas.beginText();
canvas.setTextRenderingMode(2);
canvas.setFontAndSize(font, 42);
canvas.setTextMatrix(1, 0, 0, -1, 100, 100);
canvas.showText("TEXT TO STAMP");
canvas.endText();
}
// parse text
try(PdfDocument doc = new PdfDocument(new PdfReader(new ByteArrayInputStream(resultStream.toByteArray())))){
LocationTextExtractionStrategy strat = new LocationTextExtractionStrategy();
PdfCanvasProcessor processor = new PdfCanvasProcessor(strat);
processor.processPageContent(doc.getPage(1));
Assert.assertEquals("TEXT TO STAMP", strat.getResultantText());
}
}
}
Here's the resulting failure:
java.lang.NullPointerException
at com.itextpdf.kernel.pdf.canvas.parser.PdfCanvasProcessor$SetTextFontOperator.invoke(PdfCanvasProcessor.java:811)
at com.itextpdf.kernel.pdf.canvas.parser.PdfCanvasProcessor.invokeOperator(PdfCanvasProcessor.java:456)
at com.itextpdf.kernel.pdf.canvas.parser.PdfCanvasProcessor.processContent(PdfCanvasProcessor.java:285)
at com.itextpdf.kernel.pdf.canvas.parser.PdfCanvasProcessor.processPageContent(PdfCanvasProcessor.java:306)
at
The error is the same as in this earlier question: You use a throw-away resources object, so the font resource is missing in the result.
You can fix this by using the actual page resources. Simply replace
PdfCanvas canvas = new PdfCanvas(page.newContentStreamAfter(), new PdfResources(), doc);
by
PdfCanvas canvas = new PdfCanvas(page.newContentStreamAfter(), page.getResources(), doc);

iTextSharp : Cannot attach PageEvent on a PdfSmartCopy writer

This code using ItextSharp 5.5.10:
var msOutput = new MemoryStream();
var document = new Document(PageSize.A4, 0, 0, 0, 20);
var writer = new PdfSmartCopy(document, msOutput);
writer.PageEvent = new MyHeaderFooterEvents();
Throws "Operation is not valid due to the current state of the object." when assigning the "writer.PageEvent" (also fails when doing a parameterless new Document()).
When this code works perfectly:
var outputStream = new MemoryStream();
var document = new Document(PageSize.A4, leftMargin, rightMargin, topMargin, bottomMargin);
var writer = PdfWriter.GetInstance(document, outputStream);
writer.PageEvent = new MyHeaderFooterEvents();
Any idea ?
The Pdf[Smart]Copy classes are intended for read-only usage. It's documented in the raw source code:
/// Setting page events isn't possible with Pdf(Smart)Copy.
/// Use the PageStamp class if you want to add content to copied pages.
Note to the iText development team - if XML Documentation Comments using the <summary> tag are used instead of the current style, comments will show up in Visual Studio IntelliSense.

Cannot get form designer in Visual Studio to load a form

Designer error screen shot
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainWindow));
this.TC_mainControl = new System.Windows.Forms.TabControl();
this.TP_Payment = new System.Windows.Forms.TabPage();
this.TP_Manage = new System.Windows.Forms.TabPage();
this.TP_Batch = new System.Windows.Forms.TabPage();
this.TP_Report = new System.Windows.Forms.TabPage();
this.TP_COMM = new System.Windows.Forms.TabPage();
this.TP_LOG = new System.Windows.Forms.TabPage();
this.pay_sample1 = new POSLinkTest.Payment();
this.man_sample1 = new POSLinkTest.Manage();
this.batch_sample1 = new POSLinkTest.Batch();
this.report_sample1 = new POSLinkTest.Report();
this.comm_sample1 = new POSLinkTest.Commset();
this.log_sample1 = new POSLinkTest.LogSetting();
this.TC_mainControl.SuspendLayout();
this.SuspendLayout();
//
// TC_mainControl
//
this.TC_mainControl.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.TC_mainControl.Controls.Add(this.TP_Payment);
this.TC_mainControl.Controls.Add(this.TP_Manage);
this.TC_mainControl.Controls.Add(this.TP_Batch);
this.TC_mainControl.Controls.Add(this.TP_Report);
this.TC_mainControl.Controls.Add(this.TP_COMM);
this.TC_mainControl.Controls.Add(this.TP_LOG);
this.TC_mainControl.ItemSize = new System.Drawing.Size(148, 20);
this.TC_mainControl.Location = new System.Drawing.Point(0, 0);
this.TC_mainControl.Multiline = true;
this.TC_mainControl.Name = "TC_mainControl";
this.TC_mainControl.Padding = new System.Drawing.Point(6, 0);
this.TC_mainControl.SelectedIndex = 0;
this.TC_mainControl.Size = new System.Drawing.Size(1000, 600);
this.TC_mainControl.SizeMode = System.Windows.Forms.TabSizeMode.Fixed;
this.TC_mainControl.TabIndex = 0;
this.TC_mainControl.SelectedIndexChanged += new System.EventHandler(this.TC_mainControl_SelectedIndexChanged);
//
// TP_Payment
//
this.TP_Payment.AutoScroll = true;
The solution builds without any errors? Why will the form not load into the designer, yet it will compile?
Using Visual Studio 2015, Windows 10 64 bit
I can upload the project if necessary, it is just Sample Project.
The error message on the screenshot says that types from POSLinkTest namespace are not available. So probably add a reference to that namespace.
For future use there are some other potential problems with the designer code:
Removed parameterless constructor. Solution: add the parameterless constructor back as a privet constructor to prevent others from using it but having it available for the designer
Design time code (like OnPaint handler) that references resource not available at that time (like db connection). Solution: try not to handle that in UI related code.

Text on image not appearing, in preview handler vs2005 .net2

hi i am trying to show image of my file in previwew pane i am able to display the image of my file but i am stuck in the part where i need write some text on the image before adding it to preview pane.
// create an image object, using the filename we just retrieved
String strImageFile = file.FullName.Substring(0, file.FullName.Length - 3) + "jpg";
//file.CreationTime.ToString();
//------------------------------------
//Load the Image to be written on.
Bitmap bitMapImage = new System.Drawing.Bitmap(strImageFile);
Graphics graphicImage = Graphics.FromImage(bitMapImage);
graphicImage.SmoothingMode = SmoothingMode.AntiAlias;
graphicImage.DrawString("AWESOME!", new Font("Arial", 20, FontStyle.Bold), Brushes.Black, new Point(100, 250));
//Save the new image to the response output stream.
bitMapImage.Save(strImageFile, ImageFormat.Png);
//------------------------------------
// Create a picture box control
PictureBox p = new PictureBox();
p.Dock = DockStyle.Fill;
p.Image = bitMapImage;
//p.Image = System.Drawing.Image.FromFile(strImageFile);
p.SizeMode = PictureBoxSizeMode.Zoom;
Controls.Add(p);
//graphicImage.Dispose();
//bitMapImage.Dispose();
Only the image appease and not the text, any idea what i might be missing.
thanks
Narrow it down too:
PictureBox p = new PictureBox();
// create an image object, using the filename we just retrieved
String strImageFile = file.FullName.Substring(0, file.FullName.Length - 3) + "jpg";
Bitmap bitMapImage = new System.Drawing.Bitmap(strImageFile);
Graphics graphicImage = Graphics.FromImage(bitMapImage);
graphicImage.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
graphicImage.DrawString("AWESOME!", new Font("Arial", 20, FontStyle.Bold), Brushes.Black, new Point(100, 250));
graphicImage.DrawImage(bitMapImage, new Rectangle(205, 0, 200, 200), 0, 0, bitMapImage.Width, bitMapImage.Height, GraphicsUnit.Pixel);
p.Image = bitMapImage;
p.Dock = DockStyle.Fill;
Controls.Add(p);
But i am getting an exception on

Resources