I am currently trying to load a gif into a processing sketch from a url. I am using the gifAnimation library and when I load a gif stored on my computer it works fine. I just cant seem to get it when I load from url, nothing shows up. Currently I can load the first frame using default Processing like this:
webGif= loadImage(url, "gif");
image(webGif,0,0,720,720);
If I try and load a gif using the library from the url
webGif= new Gif(this, url);
image (webGif, 0 , 0);
webGif.loop();
It doesn't load anything and my program freezes.
Loading a gif from URL seems to work as expected:
import gifAnimation.*;
Gif loopingGif;
public void setup() {
size(400, 200);
frameRate(100);
loopingGif = new Gif(this, "https://s-media-cache-ak0.pinimg.com/originals/1f/d4/83/1fd4831252c28010546e872d5b85bb70.gif");
loopingGif.loop();
}
void draw() {
background(255 / (float)height * mouseY);
image(loopingGif, 10, height / 2 - loopingGif.height / 2);
}
tested with gifAnimation 3.1 using Processing 3.2.3
Also double check the URL is valid and the file is a valid gif, before checking Processing and library versions.
Related
I am pretty new to Unity, so this might be an easy one.
I am trying to load and image from a URL an into an image in my application. In my application I have many different images, but for some reason all the images change to the image loaded from my url.
I have made a component called LoadImage and added it only to the one image I want to change. My code for loading the image looks like this:
public class LoadImage : MonoBehaviour
{
public Image img;
// Use this for initialization
void Start ()
{
DownloadViaURL();
}
void DownloadViaURL()
{
Debug.Log("Called DownloadViaURL");
FirebaseDatabase.DefaultInstance
.GetReference("Child1").Child("Child2").Child("ImageURL")
.GetValueAsync().ContinueWith(task =>
{
Debug.Log("Default Instance entered");
if (task.IsFaulted)
{
Debug.Log("Error retrieving data from server");
}
else if (task.IsCompleted)
{
DataSnapshot snapshot = task.Result;
string data_URL = snapshot.GetValue(true).ToString();
//Start coroutine to download image
StartCoroutine(AccessURL(data_URL));
}
});
}
IEnumerator AccessURL(string url)
{
using (WWW www = new WWW(url))
{
yield return www;
www.LoadImageIntoTexture(img.mainTexture as Texture2D);
Debug.Log("Texture URL: " + www.url);
}
}
}
And I have then added the image as the public Image img;
Can anyone tell my why unity load the image into all imageviews in my application instead of just the one?
You say
I have many different images,
but I guess you mean different Image components where you very probably referenced the same texture from your assets multiple times
So what your code actually does is overwriting whatever texture asset is referenced by your image => it is also changed in all other images/materials etc that reference the same texture asset.
You should rather create a new texture, load the data into it and change the image's texture reference:
// Create new texture
// Size values don't matter because texture will be overwritten
var newTexture = new Texture2D(2,2);
// Load image I new texture
www.LoadImageToTexture(newTexture);
// Use the reference to that new texture
img.mainTexture = newTexture;
Currently I was working on a UWP application. I captured the ink strokes into an image. Now the same image need to display as a preview. So the original image need to re-size to shorter size or thumbnail need to be generated.
I tried with using the larger image directly as a source to shorter sized image canvas --> not working (visible image quality degrade)
I also used Transcode of image programatically --> same result as above
I test with the same image. Re-sized the same image using paint, and there interestingly the quality of the re-sized image remains good.
Please help me to solve the issue I faced.
I not sure, need to see some code, but could be how you are saving the image? Here an example:
try
{
Windows.Storage.Pickers.FileSavePicker save = new Windows.Storage.Pickers.FileSavePicker();
save.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.Desktop;
save.DefaultFileExtension = “.png”;
save.FileTypeChoices.Add(“PNG”, new string[] { “.png” });
StorageFile filesave = await save.PickSaveFileAsync();
using (IOutputStream fileStream = await filesave.OpenAsync(FileAccessMode.ReadWrite))
{
if (fileStream != null)
{
await m_InkManager.SaveAsync(fileStream);
}
}
}
catch (Exception ex)
{
var dialog = new MessageDialog(ex.Message);
dialog.ShowAsync();
}
I will post a great tutorial of Can Bilgin that explain perfectly all about inking.
Drawing / Inking API in WinRT (C#) – I
Drawing / Inking API in WinRT (C#) – II
Drawing / Inking API in WinRT (C#) – III
We have implemented FineUploader and are running into an issue with some images that our clients are uploading. For large image files with a repeated canvas texture, FineUploader resizes the images fine, but a moiré is introduced into the final image. Is there any way to help prevent this from happening?
Here is an example:
http://205.238.27.187/Hagan/site/Artwork-Detail.cfm?ArtistsID=1110&NewID=10709
This is not because of the quality setting.
Most browsers use linear interpolation rather than bicubic when resizing images.
Fine Uploader uses the default browser image resizing algorithm.
The solution I've found is limby-resize. It uses pixel averaging/a much better resizing algo but is more CPU intensive. There is a link to a demo in the readme file. (Fine Uploader uses the "Crappy" method)
In megapix-image.js around line #168 or in the fine uploader source code,
Replace:
else {
ctx.drawImage(img, 0, 0, width, height);
}
canvas.qqImageRendered && canvas.qqImageRendered();
With:
else {
var tmpCanvas = document.createElement("canvas");
tmpCanvas.width = iw;
tmpCanvas.height = ih;
var tmpCtx = tmpCanvas.getContext("2d");
tmpCtx.drawImage(img, 0, 0);
canvasResize(tmpCanvas, canvas, function () {
alert("Image resized by limby-resize");
canvas.qqImageRendered && canvas.qqImageRendered();
});
}
And include limby-resize's canvas_resize.js before the fine uploader js file in your HTML.
I use Helvetica font and 14 px size for text. The problem is that if a page does not have any image on it the text is very clear, but in a page with at least 1 image the text is getting a little bold. You can see what I mean in images below:
* Without image on page
* With image on page
The correct font is the one that appear in picture #1. How to make all pages have the same font even if the page contains an image or not?
Thanks.
Sample code:
Document document = new Document(PageSize.LETTER);
document.SetMargins(docMargin, docMargin, docMargin, 25);
writer = PdfWriter.GetInstance(document, new FileStream(filename, FileMode.Create));
document.Open();
Font defaultFont = FontFactory.GetFont("Helvetica", 7.8, Font.NORMAL, new Color(75, 75, 75));
document.Add(new Paragraph("Lorem ipsum lorem ipsum lorem ipsum", defaultFont));
document.Add(Chunk.NEWLINE);
Image img = Image.GetInstance("my png image path");
document.Add(img);
document.Close();
I was finally able to reproduce your problem. The first PNG that I tested with which didn't reproduce your problem I created from Photoshop and used the Save For Web command. The second PNG that I tested and was able to reproduce your problem I created from MSPAINT.EXE. I tried various combinations within Save For Web and none of them have the same problem as Paint.
According to this thread from the official iText mailing list it appears to be something about the color profile of the image.
What are you seeing is the impact of newly placed transparency into a
PDF that had not previously contained it, when consideration isn't
given for the blending colorspace of the final output document.
You have an RGB document that upon adding transparency is forced into
CMYK due to lack of explicit blending space. If you were to specify
RGB as your explicit blending space at the same time you added your
transparency, all would be well.
One thing they recommend is setting the following property on your PdfWriter before adding anything:
writer.RgbTransparencyBlending = true;
When I do it I still see a very minor shift but no where near as pronounced as without it.
This isn't an answer, I just need to be able to post code.
I'm unable to reproduce your results but if I were to guess it has something to do with your PDF renderer. You can confirm this by zooming in on the text, does it look the same when zoomed in? If so, that's your renderer trying to apply visual hints to a print document. If not, can you post a simplified version of your code that does this? Does this do this for all images or just one specific one? How are you creating your text, with Paragraphs, Tables, HTML parsing or something else? What version of iTextSharp are you using?
Below is a full working WinForms C# 2010 targeting iTextSharp 5.1.2.0 that creates a two page PDF. The first page has just text and the second page has text followed by an image loaded from the desktop. On my machine, using Adobe Acrobat Pro 9.1.3 I don't see any difference in fonts when I view it on screen.
using System;
using System.IO;
using System.Windows.Forms;
using iTextSharp.text;
using iTextSharp.text.pdf;
namespace WindowsFormsApplication1 {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e) {
string pdfFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Test.pdf");
string imgFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Test.png");
using (FileStream fs = new FileStream(pdfFile, FileMode.Create, FileAccess.Write, FileShare.None)) {
using (Document doc = new Document(PageSize.LETTER)) {
using (PdfWriter writer = PdfWriter.GetInstance(doc, fs)) {
doc.Open();
BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED);
iTextSharp.text.Font f = new iTextSharp.text.Font(bf, 14);
doc.NewPage();
doc.Add(new Paragraph("This is a test", f));
doc.NewPage();
doc.Add(new Paragraph("This is a test", f));
iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(imgFile);
img.ScaleAbsolute(100, 100);
doc.Add(img);
doc.Close();
}
}
}
this.Close();
}
}
}
I am trying to embed an animated GIF image into a wxWidgets C++ program. I am able to load the image from file and display it like so:
wxAnimationCtrl *an = new wxAnimationCtrl(this, wxID_ANY, wxAnimation(wxT("image.gif"), wxANIMATION_TYPE_ANY), wxPoint(150,0));
an->Play();
But I would rather have the GIF image in my resource.rc file, so that it is compiled into the executable. How would I do this?
You can try to use wxMSWResources or wxLoadUserResource function, load GIF resource to memory, then obtain wxMemoryInputStream and then use wxAnimation::Load() and pass that input stream to that function
m_ani = new wxAnimationCtrl();
const void* data = NULL;
size_t outLen = 0;
// load the icon directory resource
if ( !wxLoadUserResource(&data, &outLen, "ID_WAIT", RT_RCDATA) )
{
wxLogError(_("Failed to load icons from resource"));
}
else
{
wxMemoryInputStream stream(data, outLen);
if (m_ani->Load(stream)) m_ani->Play();
}