Working with images when uploading in Adobe Flex - image

I'm beginner with Flex and I already have a hard task to develop, so I could use some help! :)
What I have to do is upload some images to a server, which is OK, but before uploading I must downsize this images by reducing their quality and width/height. I've found many information about the class JPGEncoder, but I couldn't make it work.
Could anyone help me with that?
Thanks!
Rafael.

you can use encodeByteArray() method of JPEGEncoder. link
some good article for image uploading to server is available at
1. insideRIA
2. http://henryjones.us/articles/using-the-as3-jpeg-encoder
3. http://blog.pigdev.com/?p=137

Here is a little sample:
farg. this code editor leaves a little to be desired...
import mx.graphics.codec.JPEGEncoder;
private function btnClick(e:Event):void
{
var encoder:JPEGEncoder = new JPEGEncoder(0); // Terrible quality
picNew.source = encoder.encode( Bitmap(picOrig.content).bitmapData );
}
<mx:Image id="picOrig" x="10" y="10" source="image1.png"/>
<mx:Image id="picNew" x="200" y="10" />
<mx:Button x="100" y="300" label="Button" click="btnClick(event);"/>

Related

In Storybook theming for brandImage how to change logo height or width?

Within Storybook's manager.js when changing the theme I've found the documentation where you can add a custom logo with:
import { create } from '#storybook/theming'
import logo from '../src/images/logo.png'
export default create({
brandImage: logo,
})
However I've been unable to find a way to adjust the logo size of a PNG. From my research it seems the only way to adjust the size is to implement a width or height in the SVG:
logo.svg:
<svg width="100" height="40" viewBox="0 0 290.72 112.41" [...]
maanger.js:
import { create } from "#storybook/theming"
import logo from "../src/logo.svg"
export default create({
brandImage: logo,
})
I'm unable to find a way in the docs (params or themeing) if there is a way to set the width or height of a PNG.
Research
Storybook change logo
Link to brandImage not working
Custom theme brand image not being displayed in the Sidebar
Storybook's styling overrides all
In Storybook is there a way when using a PNG for brandImage I can adjust the width or height without having to implement it as a SVG?

Using v-template outside of listView NATIVESCRIPT-VUE

I need to use a single v-template in my custom component like
<FlexboxLayout class="ticker-col" ref="tickercol">
<v-template name="charttemplate">
<Chart :chartData="chartData" />
</v-template>
</FlexboxLayout>
As mentioned on official docs (link), it says I have to use registerTemplate method. And I have to use a scopedSlot render function as 3rd parameter of this function. But I couldn't find out how to do this. My Chart component is still invisible.
mounted() {
const tickercol = this.$refs.tickercol;
tickercol.$templates.registerTemplate("charttemplate", null, 'what should be here?');
I'm not sure that I'm on the right way. Can anybody help?
Thanks in advance.

How can I change react-map-gl icons?

I'm trying to customize my web application's map, I'm using react-map-gl (Uber opensource code) I try to change the map's icon pins but I could not figure out, what does the string code ICON mean?
import React, { PureComponent } from 'react';
const ICON = M20.2,15.7L20.2,15.7c1.1-1.6,1.8-3.6,1.8-5.7c0-5.6-4.5-10-10-10S2,4.5,2,10c0,2,0.6,3.9,1.6,5.4c0,0.1,0.1,0.2,0.2,0.3
c0,0,0.1,0.1,0.1,0.2c0.2,0.3,0.4,0.6,0.7,0.9c2.6,3.1,7.4,7.6,7.4,7.6s4.8-4.5,7.4-7.5c0.2-0.3,0.5-0.6,0.7-0.9
C20.1,15.8,20.2,15.8,20.2,15.7z;
const pinStyle = {
cursor: 'pointer',
fill: '#d00',
stroke: 'none'
};
export default class CityPin extends PureComponent {
render() {
const { size = 20, onClick } = this.props;
return (
<svg
height={size}
viewBox="0 0 24 24"
style={{ ...pinStyle, transform: `translate(${-size / 2}px,${-size}px)` }}
onClick={onClick}
>
<path d={ICON} />
</svg>
);
}
}
What does it mean all those numbers in ICON const? How can I change the style based on this code? Please help, thanks :)
All of the gibberish that is the ICON constant is SVG Path notation and is actually drawing your current symbol. If you want to learn more about it, here is another resource. There are even websites that can help you build your own SVG path string, Option 1 Option 2, and searching the web will pull up many more.
Note that you likely need to update the viewbox numbers to fit your new thing once you have the symbol you want. It otherwise chops off the symbol at those dimensions.
In trying to figure this out, my example update was:
const ICON = 'm 10 35 l 15 30 l 15 -30 A 20 20 180 1 0 10 35 z'
with a viewbox in the svg tag of:
viewBox="-8 0 55 65"
EDIT:: you can also use any image as explained in the other answers. There is an article on using custom images at Medium with a good explanation and more details.
You mentioned you're using react-map-gl, so you could use the Marker component to change your icon pins.
Is there a specific image you'd like to use for your icons, say a .png file? If so, add that image to the directory called "public." Then, in your map where you create the markers, you can display this specific image.
For example, if you have an image called mapicon.png, you'd add that to your public folder. Then, when you're creating your markers, you could do something like this.
import ReactMapGL, {Marker} from 'react-map-gl';
<Marker key={} latitude={} longitude={}>
<img
src="mapicon.png"
alt="map icon"
/>
</Marker>
From what I understand, the string is just a reference to where the icon image is stored. Hope this helps!
You can create a custom map marker with an SVG file. If you are using create-react-app, you can import your svg icon as a component like this:
import { ReactComponent as Pin } from '../../images/map-marker-icon.svg';
Then, in your example code above you can replace the
<path d={ICON} />
with this component. Here is an example:
export default class MapPin extends PureComponent {
render() {
<Marker longitude={this.props.longitude} latitude=this.props.latitude}>
<svg
onClick={() => onClick()}
viewBox="0 0 60 100"
enable-background="new 0 0 60 100">
<Pin/>
</svg>
</Marker>
));
}
}

Flex mobile resized image layout

I'm trying to display a resized image in a flex mobile application and I couldn't get it displayed correctly.
When set to width="100%" it looks OK. (Image 1)
When I scale it down to let's say 30% by Flex (scaleMode="letterbox"), it is scaled down, but the components above and below the image still keep the distance from the Image control as it were 100% height. (Image 2)
I tried dozens of layout tricks from autolayout=true to dynamically scaled elements, but couldn't find a solution. What am I doing wrong?
(I use Flash Builder 4.7, Flex 4.6 and Air SDK 13.0 on a 64-bit Win 7 Machine.)
Thank you for your answer, really appreciate it! However, this is unfortunately not a solution as it just sets the height the same as width. In this case, the two labels gets closer to the image, but not in the place where they supposed to go.
Meanwhile I could find a way to correctly resize the image along with its bounding box.
The main idea is to put the image in a container, and adjust the image size according to the ratio of the container size divided by the original image size.
Then the image will fully fill the container, and I can then set the desired scaling ratio by adjusting the container's width.
Here is my code that works perfectly, and I really hope that it will help someone else in the future:
<?xml version="1.0" encoding="utf-8"?>
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
import spark.components.Image;
private var img:Image = new Image();
private function init():void {
drawImg("assets/image.png");
}
private function drawImg(src:String):void {
img.source = src;
img.scaleMode = "letterbox";
img.smooth = true;
imgHolder.addElement(img);
img.addEventListener(FlexEvent.READY, imgStatus);
}
private function imgStatus(e:FlexEvent):void {
var imgw:Number = e.currentTarget.bitmapData.width;
var imgh:Number = e.currentTarget.bitmapData.height;
var ratio:Number = Number(imgHolder.width/imgw);
img.width = imgw*ratio
img.height = imgh*ratio
}
]]>
</fx:Script>
<s:VGroup width="100%" horizontalAlign="center">
<s:Label text="Foo" />
<s:HGroup id="imgHolder" width="30%" />
<s:Label text="Bar" />
</s:VGroup>
First I always got a null object, so I found that I need to listen for the image to be fully loaded, and now it works perfectly.
Again, the desired width property can be set on the container and not the image.
Here's a screenshot with the results.
The height of the image indeed remains untouched by only setting the image width.
If you draw a rectangle around the image you will see the bounding box with the same size all the time.
You can modify your code like the following to have a dynamic height and have the labels positioned as you wish:
<s:VGroup width="100%"
horizontalAlign="center">
<s:Label verticalAlign="bottom"
text="Foo" />
<s:Image id="img"
source="test.gif"
width="30%"
height="{img.width}"
scaleMode="letterbox" />
<s:Label verticalAlign="top"
text="Bar" />
</s:VGroup>

How to open new explorer when clicking links in webpages loaded by app of Flex/Air?

In my application I tried using following codes to do this:
<mx:HTML x="0" y="0" width="100%" height="100%" location=“http://www.example.com”/>
The page is loaded fine.But when I click the links I found sometimes there was no any response while I need a new explore window opened with the linking url.And also I tried:
<mx:Script>
<![CDATA[
private function init():void
{
var req:URLRequest = new URLRequest("http://www.baidu.com");
var a:HTMLLoader = new HTMLLoader();
a.width = 400;
a.height = 300;
a.load(req);
htmlmc.addChild(a);
}
]]>
</mx:Script>
<mx:HTML x="10" y="10" width="345" height="258" id="htmlmc"/>
But still got nothing.Any good ideas?
Thanks in advance!
If your question is "how to open a link in new web browser window by click it in Adobe AIR?", please try this solution.
Give "id" to your HTML component. (I give its "box" in this case.)
Add this code to your application's creation complete handler.
Use following function:
protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void
{
box.htmlLoader.navigateInSystemBrowser = true;
}
Run your application and try to click on a link. This should work. I tested it with Adobe Flash Builder 4 on Windows 7. It works like a charm.

Resources